From 86dfc4b099fd686e0fc70cd63bde9871dcf0ee43 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 21 Feb 2020 13:22:23 +0100 Subject: [PATCH] build: disable -Wimplicit-fallthrough warning with clang Seems clang 10 got support for -Wimplicit-fallthrough, but does not honor the code comments to suppress the warning. What a disaster. Try to detect it. See-also: https://github.com/ClangBuiltLinux/linux/issues/ #636 See-also: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=e2079e93f562c7f7a030eb7642017ee5eabaaa10 --- m4/compiler_options.m4 | 21 ++++++++++++++++++++- meson.build | 23 ++++++++++++++++++++++- 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/m4/compiler_options.m4 b/m4/compiler_options.m4 index 3ceccd983f..9adc1f14c3 100644 --- a/m4/compiler_options.m4 +++ b/m4/compiler_options.m4 @@ -70,7 +70,6 @@ if test "$GCC" = "yes" -a "$set_more_warnings" != "no"; then -Wfloat-equal \ -Wformat-nonliteral \ -Wformat-security \ - -Wimplicit-fallthrough \ -Wimplicit-function-declaration \ -Winit-self \ -Wlogical-op \ @@ -137,6 +136,26 @@ if test "$GCC" = "yes" -a "$set_more_warnings" != "no"; then [G_DEFINE_TYPE (NMObject, nm_object, G_TYPE_OBJECT)] ) + dnl clang started supporting -Wimplicit-fallthrough, but it does not + dnl honor the code comments to suppress the warning. Disable the + dnl warning with clang. + dnl + NM_COMPILER_WARNING([$1], [implicit-fallthrough], + [int foo(int a); + int foo(int a) { + int r = 0; + switch (a) { + case 1: + r++; + /* fall-through */ + case 2: + r++; + break; + } + return r; + }] + ) + eval "AS_TR_SH([$1])='$CFLAGS_MORE_WARNINGS $$1'" else AC_MSG_RESULT(no) diff --git a/meson.build b/meson.build index a5ea1d10fd..68a0c92f69 100644 --- a/meson.build +++ b/meson.build @@ -179,7 +179,6 @@ if nm_debug '-Wfloat-equal', '-Wformat-nonliteral', '-Wformat-security', - '-Wimplicit-fallthrough', '-Wimplicit-function-declaration', '-Winit-self', '-Wlogical-op', @@ -211,6 +210,28 @@ if nm_debug '-Wunknown-attributes', '-fno-strict-aliasing', ]) + + if cc.has_argument('-Wimplicit-fallthrough') + if cc.compiles(''' + int main(int argc, char **argv) { + int r = 0; + switch (argc) { + case 0: + r++; + /* fall-through */ + case 1: + r++; + break; + } + return r; + } + ''', + args: '-Werror=implicit-fallthrough', + name: '-Werror=implicit-fallthrough') + common_flags += '-Wimplicit-fallthrough' + endif + endif + endif add_project_arguments(common_flags, language: 'c')