Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

compiler_attributes.h: Add 'fallthrough' pseudo keyword for switch/case use

Reserve the pseudo keyword 'fallthrough' for the ability to convert the
various case block /* fallthrough */ style comments to appear to be an
actual reserved word with the same gcc case block missing fallthrough
warning capability.

All switch/case blocks now should end in one of:

break;
fallthrough;
goto <label>;
return [expression];
continue;

In C mode, GCC supports the __fallthrough__ attribute since 7.1,
the same time the warning and the comment parsing were introduced.

fallthrough devolves to an empty "do {} while (0)" if the compiler
version (any version less than gcc 7) does not support the attribute.

Signed-off-by: Joe Perches <joe@perches.com>
Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Suggested-by: Dan Carpenter <dan.carpenter@oracle.com>
Cc: Miguel Ojeda <miguel.ojeda.sandonis@gmail.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Joe Perches and committed by
Linus Torvalds
294f69e6 48f9bcf9

+17
+17
include/linux/compiler_attributes.h
··· 40 40 # define __GCC4_has_attribute___noclone__ 1 41 41 # define __GCC4_has_attribute___nonstring__ 0 42 42 # define __GCC4_has_attribute___no_sanitize_address__ (__GNUC_MINOR__ >= 8) 43 + # define __GCC4_has_attribute___fallthrough__ 0 43 44 #endif 44 45 45 46 /* ··· 184 183 # define __noclone __attribute__((__noclone__)) 185 184 #else 186 185 # define __noclone 186 + #endif 187 + 188 + /* 189 + * Add the pseudo keyword 'fallthrough' so case statement blocks 190 + * must end with any of these keywords: 191 + * break; 192 + * fallthrough; 193 + * goto <label>; 194 + * return [expression]; 195 + * 196 + * gcc: https://gcc.gnu.org/onlinedocs/gcc/Statement-Attributes.html#Statement-Attributes 197 + */ 198 + #if __has_attribute(__fallthrough__) 199 + # define fallthrough __attribute__((__fallthrough__)) 200 + #else 201 + # define fallthrough do {} while (0) /* fallthrough */ 187 202 #endif 188 203 189 204 /*