Skip to content

Commit b0839b2

Browse files
nickdesaulnierstorvalds
authored andcommitted
Makefile.extrawarn: re-enable -Wformat for clang; take 2
-Wformat was recently re-enabled for builds with clang, then quickly re-disabled, due to concerns stemming from the frequency of default argument promotion related warning instances. commit 258fafc ("Makefile.extrawarn: re-enable -Wformat for clang") commit 21f9c8a ("Revert "Makefile.extrawarn: re-enable -Wformat for clang"") ISO WG14 has ratified N2562 to address default argument promotion explicitly for printf, as part of the upcoming ISO C2X standard. The behavior of clang was changed in clang-16 to not warn for the cited cases in all language modes. Add a version check, so that users of clang-16 now get the full effect of -Wformat. For older clang versions, re-enable flags under the -Wformat group that way users still get some useful checks related to format strings, without noisy default argument promotion warnings. I intentionally omitted -Wformat-y2k and -Wformat-security from being re-enabled, which are also part of -Wformat in clang-16. Link: ClangBuiltLinux/linux#378 Link: llvm/llvm-project#57102 Link: https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2562.pdf Suggested-by: Justin Stitt <[email protected]> Suggested-by: Nathan Chancellor <[email protected]> Suggested-by: Youngmin Nam <[email protected]> Signed-off-by: Nick Desaulniers <[email protected]> Reviewed-by: Masahiro Yamada <[email protected]> Reviewed-by: Nathan Chancellor <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 7726d4c commit b0839b2

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

scripts/Makefile.extrawarn

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,19 @@ else
4747

4848
ifdef CONFIG_CC_IS_CLANG
4949
KBUILD_CFLAGS += -Wno-initializer-overrides
50+
# Clang before clang-16 would warn on default argument promotions.
51+
ifeq ($(shell [ $(CONFIG_CLANG_VERSION) -lt 160000 ] && echo y),y)
52+
# Disable -Wformat
5053
KBUILD_CFLAGS += -Wno-format
54+
# Then re-enable flags that were part of the -Wformat group that aren't
55+
# problematic.
56+
KBUILD_CFLAGS += -Wformat-extra-args -Wformat-invalid-specifier
57+
KBUILD_CFLAGS += -Wformat-zero-length -Wnonnull
58+
# Requires clang-12+.
59+
ifeq ($(shell [ $(CONFIG_CLANG_VERSION) -ge 120000 ] && echo y),y)
60+
KBUILD_CFLAGS += -Wformat-insufficient-args
61+
endif
62+
endif
5163
KBUILD_CFLAGS += -Wno-sign-compare
5264
KBUILD_CFLAGS += $(call cc-disable-warning, pointer-to-enum-cast)
5365
KBUILD_CFLAGS += -Wno-tautological-constant-out-of-range-compare

0 commit comments

Comments
 (0)