[PATCH 37/39] Suppress Clang -Wimplicit-fallthrough warnings
Sam James
sam@gentoo.org
Sun Dec 22 04:59:27 GMT 2024
"H.J. Lu" <hjl.tools@gmail.com> writes:
> Since Clang doesn't properly handle
>
> /* FALLTHROUGH */
>
> in elf/tst-align2.c nor
>
> /* fall through */
>
> in misc/tst-tsearch.c
>
> tst-align2.c:100:9: error: unannotated fall-through between switch labels [-Werror,-Wimplicit-fallthrough]
> 100 | case 'A':
> | ^
> tst-align2.c:100:9: note: insert '__attribute__((fallthrough));' to silence this warning
> 100 | case 'A':
> | ^
> | __attribute__((fallthrough));
> tst-align2.c:100: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>
> ---
> configure | 7 +++++++
> configure.ac | 7 +++++++
> elf/Makefile | 3 +++
> misc/Makefile | 3 +++
> 4 files changed, 20 insertions(+)
>
> diff --git a/configure b/configure
> index 8e47743afb..103b5f2fb1 100755
> --- a/configure
> +++ b/configure
> @@ -8124,6 +8124,13 @@ fi
> config_vars="$config_vars
> cc-option-wimplicit-fallthrough = $libc_cv_cc_wimplicit_fallthrough"
>
> +if test -n "$libc_cv_test_cc_wimplicit_fallthrough"; then
> + libc_cv_test_cc_wno_implicit_fallthrough="-Wno-implicit-fallthrough"
> +else
> + libc_cv_test_cc_wno_implicit_fallthrough=
> +fi
> +config_vars="$config_vars
> +cc-option-wno-implicit-fallthrough = $libc_cv_test_cc_wno_implicit_fallthrough"
>
> { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for libgd" >&5
> printf %s "checking for libgd... " >&6; }
> diff --git a/configure.ac b/configure.ac
> index d39e16b9ec..ec3992b3ed 100644
> --- a/configure.ac
> +++ b/configure.ac
> @@ -1647,6 +1647,13 @@ LIBC_TRY_CC_AND_TEST_CC_OPTION([for -Wimplicit-fallthrough],
> LIBC_CONFIG_VAR([cc-option-wimplicit-fallthrough],
> [$libc_cv_cc_wimplicit_fallthrough])
> AC_SUBST(libc_cv_test_cc_wimplicit_fallthrough)
> +if test -n "$libc_cv_test_cc_wimplicit_fallthrough"; then
> + libc_cv_test_cc_wno_implicit_fallthrough="-Wno-implicit-fallthrough"
> +else
> + libc_cv_test_cc_wno_implicit_fallthrough=
> +fi
> +LIBC_CONFIG_VAR([cc-option-wno-implicit-fallthrough],
> + [$libc_cv_test_cc_wno_implicit_fallthrough])
>
> dnl Check whether we have the gd library available.
> AC_MSG_CHECKING(for libgd)
> diff --git a/elf/Makefile b/elf/Makefile
> index 68fde4f226..edb08972c9 100644
> --- a/elf/Makefile
> +++ b/elf/Makefile
> @@ -1910,6 +1910,9 @@ $(objpfx)tst-tls19.out: $(objpfx)tst-tls19mod1.so
>
> CFLAGS-tst-align.c += $(stack-align-test-flags)
> CFLAGS-tst-align2.c += $(stack-align-test-flags)
> +ifeq ($(have-test-clang),yes)
> +CFLAGS-tst-align2.c += $(cc-option-wno-implicit-fallthrough)
> +endif
> CFLAGS-tst-alignmod.c += $(stack-align-test-flags)
> CFLAGS-tst-alignmod2.c += $(stack-align-test-flags)
> $(objpfx)tst-align.out: $(objpfx)tst-alignmod.so
> diff --git a/misc/Makefile b/misc/Makefile
> index acd247f2e4..205e7a7ad4 100644
> --- a/misc/Makefile
> +++ b/misc/Makefile
> @@ -338,6 +338,9 @@ CFLAGS-getsysstats.c += -fexceptions
> CFLAGS-getusershell.c += -fexceptions
> CFLAGS-err.c += -fexceptions
> CFLAGS-tst-tsearch.c += $(stack-align-test-flags)
> +ifeq ($(have-test-clang),yes)
> +CFLAGS-tst-tsearch.c += $(cc-option-wno-implicit-fallthrough)
> +endif
> CFLAGS-msync.c += -fexceptions -fasynchronous-unwind-tables
> CFLAGS-fdatasync.c += -fexceptions -fasynchronous-unwind-tables
> CFLAGS-fsync.c += -fexceptions -fasynchronous-unwind-tables
> --
> 2.47.1
> ---
> elf/tst-align2.c | 4 ++++
> misc/tst-tsearch.c | 4 ++++
> 2 files changed, 8 insertions(+)
>
> diff --git a/elf/tst-align2.c b/elf/tst-align2.c
> index c73ea5a5fe..c49ed70c17 100644
> --- a/elf/tst-align2.c
> +++ b/elf/tst-align2.c
> @@ -22,6 +22,7 @@
> #include <sys/wait.h>
> #include <tst-stack-align.h>
> #include <unistd.h>
> +#include <libc-diag.h>
>
> static int res, fds[2], result;
> static bool test_destructors;
> @@ -91,6 +92,8 @@ do_test (void)
> int des_seen = 0, dso_des_seen = 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)
> {
> case 'B':
> @@ -112,6 +115,7 @@ do_test (void)
> result = 1;
> break;
> }
> + DIAG_POP_NEEDS_COMMENT_CLANG;
> }
>
> close (fds[0]);
> diff --git a/misc/tst-tsearch.c b/misc/tst-tsearch.c
> index 2ca561dd7d..2a8f13f774 100644
> --- a/misc/tst-tsearch.c
> +++ b/misc/tst-tsearch.c
> @@ -26,6 +26,7 @@
> #include <search.h>
> #include <tst-stack-align.h>
> #include <support/check.h>
> +#include <libc-diag.h>
>
> #define SEED 0
> #define BALANCED 1
> @@ -286,6 +287,8 @@ mangle_tree (enum order how, enum action what, void **root, int lag)
> abort ();
> }
>
> + DIAG_PUSH_NEEDS_COMMENT_CLANG;
> + DIAG_IGNORE_NEEDS_COMMENT_CLANG (3.2, "-Wimplicit-fallthrough");
Why is this needed with the configure check?
> switch (what)
> {
> case build_and_del:
> @@ -331,6 +334,7 @@ mangle_tree (enum order how, enum action what, void **root, int lag)
> break;
>
> }
> + DIAG_POP_NEEDS_COMMENT_CLANG;
> }
> }
More information about the Libc-alpha
mailing list