rts: Add FALLTHROUGH macro
authorBen Gamari <bgamari.foss@gmail.com>
Fri, 2 Nov 2018 18:25:27 +0000 (14:25 -0400)
committerBen Gamari <ben@smart-cactus.org>
Fri, 2 Nov 2018 21:13:03 +0000 (17:13 -0400)
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

includes/Stg.h
rts/RaiseAsync.c
rts/linker/Elf.c
rts/linker/MachO.c
rts/sm/CNF.c
rts/sm/MarkWeak.c
rts/sm/Sanity.c
rts/sm/Scav.c

index 3a11af1..9b54526 100644 (file)
 #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
index b08acc4..72f5dff 100644 (file)
@@ -449,8 +449,8 @@ check_target:
         }
         // fall to next
     }
+    FALLTHROUGH;
 #endif
-    /* fallthrough */
     case BlockedOnCCall:
         blockedThrowTo(cap,target,msg);
         return THROWTO_BLOCKED;
index fd24a92..8df7e54 100644 (file)
@@ -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;
 
index 5812e89..e28d173 100644 (file)
@@ -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.
index 6bc58cd..8d0ebcc 100644 (file)
@@ -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",
index 88037f6..d7b8fe6 100644 (file)
@@ -155,7 +155,7 @@ traverseWeakPtrList(void)
 
       // otherwise, fall through...
   }
-  /* fallthrough */
+  FALLTHROUGH;
 
   case WeakPtrs:
   {
index c6861f4..1da3e44 100644 (file)
@@ -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:
index 2f61914..8bc7029 100644 (file)
@@ -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