From dee2b702bcf067d7b6b62c18bdd060ff0810a800 Mon Sep 17 00:00:00 2001 From: "Gustavo A. R. Silva" Date: Sat, 13 Nov 2021 18:57:25 -0600 Subject: 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: https://github.com/llvm/llvm-project/commit/9ed4a94d6451046a51ef393cd62f00710820a7e8 [1] Link: https://bugs.llvm.org/show_bug.cgi?id=51094 [2] Link: https://github.com/KSPP/linux/issues/115 Link: https://github.com/ClangBuiltLinux/linux/issues/236 Co-developed-by: Kees Cook Signed-off-by: Kees Cook Co-developed-by: Linus Torvalds Signed-off-by: Linus Torvalds Signed-off-by: Gustavo A. R. Silva Reviewed-by: Nathan Chancellor Tested-by: Nathan Chancellor Signed-off-by: Linus Torvalds --- init/Kconfig | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'init') diff --git a/init/Kconfig b/init/Kconfig index 45bcaa8e7481..036b750e8d8a 100644 --- a/init/Kconfig +++ b/init/Kconfig @@ -885,6 +885,11 @@ config ARCH_WANT_BATCHED_UNMAP_TLB_FLUSH config CC_HAS_INT128 def_bool !$(cc-option,$(m64-flag) -D__SIZEOF_INT128__=0) && 64BIT +config CC_IMPLICIT_FALLTHROUGH + string + default "-Wimplicit-fallthrough=5" if CC_IS_GCC + default "-Wimplicit-fallthrough" if CC_IS_CLANG && $(cc-option,-Wunreachable-code-fallthrough) + # # For architectures that know their GCC __int128 support is sound # -- cgit