Add more 'fall through' switch comments 25/14125/16
authorCheyenne Wills <cwills@sinenomine.net>
Fri, 3 Apr 2020 21:00:42 +0000 (15:00 -0600)
committerBenjamin Kaduk <kaduk@mit.edu>
Thu, 14 May 2020 03:35:09 +0000 (23:35 -0400)
Commit a455452d (LINUX 5.3: Add comments for fallthrough switch cases)
added the special /* fall through */ comment to various switch/case
blocks, in order to avoid implicit-fallthrough warnings from causing
the build to fail when building the Linux kernel module.

In this commit, add additional /* fall through */ comments to the rest
of the tree where falling through is intentional. Add a "break;" in one
place in dumptool.c where falling through seems like a mistake, and flag
certain functions as AFS_NORETURN to avoid needing to explicitly break
or fallthrough.

Check for the availability of the -Wimplicit-fallthrough compiler flag
and use it when --enable-checking is set, to prevent additional cases
from creeping into the tree.

Note: the -Wimplicit-fallthrough compiler flag was added in gcc 7.

Change-Id: Iae34e7969606603da8358d7cfa5fd04279b218dc
Reviewed-on: https://gerrit.openafs.org/14125
Reviewed-by: Andrew Deason <adeason@sinenomine.net>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
Tested-by: BuildBot <buildbot@rampaginggeek.com>

12 files changed:
src/butc/dump.c
src/cf/osconf.m4
src/cmd/cmd.c
src/opr/jhash.h
src/tools/dumpscan/afsdump_dirlist.c
src/tools/dumpscan/afsdump_extract.c
src/tools/dumpscan/afsdump_scan.c
src/tools/dumpscan/dumptool.c
src/tools/dumpscan/parsevnode.c
src/vol/salvaged.c
src/vol/salvsync-server.c
src/vol/volume.c

index 62d09e5..ceda6d7 100644 (file)
@@ -868,8 +868,7 @@ dumpPass(struct dumpRock * dparamsPtr, int passNumber)
                    dparamsPtr->volumesFailed++;
                    continue;
                }
