Suppress Clang -Wimplicit-fallthrough warnings

Since Clang doesn't properly handle

/* FALLTHROUGH */

in elf/tst-align2.c nor

/* fall through */

in misc/tst-tsearch.c

tst-align2.c💯9: error: unannotated fall-through between switch labels [-Werror,-Wimplicit-fallthrough]
  100 |         case 'A':
      |         ^
tst-align2.c💯9: note: insert '__attribute__((fallthrough));' to silence this warning
  100 |         case 'A':
      |         ^
      |         __attribute__((fallthrough));
tst-align2.c💯9: note: insert 'break;' to avoid fall-through
  100 |         case 'A':
      |         ^
      |         break;

suppress them when compiled with Clang.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
Reviewed-by: Sam James <sam@gentoo.org>
This commit is contained in:
H.J. Lu 2024-12-23 05:12:00 +08:00
parent 309225af54
commit 0813cb5847
2 changed files with 8 additions and 0 deletions

View File

@ -22,6 +22,7 @@
#include <sys/wait.h> #include <sys/wait.h>
#include <tst-stack-align.h> #include <tst-stack-align.h>
#include <unistd.h> #include <unistd.h>
#include <libc-diag.h>
static int res, fds[2], result; static int res, fds[2], result;
static bool test_destructors; static bool test_destructors;
@ -91,6 +92,8 @@ do_test (void)
int des_seen = 0, dso_des_seen = 0; int des_seen = 0, dso_des_seen = 0;
while ((len = TEMP_FAILURE_RETRY (read (fds[0], &c, 1))) > 0) while ((len = TEMP_FAILURE_RETRY (read (fds[0], &c, 1))) > 0)
{ {
DIAG_PUSH_NEEDS_COMMENT_CLANG;
DIAG_IGNORE_NEEDS_COMMENT_CLANG (3.2, "-Wimplicit-fallthrough");
switch (c) switch (c)
{ {
case 'B': case 'B':
@ -112,6 +115,7 @@ do_test (void)
result = 1; result = 1;
break; break;
} }
DIAG_POP_NEEDS_COMMENT_CLANG;
} }
close (fds[0]); close (fds[0]);

View File

@ -26,6 +26,7 @@
#include <search.h> #include <search.h>
#include <tst-stack-align.h> #include <tst-stack-align.h>
#include <support/check.h> #include <support/check.h>
#include <libc-diag.h>
#define SEED 0 #define SEED 0
#define BALANCED 1 #define BALANCED 1
@ -286,6 +287,8 @@ mangle_tree (enum order how, enum action what, void **root, int lag)
abort (); abort ();
} }
DIAG_PUSH_NEEDS_COMMENT_CLANG;
DIAG_IGNORE_NEEDS_COMMENT_CLANG (3.2, "-Wimplicit-fallthrough");
switch (what) switch (what)
{ {
case build_and_del: case build_and_del:
@ -331,6 +334,7 @@ mangle_tree (enum order how, enum action what, void **root, int lag)
break; break;
} }
DIAG_POP_NEEDS_COMMENT_CLANG;
} }
} }