Use fallthrough attribute
authorJens Axboe <axboe@kernel.dk>
Fri, 28 Aug 2020 15:14:38 +0000 (09:14 -0600)
committerJens Axboe <axboe@kernel.dk>
Fri, 28 Aug 2020 15:14:38 +0000 (09:14 -0600)
Fio currently triggers a bunch of fall through errors on clang 10,
since it doesn't work with the /* fall through */ method of
indicating fallthrough.

Normalize this a bit and use the correct compiler attribute for this.

Signed-off-by: Jens Axboe <axboe@kernel.dk>
compiler/compiler.h
crc/murmur3.c
hash.h
init.c
io_u.c
lib/lfsr.c
parse.c
t/lfsr-test.c

index 8a784b9269b6a66419fc7f51cb453f047309653f..8988236c828a909bca94df49891508fcfc8d8945 100644 (file)
 #define FIELD_SIZE(s, f) (sizeof(((__typeof__(s))0)->f))
 #endif
 
+#ifndef __has_attribute
+#define __GCC4_has_attribute___fallthrough__   0
+#endif
+
+#if __has_attribute(__fallthrough__)
+#define fallthrough     __attribute__((__fallthrough__))
+#else
+#define fallthrough    do {} while (0)  /* fallthrough */
+#endif
+
 #endif
index f4f2f2c648d24e51fa9eed9febda91142c28300f..ba408a9e80c8df60f8a9466cb862024cdad69135 100644 (file)
@@ -1,4 +1,5 @@
 #include "murmur3.h"
+#include "../compiler/compiler.h"
 
 static inline uint32_t rotl32(uint32_t x, int8_t r)
 {
@@ -29,10 +30,10 @@ static uint32_t murmur3_tail(const uint8_t *data, const int nblocks,
        switch (len & 3) {
        case 3:
                k1 ^= tail[2] << 16;
-               /* fall through */
+               fallthrough;
        case 2:
                k1 ^= tail[1] << 8;
-               /* fall through */
+               fallthrough;
        case 1:
                k1 ^= tail[0];
                k1 *= c1;
diff --git a/hash.h b/hash.h
index 66dd3d6916ea5b1386948c2d2a661d8bce59abf9..2c04bc296974dbe7708fe2ef940afd5893a92ec0 100644 (file)
--- a/hash.h
+++ b/hash.h
@@ -3,6 +3,7 @@
 
 #include <inttypes.h>
 #include "arch/arch.h"
+#include "compiler/compiler.h"
 
 /* Fast hashing routine for a long.
    (C) 2002 William Lee Irwin III, IBM */
@@ -141,19 +142,20 @@ static inline uint32_t jhash(const void *key, uint32_t length, uint32_t initval)
        /* Last block: affect all 32 bits of (c) */
        /* All the case statements fall through */
        switch (length) {
-       case 12: c += (uint32_t) k[11] << 24;   /* fall through */
-       case 11: c += (uint32_t) k[10] << 16;   /* fall through */
-       case 10: c += (uint32_t) k[9] << 8;     /* fall through */
-       case 9:  c += k[8];                     /* fall through */
-       case 8:  b += (uint32_t) k[7] << 24;    /* fall through */
-       case 7:  b += (uint32_t) k[6] << 16;    /* fall through */
-       case 6:  b += (uint32_t) k[5] << 8;     /* fall through */
-       case 5:  b += k[4];                     /* fall through */
-       case 4:  a += (uint32_t) k[3] << 24;    /* fall through */
-       case 3:  a += (uint32_t) k[2] << 16;    /* fall through */
-       case 2:  a += (uint32_t) k[1] << 8;     /* fall through */
+       case 12: c += (uint32_t) k[11] << 24;   fallthrough;
+       case 11: c += (uint32_t) k[10] << 16;   fallthrough;
+       case 10: c += (uint32_t) k[9] << 8;     fallthrough;
+       case 9:  c += k[8];                     fallthrough;
+       case 8:  b += (uint32_t) k[7] << 24;    fallthrough;
+       case 7:  b += (uint32_t) k[6] << 16;    fallthrough;
+       case 6:  b += (uint32_t) k[5] << 8;     fallthrough;
+       case 5:  b += k[4];                     fallthrough;
+       case 4:  a += (uint32_t) k[3] << 24;    fallthrough;
+       case 3:  a += (uint32_t) k[2] << 16;    fallthrough;
+       case 2:  a += (uint32_t) k[1] << 8;     fallthrough;
        case 1:  a += k[0];
                 __jhash_final(a, b, c);
+                fallthrough;
        case 0: /* Nothing left to add */
                break;
        }
diff --git a/init.c b/init.c
index 9dd5c9b8b1c8f2fc7178bf043a1756a1ba168780..3cd0238b1e2f8cad547191952afae22515bf98a9 100644 (file)
--- a/init.c
+++ b/init.c
@@ -2895,7 +2895,7 @@ int parse_cmd_line(int argc, char *argv[], int client_type)
                        log_err("%s: unrecognized option '%s'\n", argv[0],
                                                        argv[optind - 1]);
                        show_closest_option(argv[optind - 1]);
-                       /* fall through */
+                       fallthrough;
                default:
                        do_exit++;
                        exit_val = 1;
diff --git a/io_u.c b/io_u.c
index 2ef5acec95fe798bd4a657e4936414ea84593efd..155d0a3288acb0703e74c824f34ad9ce515d3900 100644 (file)
--- a/io_u.c
+++ b/io_u.c
@@ -993,6 +993,7 @@ static void __io_u_mark_map(uint64_t *map, unsigned int nr)
                break;
        case 1 ... 4:
                idx = 1;
+               fallthrough;
        case 0:
                break;
        }
@@ -1034,6 +1035,7 @@ void io_u_mark_depth(struct thread_data *td, unsigned int nr)
                break;
        case 2 ... 3:
                idx = 1;
+               fallthrough;
        case 1:
                break;
        }
@@ -1074,6 +1076,7 @@ static void io_u_mark_lat_nsec(struct thread_data *td, unsigned long long nsec)
                break;
        case 2 ... 3:
                idx = 1;
+               fallthrough;
        case 0 ... 1:
                break;
        }
