[commit: ghc] master: rts: Add FALLTHROUGH macro (6bb8aaa)
git at git.haskell.org
git at git.haskell.org
Fri Nov 2 21:13:58 UTC 2018
Repository : ssh://git@git.haskell.org/ghc
On branch : master
Link : http://ghc.haskell.org/trac/ghc/changeset/6bb8aaa3b4fcebf8f0de2f81f00dcc20b857c4f5/ghc
>---------------------------------------------------------------
commit 6bb8aaa3b4fcebf8f0de2f81f00dcc20b857c4f5
Author: Ben Gamari <bgamari.foss at gmail.com>
Date: Fri Nov 2 14:25:27 2018 -0400
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
>---------------------------------------------------------------
6bb8aaa3b4fcebf8f0de2f81f00dcc20b857c4f5
includes/Stg.h | 7 +++++++
rts/RaiseAsync.c | 2 +-
rts/linker/Elf.c | 2 +-
rts/linker/MachO.c | 1 +
rts/sm/CNF.c | 16 ++++++++--------
rts/sm/MarkWeak.c | 2 +-
rts/sm/Sanity.c | 2 +-
rts/sm/Scav.c | 10 +++++-----
8 files changed, 25 insertions(+), 17 deletions(-)
diff --git a/includes/Stg.h b/includes/Stg.h
index 3a11af1..9b54526 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 b08acc4..72f5dff 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 fd24a92..8df7e54 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 5812e89..e28d173 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 6bc58cd..8d0ebcc 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 88037f6..d7b8fe6 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 c6861f4..1da3e44 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 2f61914..8bc7029 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
More information about the ghc-commits
mailing list