]> Git Repo - linux.git/commitdiff
tools/nolibc: compiler: add macro __nolibc_fallthrough
authorThomas Weißschuh <[email protected]>
Mon, 30 Sep 2024 05:35:19 +0000 (07:35 +0200)
committerThomas Weißschuh <[email protected]>
Mon, 7 Oct 2024 19:56:18 +0000 (21:56 +0200)
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/[email protected]
Signed-off-by: Thomas Weißschuh <[email protected]>
tools/include/nolibc/compiler.h
tools/include/nolibc/stdio.h

index 9bc6a706a332378e5af1f5baabf953f137f99749..fa1f547e7f13d151ea98b9c585b36659d2d27324 100644 (file)
 #  define __no_stack_protector __attribute__((__optimize__("-fno-stack-protector")))
 #endif /* __nolibc_has_attribute(no_stack_protector) */
 
+#if __nolibc_has_attribute(fallthrough)
+#  define __nolibc_fallthrough do { } while (0); __attribute__((fallthrough))
+#else
+#  define __nolibc_fallthrough do { } while (0)
+#endif /* __nolibc_has_attribute(fallthrough) */
+
 #endif /* _NOLIBC_COMPILER_H */
index c968dbbc4ef8137e237b859bf18a6d2970230cbf..3892034198dd566d21a5cc0a9f67cf097d428393 100644 (file)
@@ -15,6 +15,7 @@
 #include "stdarg.h"
 #include "stdlib.h"
 #include "string.h"
+#include "compiler.h"
 
 #ifndef EOF
 #define EOF (-1)
@@ -264,7 +265,7 @@ int vfprintf(FILE *stream, const char *fmt, va_list args)
                                case 'p':
                                        *(out++) = '0';
                                        *(out++) = 'x';
-                                       /* fall through */
+                                       __nolibc_fallthrough;
                                default: /* 'x' and 'p' above */
                                        u64toh_r(v, out);
                                        break;
This page took 0.055971 seconds and 4 git commands to generate.