Skip to content

Commit dee2b70

Browse files
GustavoARSilvatorvalds
authored andcommitted
kconfig: Add support for -Wimplicit-fallthrough
Add Kconfig support for -Wimplicit-fallthrough for both GCC and Clang. The compiler option is under configuration CC_IMPLICIT_FALLTHROUGH, which is enabled by default. Special thanks to Nathan Chancellor who fixed the Clang bug[1][2]. 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. :) Link: llvm/llvm-project@9ed4a94 [1] Link: https://bugs.llvm.org/show_bug.cgi?id=51094 [2] Link: KSPP/linux#115 Link: ClangBuiltLinux/linux#236 Co-developed-by: Kees Cook <[email protected]> Signed-off-by: Kees Cook <[email protected]> Co-developed-by: Linus Torvalds <[email protected]> Signed-off-by: Linus Torvalds <[email protected]> Signed-off-by: Gustavo A. R. Silva <[email protected]> Reviewed-by: Nathan Chancellor <[email protected]> Tested-by: Nathan Chancellor <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent ce49bfc commit dee2b70

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

Makefile

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -789,7 +789,7 @@ stackp-flags-$(CONFIG_STACKPROTECTOR_STRONG) := -fstack-protector-strong
789789
KBUILD_CFLAGS += $(stackp-flags-y)
790790

791791
KBUILD_CFLAGS-$(CONFIG_WERROR) += -Werror
792-
KBUILD_CFLAGS += $(KBUILD_CFLAGS-y)
792+
KBUILD_CFLAGS += $(KBUILD_CFLAGS-y) $(CONFIG_CC_IMPLICIT_FALLTHROUGH)
793793

794794
ifdef CONFIG_CC_IS_CLANG
795795
KBUILD_CPPFLAGS += -Qunused-arguments
@@ -801,10 +801,6 @@ KBUILD_CFLAGS += -Wno-gnu
801801
KBUILD_CFLAGS += -mno-global-merge
802802
else
803803

804-
# Warn about unmarked fall-throughs in switch statement.
805-
# Disabled for clang while comment to attribute conversion happens and
806-
# https://github.com/ClangBuiltLinux/linux/issues/636 is discussed.
807-
KBUILD_CFLAGS += $(call cc-option,-Wimplicit-fallthrough=5,)
808804
# gcc inanely warns about local variables called 'main'
809805
KBUILD_CFLAGS += -Wno-main
810806
endif

init/Kconfig

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -885,6 +885,11 @@ config ARCH_WANT_BATCHED_UNMAP_TLB_FLUSH
885885
config CC_HAS_INT128
886886
def_bool !$(cc-option,$(m64-flag) -D__SIZEOF_INT128__=0) && 64BIT
887887

888+
config CC_IMPLICIT_FALLTHROUGH
889+
string
890+
default "-Wimplicit-fallthrough=5" if CC_IS_GCC
891+
default "-Wimplicit-fallthrough" if CC_IS_CLANG && $(cc-option,-Wunreachable-code-fallthrough)
892+
888893
#
889894
# For architectures that know their GCC __int128 support is sound
890895
#

0 commit comments

Comments
 (0)