Skip to content

Commit dd8a734

Browse files
nathanchancegregkh
authored andcommitted
kbuild: Properly disable -Wunterminated-string-initialization for clang
commit 4f79eaa upstream. Clang and GCC have different behaviors around disabling warnings included in -Wall and -Wextra and the order in which flags are specified, which is exposed by clang's new support for -Wunterminated-string-initialization. $ cat test.c const char foo[3] = "FOO"; const char bar[3] __attribute__((__nonstring__)) = "BAR"; $ clang -fsyntax-only -Wextra test.c test.c:1:21: warning: initializer-string for character array is too long, array size is 3 but initializer has size 4 (including the null terminating character); did you mean to use the 'nonstring' attribute? [-Wunterminated-string-initialization] 1 | const char foo[3] = "FOO"; | ^~~~~ $ clang -fsyntax-only -Wextra -Wno-unterminated-string-initialization test.c $ clang -fsyntax-only -Wno-unterminated-string-initialization -Wextra test.c test.c:1:21: warning: initializer-string for character array is too long, array size is 3 but initializer has size 4 (including the null terminating character); did you mean to use the 'nonstring' attribute? [-Wunterminated-string-initialization] 1 | const char foo[3] = "FOO"; | ^~~~~ $ gcc -fsyntax-only -Wextra test.c test.c:1:21: warning: initializer-string for array of ‘char’ truncates NUL terminator but destination lacks ‘nonstring’ attribute (4 chars into 3 available) [-Wunterminated-string-initialization] 1 | const char foo[3] = "FOO"; | ^~~~~ $ gcc -fsyntax-only -Wextra -Wno-unterminated-string-initialization test.c $ gcc -fsyntax-only -Wno-unterminated-string-initialization -Wextra test.c Move -Wextra up right below -Wall in Makefile.extrawarn to ensure these flags are at the beginning of the warning options list. Move the couple of warning options that have been added to the main Makefile since commit e88ca24 ("kbuild: consolidate warning flags in scripts/Makefile.extrawarn") to scripts/Makefile.extrawarn after -Wall / -Wextra to ensure they get properly disabled for all compilers. Fixes: 9d7a057 ("gcc-15: disable '-Wunterminated-string-initialization' entirely for now") Link: llvm/llvm-project#10359 Signed-off-by: Nathan Chancellor <[email protected]> Signed-off-by: Linus Torvalds <[email protected]> Signed-off-by: Nathan Chancellor <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 3f856d5 commit dd8a734

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

Makefile

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -997,13 +997,6 @@ NOSTDINC_FLAGS += -nostdinc
997997
# perform bounds checking.
998998
KBUILD_CFLAGS += $(call cc-option, -fstrict-flex-arrays=3)
999999

1000-
#Currently, disable -Wstringop-overflow for GCC 11, globally.
1001-
KBUILD_CFLAGS-$(CONFIG_CC_NO_STRINGOP_OVERFLOW) += $(call cc-disable-warning, stringop-overflow)
1002-
KBUILD_CFLAGS-$(CONFIG_CC_STRINGOP_OVERFLOW) += $(call cc-option, -Wstringop-overflow)
1003-
1004-
#Currently, disable -Wunterminated-string-initialization as broken
1005-
KBUILD_CFLAGS += $(call cc-disable-warning, unterminated-string-initialization)
1006-
10071000
# disable invalid "can't wrap" optimizations for signed / pointers
10081001
KBUILD_CFLAGS += -fno-strict-overflow
10091002

scripts/Makefile.extrawarn

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
# Default set of warnings, always enabled
1010
KBUILD_CFLAGS += -Wall
11+
KBUILD_CFLAGS += -Wextra
1112
KBUILD_CFLAGS += -Wundef
1213
KBUILD_CFLAGS += -Werror=implicit-function-declaration
1314
KBUILD_CFLAGS += -Werror=implicit-int
@@ -68,6 +69,13 @@ KBUILD_CFLAGS += -Wno-pointer-sign
6869
# globally built with -Wcast-function-type.
6970
KBUILD_CFLAGS += $(call cc-option, -Wcast-function-type)
7071

72+
# Currently, disable -Wstringop-overflow for GCC 11, globally.
73+
KBUILD_CFLAGS-$(CONFIG_CC_NO_STRINGOP_OVERFLOW) += $(call cc-disable-warning, stringop-overflow)
74+
KBUILD_CFLAGS-$(CONFIG_CC_STRINGOP_OVERFLOW) += $(call cc-option, -Wstringop-overflow)
75+
76+
# Currently, disable -Wunterminated-string-initialization as broken
77+
KBUILD_CFLAGS += $(call cc-disable-warning, unterminated-string-initialization)
78+
7179
# The allocators already balk at large sizes, so silence the compiler
7280
# warnings for bounds checks involving those possible values. While
7381
# -Wno-alloc-size-larger-than would normally be used here, earlier versions
@@ -97,7 +105,6 @@ KBUILD_CFLAGS += $(call cc-option,-Wenum-conversion)
97105
# Explicitly clear padding bits during variable initialization
98106
KBUILD_CFLAGS += $(call cc-option,-fzero-init-padding-bits=all)
99107

100-
KBUILD_CFLAGS += -Wextra
101108
KBUILD_CFLAGS += -Wunused
102109

103110
#

0 commit comments

Comments
 (0)