All of lore.kernel.org
 help / color / mirror / Atom feed
From: Nathan Chancellor <nathan@kernel.org>
To: "Gustavo A. R. Silva" <gustavoars@kernel.org>,
	Linus Torvalds <torvalds@linux-foundation.org>
Cc: Kees Cook <keescook@chromium.org>,
	Nick Desaulniers <ndesaulniers@google.com>,
	Masahiro Yamada <masahiroy@kernel.org>,
	linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org,
	clang-built-linux@googlegroups.com,
	Nathan Chancellor <nathan@kernel.org>
Subject: [PATCH] kbuild: Enable -Wimplicit-fallthrough for clang 14.0.0+
Date: Mon, 16 Aug 2021 17:56:24 -0700	[thread overview]
Message-ID: <20210817005624.1455428-1-nathan@kernel.org> (raw)

Clang prior to 14.0.0 warns when a fallthrough annotation is in an
unreachable spot, which can occur when IS_ENABLED(CONFIG_...) in a
conditional statement prior to the fallthrough annotation such as

  if (IS_ENABLED(CONFIG_...))
      break;
  fallthrough;

which to clang looks like

  break;
  fallthrough;

if CONFIG_... is enabled due to the control flow graph. Example of the
warning in practice:

sound/core/pcm_native.c:3812:3: warning: fallthrough annotation in
unreachable code [-Wimplicit-fallthrough]
                fallthrough;
                ^

Warning on unreachable annotations makes the warning too noisy and
pointless for the kernel due to the nature of guarding some code on
configuration options so it was disabled in commit d936eb238744 ("Revert
"Makefile: Enable -Wimplicit-fallthrough for Clang"").

This has been resolved in clang 14.0.0 by moving the unreachable warning
to its own flag under -Wunreachable-code, which the kernel will most
likely never enable due to situations like this.

Enable -Wimplicit-fallthrough for clang 14+ so that issues such as the
one in commit 652b44453ea9 ("habanalabs/gaudi: fix missing code in ECC
handling") can be caught before they enter the tree.

Link: https://github.com/ClangBuiltLinux/linux/issues/236
Link: https://github.com/llvm/llvm-project/commit/9ed4a94d6451046a51ef393cd62f00710820a7e8
Signed-off-by: Nathan Chancellor <nathan@kernel.org>
---
 Makefile | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/Makefile b/Makefile
index c19d1638da25..91a4a80409e1 100644
--- a/Makefile
+++ b/Makefile
@@ -797,11 +797,17 @@ KBUILD_CFLAGS += -Wno-gnu
 # source of a reference will be _MergedGlobals and not on of the whitelisted names.
 # See modpost pattern 2
 KBUILD_CFLAGS += -mno-global-merge
+
+# Warn about unmarked fall-throughs in switch statement.
+# Clang prior to 14.0.0 warned on unreachable fallthroughs with
+# -Wimplicit-fallthrough, which is unacceptable due to IS_ENABLED().
+# https://bugs.llvm.org/show_bug.cgi?id=51094
+ifeq ($(shell test $(CONFIG_CLANG_VERSION) -ge 140000; echo $$?),0)
+KBUILD_CFLAGS += -Wimplicit-fallthrough
+endif
 else
 
 # Warn about unmarked fall-throughs in switch statement.
-# Disabled for clang while comment to attribute conversion happens and
-# https://github.com/ClangBuiltLinux/linux/issues/636 is discussed.
 KBUILD_CFLAGS += $(call cc-option,-Wimplicit-fallthrough=5,)
 endif
 

base-commit: a2824f19e6065a0d3735acd9fe7155b104e7edf5
-- 
2.33.0


             reply	other threads:[~2021-08-17  0:57 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-17  0:56 Nathan Chancellor [this message]
2021-08-17  4:16 ` [PATCH] kbuild: Enable -Wimplicit-fallthrough for clang 14.0.0+ kernel test robot
2021-08-17  4:16   ` kernel test robot
2021-08-17  4:20 ` Nathan Chancellor
2021-08-17  4:37   ` Linus Torvalds
2021-08-17  4:55     ` Nathan Chancellor
2021-08-17 18:03       ` Kees Cook
2021-08-17 18:25         ` Nathan Chancellor
2021-08-17 21:17           ` Masahiro Yamada
2021-08-17 21:33             ` Gustavo A. R. Silva
2021-08-17 23:06               ` Kees Cook
2021-08-17 23:23                 ` Nathan Chancellor
2021-08-17 23:40                   ` Gustavo A. R. Silva
2021-08-18  4:15                   ` Masahiro Yamada
2021-08-18  4:27                   ` Philip Li
2021-08-18  4:45                     ` Gustavo A. R. Silva
2021-08-18  7:31                       ` Philip Li
2021-08-18 12:12                   ` Mark Brown
2021-08-25 21:09             ` Nick Desaulniers

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210817005624.1455428-1-nathan@kernel.org \
    --to=nathan@kernel.org \
    --cc=clang-built-linux@googlegroups.com \
    --cc=gustavoars@kernel.org \
    --cc=keescook@chromium.org \
    --cc=linux-kbuild@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=masahiroy@kernel.org \
    --cc=ndesaulniers@google.com \
    --cc=torvalds@linux-foundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.