Skip to content

Commit 079ec6a

Browse files
committed
tools/nolibc: compiler: add macro __nolibc_fallthrough
Recent version of GCC and clang gained -Wimplicit-fallthrough, warning about implicit fall-through between switch labels. As nolibc does not control the compilation flags, this can trigger warnings for when built by the user. Make use of the "fallthrough" attribute to explicitly annotate the expected fall-throughs and silence the warning. Link: https://lore.kernel.org/r/20240930-nolibc-fallthrough-v2-1-2e8d10fe3430@weissschuh.net Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
1 parent 711b587 commit 079ec6a

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

tools/include/nolibc/compiler.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,10 @@
3232
# define __no_stack_protector __attribute__((__optimize__("-fno-stack-protector")))
3333
#endif /* __nolibc_has_attribute(no_stack_protector) */
3434

35+
#if __nolibc_has_attribute(fallthrough)
36+
# define __nolibc_fallthrough do { } while (0); __attribute__((fallthrough))
37+
#else
38+
# define __nolibc_fallthrough do { } while (0)
39+
#endif /* __nolibc_has_attribute(fallthrough) */
40+
3541
#endif /* _NOLIBC_COMPILER_H */

tools/include/nolibc/stdio.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "stdarg.h"
1616
#include "stdlib.h"
1717
#include "string.h"
18+
#include "compiler.h"
1819

1920
#ifndef EOF
2021
#define EOF (-1)
@@ -264,7 +265,7 @@ int vfprintf(FILE *stream, const char *fmt, va_list args)
264265
case 'p':
265266
*(out++) = '0';
266267
*(out++) = 'x';
267-
/* fall through */
268+
__nolibc_fallthrough;
268269
default: /* 'x' and 'p' above */
269270
u64toh_r(v, out);
270271
break;

0 commit comments

Comments
 (0)