aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGustavo A. R. Silva <gustavoars@kernel.org>2021-09-13 16:45:28 -0500
committerGustavo A. R. Silva <gustavoars@kernel.org>2021-10-13 14:48:18 -0500
commit9bed5200e04d2a3dcd3a420d249e947eac7ec7c1 (patch)
tree5dfd844c4b7ba0f5a3953ad192998bcb66537466
parent02900f428d3c7acd89b77784bec33ddec7b750a4 (diff)
downloadlinux-9bed5200e04d2a3dcd3a420d249e947eac7ec7c1.tar.gz
Makefile: Enable -Wimplicit-fallthrough for Clang
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. 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 Link: https://github.com/KSPP/linux/issues/115 Link: https://github.com/ClangBuiltLinux/linux/issues/236 [The conditional "ifneq" 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>
-rw-r--r--Makefile8
1 files changed, 8 insertions, 0 deletions
diff --git a/Makefile b/Makefile
index 5e7c1d8544412..eb44b3b0c5bce 100644
--- a/Makefile
+++ b/Makefile
@@ -796,6 +796,14 @@ 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 as long as
+# -Wunreachable-code-fallthrough is present. Clang prior to 14
+# warned on unreachable fallthroughs with -Wimplicit-fallthrough,
+# which is unacceptable due to IS_ENABLED().
+# https://bugs.llvm.org/show_bug.cgi?id=51094
+ifneq ($(call cc-option,-Wunreachable-code-fallthrough),)
+KBUILD_CFLAGS += -Wimplicit-fallthrough
+endif
else
# Warn about unmarked fall-throughs in switch statement.