btrfs-progs: fix fallthrough cases with proper attributes

[FALSE ALERT]
Unlike gcc, clang doesn't really understand the comments, thus it's
reportings tons of fall through related errors:

  cmds/reflink.c:124:3: warning: unannotated fall-through between switch labels [-Wimplicit-fallthrough]
                  case 'r':
                  ^
  cmds/reflink.c:124:3: note: insert '__attribute__((fallthrough));' to silence this warning
                  case 'r':
                  ^
                  __attribute__((fallthrough));
  cmds/reflink.c:124:3: note: insert 'break;' to avoid fall-through
                  case 'r':
                  ^
                  break;

[CAUSE]
Although gcc is fine with /* fallthrough */ comments, clang is not.

[FIX]
So just introduce a fallthrough macro to handle the situation properly,
and use that macro instead.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
Qu Wenruo 2023-01-27 13:41:16 +08:00 committed by David Sterba
parent 66dad3a8f5
commit 3a1d4aa089
9 changed files with 65 additions and 54 deletions

View File

@ -120,7 +120,7 @@ static int cmd_reflink_clone(const struct cmd_struct *cmd, int argc, char **argv
switch (c) {
case 's':
same_file = true;
/* fallthrough */
fallthrough;
case 'r':
range = malloc(sizeof(struct reflink_range));
if (!range) {

View File

@ -602,7 +602,7 @@ again:
memset(p[curr], 0, sizeof(**p));
p[curr + 1] = NULL;
++state;
/* fall through */
fallthrough;
case 2: /* start of line, skip space */
while (isspace(l[i]) && i < avail) {
if (l[i] == '\n')
@ -613,7 +613,7 @@ again:
(!eof && !memchr(l + i, '\n', avail - i)))
goto again;
++state;
/* fall through */
fallthrough;
case 3: /* read fsid */
if (i == avail)
continue;
@ -629,7 +629,7 @@ again:
_SCRUB_INVALID;
i += j + 1;
++state;
/* fall through */
fallthrough;
case 4: /* read dev id */
for (j = 0; isdigit(l[i + j]) && i+j < avail; ++j)
;
@ -638,7 +638,7 @@ again:
p[curr]->devid = atoll(&l[i]);
i += j + 1;
++state;
/* fall through */
fallthrough;
case 5: /* read key/value pair */
ret = 0;
_SCRUB_KVREAD(ret, &i, data_extents_scrubbed, avail, l,
@ -682,7 +682,7 @@ again:
if (ret != 1)
_SCRUB_INVALID;
++state;
/* fall through */
fallthrough;
case 6: /* after number */
if (l[i] == '|')
state = 5;

View File

@ -74,7 +74,7 @@ static void print_escaped(const char *str)
case '"':
case '\\':
putchar('\\');
/* fallthrough */
fallthrough;
default:
putchar(*str);
}

View File

@ -184,22 +184,22 @@ u64 parse_size_from_string(const char *s)
switch (c) {
case 'e':
mult *= 1024;
/* fallthrough */
fallthrough;
case 'p':
mult *= 1024;
/* fallthrough */
fallthrough;
case 't':
mult *= 1024;
/* fallthrough */
fallthrough;
case 'g':
mult *= 1024;
/* fallthrough */
fallthrough;
case 'm':
mult *= 1024;
/* fallthrough */
fallthrough;
case 'k':
mult *= 1024;
/* fallthrough */
fallthrough;
case 'b':
break;
default:

View File

@ -89,15 +89,15 @@ int pretty_size_snprintf(u64 size, char *str, size_t str_size, unsigned unit_mod
case UNITS_TBYTES:
base *= mult;
num_divs++;
/* fallthrough */
fallthrough;
case UNITS_GBYTES:
base *= mult;
num_divs++;
/* fallthrough */
fallthrough;
case UNITS_MBYTES:
base *= mult;
num_divs++;
/* fallthrough */
fallthrough;
case UNITS_KBYTES:
num_divs++;
break;

View File

@ -116,6 +116,7 @@ static void* XXH_memcpy(void* dest, const void* src, size_t size) { return memcp
#define XXH_STATIC_LINKING_ONLY
#include "xxhash.h"
#include "kerncompat.h"
/* *************************************
* Compiler Specific Options
@ -397,41 +398,41 @@ XXH32_finalize(U32 h32, const void* ptr, size_t len, XXH_alignment align)
} else {
switch(len&15) /* or switch(bEnd - p) */ {
case 12: PROCESS4;
/* fallthrough */
fallthrough;
case 8: PROCESS4;
/* fallthrough */
fallthrough;
case 4: PROCESS4;
return XXH32_avalanche(h32);
case 13: PROCESS4;
/* fallthrough */
fallthrough;
case 9: PROCESS4;
/* fallthrough */
fallthrough;
case 5: PROCESS4;
PROCESS1;
return XXH32_avalanche(h32);
case 14: PROCESS4;
/* fallthrough */
fallthrough;
case 10: PROCESS4;
/* fallthrough */
fallthrough;
case 6: PROCESS4;
PROCESS1;
PROCESS1;
return XXH32_avalanche(h32);
case 15: PROCESS4;
/* fallthrough */
fallthrough;
case 11: PROCESS4;
/* fallthrough */
fallthrough;
case 7: PROCESS4;
/* fallthrough */
fallthrough;
case 3: PROCESS1;
/* fallthrough */
fallthrough;
case 2: PROCESS1;
/* fallthrough */
fallthrough;
case 1: PROCESS1;
/* fallthrough */
fallthrough;
case 0: return XXH32_avalanche(h32);
}
XXH_ASSERT(0);
@ -825,63 +826,63 @@ XXH64_finalize(U64 h64, const void* ptr, size_t len, XXH_alignment align)
} else {
switch(len & 31) {
case 24: PROCESS8_64;
/* fallthrough */
fallthrough;
case 16: PROCESS8_64;
/* fallthrough */
fallthrough;
case 8: PROCESS8_64;
return XXH64_avalanche(h64);
case 28: PROCESS8_64;
/* fallthrough */
fallthrough;
case 20: PROCESS8_64;
/* fallthrough */
fallthrough;
case 12: PROCESS8_64;
/* fallthrough */
fallthrough;
case 4: PROCESS4_64;
return XXH64_avalanche(h64);
case 25: PROCESS8_64;
/* fallthrough */
fallthrough;
case 17: PROCESS8_64;
/* fallthrough */
fallthrough;
case 9: PROCESS8_64;
PROCESS1_64;
return XXH64_avalanche(h64);
case 29: PROCESS8_64;
/* fallthrough */
fallthrough;
case 21: PROCESS8_64;
/* fallthrough */
fallthrough;
case 13: PROCESS8_64;
/* fallthrough */
fallthrough;
case 5: PROCESS4_64;
PROCESS1_64;
return XXH64_avalanche(h64);
case 26: PROCESS8_64;
/* fallthrough */
fallthrough;
case 18: PROCESS8_64;
/* fallthrough */
fallthrough;
case 10: PROCESS8_64;
PROCESS1_64;
PROCESS1_64;
return XXH64_avalanche(h64);
case 30: PROCESS8_64;
/* fallthrough */
fallthrough;
case 22: PROCESS8_64;
/* fallthrough */
fallthrough;
case 14: PROCESS8_64;
/* fallthrough */
fallthrough;
case 6: PROCESS4_64;
PROCESS1_64;
PROCESS1_64;
return XXH64_avalanche(h64);
case 27: PROCESS8_64;
/* fallthrough */
fallthrough;
case 19: PROCESS8_64;
/* fallthrough */
fallthrough;
case 11: PROCESS8_64;
PROCESS1_64;
PROCESS1_64;
@ -889,19 +890,19 @@ XXH64_finalize(U64 h64, const void* ptr, size_t len, XXH_alignment align)
return XXH64_avalanche(h64);
case 31: PROCESS8_64;
/* fallthrough */
fallthrough;
case 23: PROCESS8_64;
/* fallthrough */
fallthrough;
case 15: PROCESS8_64;
/* fallthrough */
fallthrough;
case 7: PROCESS4_64;
/* fallthrough */
fallthrough;
case 3: PROCESS1_64;
/* fallthrough */
fallthrough;
case 2: PROCESS1_64;
/* fallthrough */
fallthrough;
case 1: PROCESS1_64;
/* fallthrough */
fallthrough;
case 0: return XXH64_avalanche(h64);
}
}

View File

@ -1432,7 +1432,7 @@ static int restore_one_work(struct mdrestore_struct *mdres,
switch (ret) {
case Z_NEED_DICT:
ret = Z_DATA_ERROR;
__attribute__ ((fallthrough));
fallthrough;
case Z_DATA_ERROR:
case Z_MEM_ERROR:
goto out;

View File

@ -227,6 +227,16 @@ static inline int mutex_is_locked(struct mutex *m)
#define __attribute_const__ __attribute__((__const__))
#endif
/* To silence compilers (like clang) that don't understand fallthrough comments. */
#if defined __has_attribute
# if __has_attribute(__fallthrough__)
# define fallthrough __attribute__((__fallthrough__))
# endif
#else
# define fallthrough do {} while (0) /* fallthrough */
#endif
/**
* __set_bit - Set a bit in memory
* @nr: the bit to set

View File

@ -796,7 +796,7 @@ void print_objectid(FILE *stream, u64 objectid, u8 type)
fprintf(stream, "FIRST_CHUNK_TREE");
break;
}
/* fall-thru */
fallthrough;
default:
fprintf(stream, "%llu", (unsigned long long)objectid);
}