@@ -1115,6 +1118,7 @@ static void io_u_mark_lat_usec(struct thread_data *td, unsigned long long usec)
                break;
        case 2 ... 3:
                idx = 1;
+               fallthrough;
        case 0 ... 1:
                break;
        }
@@ -1162,6 +1166,7 @@ static void io_u_mark_lat_msec(struct thread_data *td, unsigned long long msec)
                break;
        case 2 ... 3:
                idx = 1;
+               fallthrough;
        case 0 ... 1:
                break;
        }
index 1ef6ebbf1a22d39b6a4ff86d936bfebb08e32f96..a32e850a704f08e8e43456a5b684cae6cd8aba22 100644 (file)
@@ -88,37 +88,37 @@ static inline void __lfsr_next(struct fio_lfsr *fl, unsigned int spin)
         */
        switch (spin) {
                case 15: __LFSR_NEXT(fl, fl->last_val);
-               /* fall through */
+               fallthrough;
                case 14: __LFSR_NEXT(fl, fl->last_val);
-               /* fall through */
+               fallthrough;
                case 13: __LFSR_NEXT(fl, fl->last_val);
-               /* fall through */
+               fallthrough;
                case 12: __LFSR_NEXT(fl, fl->last_val);
-               /* fall through */
+               fallthrough;
                case 11: __LFSR_NEXT(fl, fl->last_val);
-               /* fall through */
+               fallthrough;
                case 10: __LFSR_NEXT(fl, fl->last_val);
-               /* fall through */
+               fallthrough;
                case  9: __LFSR_NEXT(fl, fl->last_val);
-               /* fall through */
+               fallthrough;
                case  8: __LFSR_NEXT(fl, fl->last_val);
-               /* fall through */
+               fallthrough;
                case  7: __LFSR_NEXT(fl, fl->last_val);
-               /* fall through */
+               fallthrough;
                case  6: __LFSR_NEXT(fl, fl->last_val);
-               /* fall through */
+               fallthrough;
                case  5: __LFSR_NEXT(fl, fl->last_val);
-               /* fall through */
+               fallthrough;
                case  4: __LFSR_NEXT(fl, fl->last_val);
-               /* fall through */
+               fallthrough;
                case  3: __LFSR_NEXT(fl, fl->last_val);
-               /* fall through */
+               fallthrough;
                case  2: __LFSR_NEXT(fl, fl->last_val);
-               /* fall through */
+               fallthrough;
                case  1: __LFSR_NEXT(fl, fl->last_val);
-               /* fall through */
+               fallthrough;
                case  0: __LFSR_NEXT(fl, fl->last_val);
-               /* fall through */
+               fallthrough;
                default: break;
        }
 }
diff --git a/parse.c b/parse.c
index 04b2e1989e34b0fa54810a4f97d8649f0f53eb91..f4cefcf6243edbd911cb4f274611912c440a5f07 100644 (file)
--- a/parse.c
+++ b/parse.c
@@ -596,7 +596,7 @@ static int __handle_option(const struct fio_option *o, const char *ptr,
        }
        case FIO_OPT_STR_VAL_TIME:
                is_time = 1;
-               /* fall through */
+               fallthrough;
        case FIO_OPT_ULL:
        case FIO_OPT_INT:
        case FIO_OPT_STR_VAL: {
@@ -941,7 +941,7 @@ static int __handle_option(const struct fio_option *o, const char *ptr,
        }
        case FIO_OPT_DEPRECATED:
                ret = 1;
-               /* fall through */
+               fallthrough;
        case FIO_OPT_SOFT_DEPRECATED:
                log_info("Option %s is deprecated\n", o->name);
                break;
index ea8c8ddbde9a3429624ddde9cb9615a24c7b8c9b..279e07f0ecd05110fae4e78e12787b8d7788fc27 100644 (file)
@@ -6,6 +6,7 @@
 #include "../lib/lfsr.h"
 #include "../gettime.h"
 #include "../fio_time.h"
+#include "../compiler/compiler.h"
 
 static void usage(void)
 {
@@ -40,11 +41,11 @@ int main(int argc, char *argv[])
        switch (argc) {
                case 5: if (strncmp(argv[4], "verify", 7) == 0)
                                verify = 1;
-                       /* fall through */
+                       fallthrough;
                case 4: spin = atoi(argv[3]);
-                       /* fall through */
+                       fallthrough;
                case 3: seed = atol(argv[2]);
-                       /* fall through */
+                       fallthrough;
                case 2: numbers = strtol(argv[1], NULL, 16);
                                break;
                default: usage();