Re: [PATCH] kbuild: Enable -Wimplicit-fallthrough for clang 14.0.0+

From: Nathan Chancellor
Date: Tue Aug 17 2021 - 14:25:41 EST

On 8/17/2021 11:03 AM, Kees Cook wrote:
On Mon, Aug 16, 2021 at 09:55:28PM -0700, Nathan Chancellor wrote:
If you/Gustavo would prefer, I can upgrade that check to

ifneq ($(call cc-option, -Wunreachable-code-fallthrough),)

I was just trying to save a call to the compiler, as that is more expensive
than a shell test call.

I prefer the option test -- this means no changes are needed on the
kernel build side if it ever finds itself backported to earlier versions
(and it handles the current case of "14" not meaning "absolute latest").

More specifically, I think you want this (untested):

That should work but since -Wunreachable-code-fallthrough is off by default, I did not really see a reason to include it in KBUILD_CFLAGS. I do not have a strong opinion though, your version is smaller than mine is so we can just go with that. I'll defer to Gustavo on it since he has put in all of the work cleaning up the warnings.


diff --git a/Makefile b/Makefile
index b5fd51e68ae9..9845ea50a368 100644
--- a/Makefile
+++ b/Makefile
@@ -859,11 +859,11 @@ 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 only if we can also
+# disable the bogus unreachable code warnings.
+KBUILD_CFLAGS += $(call cc-option,-Wimplicit-fallthrough -Wno-unreachable-code-fallthrough,)
# Warn about unmarked fall-throughs in switch statement.
-# Disabled for clang while comment to attribute conversion happens and
-# is discussed.
KBUILD_CFLAGS += $(call cc-option,-Wimplicit-fallthrough=5,)