diff options
author | Joe Perches <joe@perches.com> | 2019-10-05 12:46:42 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2019-10-11 12:26:05 -0400 |
commit | 294f69e662d1570703e9b56e95be37a9fd3afba5 (patch) | |
tree | 8138e829d29b3f06e3bc1de49cab4a34e31dc1a7 | |
parent | 48f9bcf91461b43249949f4e172b5c0245dde751 (diff) |
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>
-rw-r--r-- | include/linux/compiler_attributes.h | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/include/linux/compiler_attributes.h b/include/linux/compiler_attributes.h index 6b318efd8a74..cdf016596659 100644 --- a/include/linux/compiler_attributes.h +++ b/include/linux/compiler_attributes.h | |||
@@ -40,6 +40,7 @@ | |||
40 | # define __GCC4_has_attribute___noclone__ 1 | 40 | # define __GCC4_has_attribute___noclone__ 1 |
41 | # define __GCC4_has_attribute___nonstring__ 0 | 41 | # define __GCC4_has_attribute___nonstring__ 0 |
42 | # define __GCC4_has_attribute___no_sanitize_address__ (__GNUC_MINOR__ >= 8) | 42 | # define __GCC4_has_attribute___no_sanitize_address__ (__GNUC_MINOR__ >= 8) |
43 | # define __GCC4_has_attribute___fallthrough__ 0 | ||
43 | #endif | 44 | #endif |
44 | 45 | ||
45 | /* | 46 | /* |
@@ -186,6 +187,22 @@ | |||
186 | #endif | 187 | #endif |
187 | 188 | ||
188 | /* | 189 | /* |
190 | * Add the pseudo keyword 'fallthrough' so case statement blocks | ||
191 | * must end with any of these keywords: | ||
192 | * break; | ||
193 | * fallthrough; | ||
194 | * goto <label>; | ||
195 | * return [expression]; | ||
196 | * | ||
197 | * gcc: https://gcc.gnu.org/onlinedocs/gcc/Statement-Attributes.html#Statement-Attributes | ||
198 | */ | ||
199 | #if __has_attribute(__fallthrough__) | ||
200 | # define fallthrough __attribute__((__fallthrough__)) | ||
201 | #else | ||
202 | # define fallthrough do {} while (0) /* fallthrough */ | ||
203 | #endif | ||
204 | |||
205 | /* | ||
189 | * Note the missing underscores. | 206 | * Note the missing underscores. |
190 | * | 207 | * |
191 | * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-noinline-function-attribute | 208 | * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-noinline-function-attribute |