-               /* Fall into RWVOL case */
-
+               /* fall through */
            case RWVOL:
                for (e = 0; e < vldbEntry.nServers; e++) {      /* Find the RW volume */
                    if (vldbEntry.serverFlags[e] & VLSF_RWVOL)
index a765717..12125ce 100644 (file)
@@ -658,6 +658,11 @@ else
   esac
 fi
 
+dnl add additional checks if compilers support the flags
+AS_IF([test "x$enable_checking" != "xno"],
+      [AX_APPEND_COMPILE_FLAGS([-Wimplicit-fallthrough], [XCFLAGS])
+])
+
 dnl horribly cheating, assuming double / is ok.
 case $INSTALL in
   ./* ) 
index 10b2b1b..87f8e69 100644 (file)
@@ -691,7 +691,7 @@ ResetSyntax(struct cmd_syndesc *as)
        case CMD_SINGLE_OR_FLAG:
            if (tp->items == &dummy)
                break;
-           /* Deliberately fall through here */
+           /* fall through */
        case CMD_SINGLE:
        case CMD_LIST:
            /* free whole list in both cases, just for fun */
index 4568f56..d110735 100644 (file)
@@ -150,19 +150,19 @@ opr_jhash_opaque(const void *val, size_t length, afs_uint32 initval)
 
     /* All the case statements fall through */
     switch(length) {
-      case 12 : c += (afs_uint32) str[11]<<24;
-      case 11 : c += (afs_uint32) str[10]<<16;
-      case 10 : c += (afs_uint32) str[9]<<8;
-      case 9  : c += (afs_uint32) str[8];
-      case 8  : b += (afs_uint32) str[7]<<24;
-      case 7  : b += (afs_uint32) str[6]<<16;
-      case 6  : b += (afs_uint32) str[5]<<8;
-      case 5  : b += (afs_uint32) str[4];
-      case 4  : a += (afs_uint32) str[3]<<24;
-      case 3  : a += (afs_uint32) str[2]<<16;
-      case 2  : a += (afs_uint32) str[1]<<8;
+      case 12 : c += (afs_uint32) str[11]<<24;         /* fall through */
+      case 11 : c += (afs_uint32) str[10]<<16;         /* fall through */
+      case 10 : c += (afs_uint32) str[9]<<8;   /* fall through */
+      case 9  : c += (afs_uint32) str[8];      /* fall through */
+      case 8  : b += (afs_uint32) str[7]<<24;  /* fall through */
+      case 7  : b += (afs_uint32) str[6]<<16;  /* fall through */
+      case 6  : b += (afs_uint32) str[5]<<8;   /* fall through */
+      case 5  : b += (afs_uint32) str[4];      /* fall through */
+      case 4  : a += (afs_uint32) str[3]<<24;  /* fall through */
+      case 3  : a += (afs_uint32) str[2]<<16;  /* fall through */
+      case 2  : a += (afs_uint32) str[1]<<8;   /* fall through */
       case 1  : a += (afs_uint32) str[0];
-       opr_jhash_final(a, b, c);
+       opr_jhash_final(a, b, c);               /* fall through */
       case 0:     /* case 0: nothing left to add */
        break;
     }
index 0af2ed7..811ddd4 100644 (file)
@@ -56,7 +56,7 @@ static dump_parser dp;
 
 
 /* Print a usage message and exit */
-static void
+static void AFS_NORETURN
 usage(int status, char *msg)
 {
     if (msg)
index db0b2fa..dfe0369 100644 (file)
@@ -62,7 +62,7 @@ static path_hashinfo phi;
 static dump_parser dp;
 
 /* Print a usage message and exit */
-static void
+static void AFS_NORETURN
 usage(int status, char *msg)
 {
     if (msg)
index dafae67..787172d 100644 (file)
@@ -63,7 +63,7 @@ static dump_parser dp;
 
 
 /* Print a usage message and exit */
-static void
+static void AFS_NORETURN
 usage(int status, char *msg)
 {
     if (msg)
index 58d67e8..61dc0e6 100644 (file)
@@ -1300,6 +1300,7 @@ DirectoryList(int argc, char **argv, struct vnodeData *vdata,
            break;
        case 'R':
            Rflag++;
+           break;
        case 's':
            sflag++;
            break;
index 0e18e49..1940b3b 100644 (file)
@@ -480,7 +480,7 @@ parse_vdata(XFILE * X, unsigned char *tag, tagged_field * field,
                    return r;
                break;
            }
-
+           /* fall through */
        default:
            if ((r = xfskip(X, v->size)))
                return r;
index 54c4a63..bf3d101 100644 (file)
@@ -478,6 +478,7 @@ SalvageClient(VolumeId vid, char * pname)
        switch (sres.state) {
        case SALVSYNC_STATE_ERROR:
            printf("salvageserver reports salvage ended in an error; check log files for more details\n");
+           /* fall through */
        case SALVSYNC_STATE_DONE:
        case SALVSYNC_STATE_UNKNOWN:
            done = 1;
index bd9f974..8eb879f 100644 (file)
@@ -940,7 +940,7 @@ LinkNode(struct SalvageQueueNode * parent,
     switch (clone->state) {
     case SALVSYNC_STATE_QUEUED:
        DeleteFromSalvageQueue(clone);
-
+       /* fall through */
     case SALVSYNC_STATE_SALVAGING:
        switch (parent->state) {
        case SALVSYNC_STATE_UNKNOWN:
index c2d0668..4c2c10e 100644 (file)
@@ -1796,15 +1796,18 @@ ShutdownVolumeWalk_r(struct DiskPartition64 * dp, int pass,
                (V_attachState(vp) != VOL_STATE_PREATTACHED)) {
                break;
            }
+           /* fall through */
        case 1:
            if ((V_attachState(vp) == VOL_STATE_ATTACHED) &&
                (vp->header == NULL)) {
                break;
            }
+           /* fall through */
        case 2:
            if (VIsExclusiveState(V_attachState(vp))) {
                break;
            }
+           /* fall through */
        case 3:
            *idx = nqp;
            DeleteVolumeFromVByPList_r(vp);