Skip to content

Commit 908dd50

Browse files
arndbakpm00
authored andcommitted
kbuild: enable -Wformat-truncation on clang
This warning option still produces output on gcc but is now clean when building with clang, so enable it conditionally on the compiler for now. As far as I can tell, the remaining warnings with gcc are the result of analysing the code more deeply across inlining, while clang only does this within a function. Link: https://lore.kernel.org/lkml/[email protected]/ Link: https://lore.kernel.org/linux-patches/20231002-disable-wformat-truncation-overflow-non-kprintf-v1-1-35179205c8d9@kernel.org/ Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Arnd Bergmann <[email protected]> Cc: Kees Cook <[email protected]> Cc: Masahiro Yamada <[email protected]> Cc: Nathan Chancellor <[email protected]> Cc: Nicolas Schier <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 06bb7fc commit 908dd50

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

scripts/Makefile.extrawarn

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,14 @@ KBUILD_CFLAGS += $(call cc-disable-warning, unused-but-set-variable)
100100
KBUILD_CFLAGS += $(call cc-disable-warning, unused-const-variable)
101101
KBUILD_CFLAGS += $(call cc-disable-warning, packed-not-aligned)
102102
KBUILD_CFLAGS += $(call cc-disable-warning, format-overflow)
103+
ifdef CONFIG_CC_IS_GCC
103104
KBUILD_CFLAGS += $(call cc-disable-warning, format-truncation)
105+
else
106+
# Clang checks for overflow/truncation with '%p', while GCC does not:
107+
# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111219
108+
KBUILD_CFLAGS += $(call cc-disable-warning, format-overflow-non-kprintf)
109+
KBUILD_CFLAGS += $(call cc-disable-warning, format-truncation-non-kprintf)
110+
endif
104111
KBUILD_CFLAGS += $(call cc-disable-warning, stringop-truncation)
105112

106113
KBUILD_CFLAGS += -Wno-override-init # alias for -Wno-initializer-overrides in clang

0 commit comments

Comments
 (0)