Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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/20240326230511.GA2796782@dev-arch.thelio-3990X/
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/20240415122037.1983124-5-arnd@kernel.org
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Cc: Kees Cook <keescook@chromium.org>
Cc: Masahiro Yamada <masahiroy@kernel.org>
Cc: Nathan Chancellor <nathan@kernel.org>
Cc: Nicolas Schier <nicolas@fjasle.eu>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Arnd Bergmann and committed by
Andrew Morton
908dd508 06bb7fc0

+7
+7
scripts/Makefile.extrawarn
··· 100 100 KBUILD_CFLAGS += $(call cc-disable-warning, unused-const-variable) 101 101 KBUILD_CFLAGS += $(call cc-disable-warning, packed-not-aligned) 102 102 KBUILD_CFLAGS += $(call cc-disable-warning, format-overflow) 103 + ifdef CONFIG_CC_IS_GCC 103 104 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 104 111 KBUILD_CFLAGS += $(call cc-disable-warning, stringop-truncation) 105 112 106 113 KBUILD_CFLAGS += -Wno-override-init # alias for -Wno-initializer-overrides in clang