summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Gamari <bgamari.foss@gmail.com>2018-11-02 14:25:27 -0400
committerBen Gamari <ben@smart-cactus.org>2018-11-02 17:13:03 -0400
commit6bb8aaa3b4fcebf8f0de2f81f00dcc20b857c4f5 (patch)
tree09eaa82c607421240ba01ff0b312b804f44bab5e
parent5f81952e230fef1f65ae473e09d44101c489c483 (diff)
downloadhaskell-6bb8aaa3b4fcebf8f0de2f81f00dcc20b857c4f5.tar.gz
rts: Add FALLTHROUGH macro
Instead of using the GCC `/* fallthrough */` syntax we now use the `__attribute__((fallthrough))`, which Phyx says should be more portable than the former. Also adds a missing fallthrough annotation in the MachO linker, fixing #14613. Reviewers: erikd, simonmar Reviewed By: simonmar Subscribers: rwbarton, carter GHC Trac Issues: #14613 Differential Revision: https://phabricator.haskell.org/D5292
-rw-r--r--includes/Stg.h7
-rw-r--r--rts/RaiseAsync.c2
-rw-r--r--rts/linker/Elf.c2
-rw-r--r--rts/linker/MachO.c1
-rw-r--r--rts/sm/CNF.c16
-rw-r--r--rts/sm/MarkWeak.c2
-rw-r--r--rts/sm/Sanity.c2
-rw-r--r--rts/sm/Scav.c10
8 files changed, 25 insertions, 17 deletions
diff --git a/includes/Stg.h b/includes/Stg.h
index 3a11af1e5e..9b54526342 100644
--- a/includes/Stg.h
+++ b/includes/Stg.h
@@ -196,6 +196,13 @@
#define GNUC3_ATTRIBUTE(at)
#endif
+/* Used to mark a switch case that falls-through */
+#if (defined(__GNUC__) && __GNUC__ >= 7) || defined(__clang__)
+#define FALLTHROUGH GNU_ATTRIBUTE(fallthrough)
+#else
+#define FALLTHROUGH ((void)0)
+#endif /* __GNUC__ >= 7 */
+
#if !defined(DEBUG) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3))
#define GNUC_ATTR_HOT __attribute__((hot))
#else
diff --git a/rts/RaiseAsync.c b/rts/RaiseAsync.c
index b08acc4078..72f5dff7f6 100644
--- a/rts/RaiseAsync.c
+++ b/rts/RaiseAsync.c
@@ -449,8 +449,8 @@ check_target:
}
// fall to next
}
+ FALLTHROUGH;
#endif
- /* fallthrough */
case BlockedOnCCall:
blockedThrowTo(cap,target,msg);
return THROWTO_BLOCKED;
diff --git a/rts/linker/Elf.c b/rts/linker/Elf.c
index fd24a92630..8df7e54729 100644
--- a/rts/linker/Elf.c
+++ b/rts/linker/Elf.c
@@ -1536,7 +1536,7 @@ do_Elf_Rela_relocations ( ObjectCode* oc, char* ehdrC,
case R_PPC_PLTREL24:
value -= 0x8000; /* See Note [.LCTOC1 in PPC PIC code] */
- /* fallthrough */
+ FALLTHROUGH;
case R_PPC_REL24:
delta = value - P;
diff --git a/rts/linker/MachO.c b/rts/linker/MachO.c
index 5812e89cda..e28d1730fa 100644
--- a/rts/linker/MachO.c
+++ b/rts/linker/MachO.c
@@ -1530,6 +1530,7 @@ ocGetNames_MachO(ObjectCode* oc)
secArray[i].info->macho_section = section;
secArray[i].info->relocation_info
= (MachORelocationInfo*)(oc->image + section->reloff);
+ FALLTHROUGH;
}
default: {
// just set the pointer to the loaded image.
diff --git a/rts/sm/CNF.c b/rts/sm/CNF.c
index 6bc58cde75..8d0ebccaf3 100644
--- a/rts/sm/CNF.c
+++ b/rts/sm/CNF.c
@@ -212,7 +212,7 @@ compactAllocateBlockInternal(Capability *cap,
case ALLOCATE_IMPORT_NEW:
dbl_link_onto(block, &g0->compact_blocks_in_import);
- /* fallthrough */
+ FALLTHROUGH;
case ALLOCATE_IMPORT_APPEND:
ASSERT(first == NULL);
ASSERT(g == g0);
@@ -689,17 +689,17 @@ verify_consistency_block (StgCompactNFData *str, StgCompactNFDataBlock *block)
switch (info->type) {
case CONSTR_1_0:
check_object_in_compact(str, UNTAG_CLOSURE(q->payload[0]));
- /* fallthrough */
+ FALLTHROUGH;
case CONSTR_0_1:
p += sizeofW(StgClosure) + 1;
break;
case CONSTR_2_0:
check_object_in_compact(str, UNTAG_CLOSURE(q->payload[1]));
- /* fallthrough */
+ FALLTHROUGH;
case CONSTR_1_1:
check_object_in_compact(str, UNTAG_CLOSURE(q->payload[0]));
- /* fallthrough */
+ FALLTHROUGH;
case CONSTR_0_2:
p += sizeofW(StgClosure) + 2;
break;
@@ -931,7 +931,7 @@ fixup_block(StgCompactNFDataBlock *block, StgWord *fixup_table, uint32_t count)
if (!fixup_one_pointer(fixup_table, count,
&((StgClosure*)p)->payload[0]))
return false;
- /* fallthrough */
+ FALLTHROUGH;
case CONSTR_0_1:
p += sizeofW(StgClosure) + 1;
break;
@@ -940,12 +940,12 @@ fixup_block(StgCompactNFDataBlock *block, StgWord *fixup_table, uint32_t count)
if (!fixup_one_pointer(fixup_table, count,
&((StgClosure*)p)->payload[1]))
return false;
- /* fallthrough */
+ FALLTHROUGH;
case CONSTR_1_1:
if (!fixup_one_pointer(fixup_table, count,
&((StgClosure*)p)->payload[0]))
return false;
- /* fallthrough */
+ FALLTHROUGH;
case CONSTR_0_2:
p += sizeofW(StgClosure) + 2;
break;
@@ -999,7 +999,7 @@ fixup_block(StgCompactNFDataBlock *block, StgWord *fixup_table, uint32_t count)
break;
}
- // fall through
+ FALLTHROUGH;
default:
debugBelch("Invalid non-NFData closure (type %d) in Compact\n",
diff --git a/rts/sm/MarkWeak.c b/rts/sm/MarkWeak.c
index 88037f6a34..d7b8fe696f 100644
--- a/rts/sm/MarkWeak.c
+++ b/rts/sm/MarkWeak.c
@@ -155,7 +155,7 @@ traverseWeakPtrList(void)
// otherwise, fall through...
}
- /* fallthrough */
+ FALLTHROUGH;
case WeakPtrs:
{
diff --git a/rts/sm/Sanity.c b/rts/sm/Sanity.c
index c6861f4134..1da3e4416f 100644
--- a/rts/sm/Sanity.c
+++ b/rts/sm/Sanity.c
@@ -102,7 +102,7 @@ checkStackFrame( StgPtr c )
case UPDATE_FRAME:
ASSERT(LOOKS_LIKE_CLOSURE_PTR(((StgUpdateFrame*)c)->updatee));
- /* fallthrough */
+ FALLTHROUGH;
case ATOMICALLY_FRAME:
case CATCH_RETRY_FRAME:
case CATCH_STM_FRAME:
diff --git a/rts/sm/Scav.c b/rts/sm/Scav.c
index 2f61914e55..8bc702900b 100644
--- a/rts/sm/Scav.c
+++ b/rts/sm/Scav.c
@@ -498,7 +498,7 @@ scavenge_block (bdescr *bd)
case FUN_1_0:
scavenge_fun_srt(info);
- /* fallthrough */
+ FALLTHROUGH;
case CONSTR_1_0:
evacuate(&((StgClosure *)p)->payload[0]);
p += sizeofW(StgHeader) + 1;
@@ -511,7 +511,7 @@ scavenge_block (bdescr *bd)
case FUN_0_1:
scavenge_fun_srt(info);
- /* fallthrough */
+ FALLTHROUGH;
case CONSTR_0_1:
p += sizeofW(StgHeader) + 1;
break;
@@ -523,7 +523,7 @@ scavenge_block (bdescr *bd)
case FUN_0_2:
scavenge_fun_srt(info);
- /* fallthrough */
+ FALLTHROUGH;
case CONSTR_0_2:
p += sizeofW(StgHeader) + 2;
break;
@@ -536,7 +536,7 @@ scavenge_block (bdescr *bd)
case FUN_1_1:
scavenge_fun_srt(info);
- /* fallthrough */
+ FALLTHROUGH;
case CONSTR_1_1:
evacuate(&((StgClosure *)p)->payload[0]);
p += sizeofW(StgHeader) + 2;
@@ -1738,7 +1738,7 @@ scavenge_static(void)
case FUN_STATIC:
scavenge_fun_srt(info);
- /* fallthrough */
+ FALLTHROUGH;
// a FUN_STATIC can also be an SRT, so it may have pointer
// fields. See Note [SRTs] in CmmBuildInfoTables, specifically