]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
Makefile: Enable -Wimplicit-fallthrough for Clang
authorGustavo A. R. Silva <gustavoars@kernel.org>
Tue, 17 Aug 2021 20:33:33 +0000 (15:33 -0500)
committerGustavo A. R. Silva <gustavoars@kernel.org>
Wed, 18 Aug 2021 21:46:44 +0000 (16:46 -0500)
With the recent fixes for fallthrough warnings, it is now possible to
enable -Wimplicit-fallthrough for Clang.

Special thanks to Nathan Chancellor who fixed the Clang bug[1][2]
that put the application of this patch to a halt, temporarily. This
bugfix only appears in Clang 14.0.0, so older versions still contain
the bug and -Wimplicit-fallthrough won't be enabled for them, for
now.

As Masahiro noted, the "ifeq" conditional "will break when Clang
version 100.0.0 is released. But, before that, we will raise the
minimum supported clang version, and this conditional will go away."[3]

This concludes a long journey and now we are finally getting rid
of the unintentional fallthrough bug-class in the kernel, entirely.

[1] https://github.com/llvm/llvm-project/commit/9ed4a94d6451046a51ef393cd62f00710820a7e8
[2] https://bugs.llvm.org/show_bug.cgi?id=51094
[3] https://lore.kernel.org/lkml/CAK7LNAQFgYgavTP2ZG9Y16XBVdPuJ98J_Ty1OrQy1GXHq6JjQQ@mail.gmail.com/

Link: https://github.com/KSPP/linux/issues/115
Link: https://github.com/ClangBuiltLinux/linux/issues/236
["firstword" and "sort" was idea of Masahiro]
Suggested-by: Masahiro Yamada <masahiroy@kernel.org>
[The conditional "ifeq" was idea of Nathan]
Suggested-by: Nathan Chancellor <nathan@kernel.org>
Reviewed-by: Nathan Chancellor <nathan@kernel.org>
Tested-by: Nathan Chancellor <nathan@kernel.org>
Co-developed-by: Kees Cook <keescook@chromium.org>
Signed-off-by: Kees Cook <keescook@chromium.org>
Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
Makefile

index c19d1638da25cf32d2c6c34a82261dad336a6db4..06a228892e4e82098d6950f2a3e43c8dfec0a9ca 100644 (file)
--- 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 ($(firstword $(sort $(CONFIG_CLANG_VERSION) 140000)),140000)
+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