History

kbuild: avoid duplicate warning options

Some warning options are disabled at one place and then conditionally re-enabled later in scripts/Makefile.extrawarn. For consistency, rework this file so each of those warnings only gets etiher enabled or disabled based on the W= flags but not both.

Arnd Bergmann committed 3 years ago

Commit 2cd32711 parent e88ca241 file · +26 −17Browse files

Unified · Split

scripts/Makefile.extrawarn+26−17
@@ -56,20 +56,12 @@ KBUILD_CFLAGS += -Wno-pointer-sign · 55 unmodified lines
5656 # globally built with -Wcast-function-type.
5757 KBUILD_CFLAGS += $(call cc-option, -Wcast-function-type)
5858
59−# disable stringop warnings in gcc 8+
60−KBUILD_CFLAGS += $(call cc-disable-warning, stringop-truncation)
61−
6259 # We'll want to enable this eventually, but it's not going away for 5.7 at least
6360 KBUILD_CFLAGS += $(call cc-disable-warning, stringop-overflow)
6461
6562 # Another good warning that we'll want to enable eventually
6663 KBUILD_CFLAGS += $(call cc-disable-warning, restrict)
6764
68−# Enabled with W=2, disabled by default as noisy
69−ifdef CONFIG_CC_IS_GCC
70−KBUILD_CFLAGS += -Wno-maybe-uninitialized
71−endif
72−
7365 # The allocators already balk at large sizes, so silence the compiler
7466 # warnings for bounds checks involving those possible values. While
7567 # -Wno-alloc-size-larger-than would normally be used here, earlier versions
@@ -96,8 +88,6 @@ KBUILD_CFLAGS += $(call cc-option,-Werror=designated-init) · 20 unmodified lines
9688 # Warn if there is an enum types mismatch
9789 KBUILD_CFLAGS += $(call cc-option,-Wenum-conversion)
9890
99−KBUILD_CFLAGS += $(call cc-disable-warning, packed-not-aligned)
100−
10191 # backward compatibility
10292 KBUILD_EXTRA_WARN ?= $(KBUILD_ENABLE_EXTRA_GCC_CHECKS)
10393
@@ -122,11 +112,6 @@ KBUILD_CFLAGS += $(call cc-option, -Wunused-but-set-variable) · 18 unmodified lines
122112 KBUILD_CFLAGS += $(call cc-option, -Wunused-const-variable)
123113 KBUILD_CFLAGS += $(call cc-option, -Wpacked-not-aligned)
124114 KBUILD_CFLAGS += $(call cc-option, -Wstringop-truncation)
125−# The following turn off the warnings enabled by -Wextra
126−KBUILD_CFLAGS += -Wno-missing-field-initializers
127−KBUILD_CFLAGS += -Wno-sign-compare
128−KBUILD_CFLAGS += -Wno-type-limits
129−KBUILD_CFLAGS += -Wno-shift-negative-value
130115
131116 KBUILD_CPPFLAGS += -Wundef
132117 KBUILD_CPPFLAGS += -DKBUILD_EXTRA_WARN1
@@ -135,9 +120,12 @@ else · 2 unmodified lines
135120
136121 # Some diagnostics enabled by default are noisy.
137122 # Suppress them by using -Wno... except for W=1.
123+KBUILD_CFLAGS += $(call cc-disable-warning, unused-but-set-variable)
124+KBUILD_CFLAGS += $(call cc-disable-warning, unused-const-variable)
125+KBUILD_CFLAGS += $(call cc-disable-warning, packed-not-aligned)
126+KBUILD_CFLAGS += $(call cc-disable-warning, stringop-truncation)
138127
139128 ifdef CONFIG_CC_IS_CLANG
140−KBUILD_CFLAGS += -Wno-initializer-overrides
141129 # Clang before clang-16 would warn on default argument promotions.
142130 ifneq ($(call clang-min-version, 160000),y)
143131 # Disable -Wformat
@@ -151,7 +139,6 @@ ifeq ($(call clang-min-version, 120000),y) · 7 unmodified lines
151139 KBUILD_CFLAGS += -Wformat-insufficient-args
152140 endif
153141 endif
154−KBUILD_CFLAGS += -Wno-sign-compare
155142 KBUILD_CFLAGS += $(call cc-disable-warning, pointer-to-enum-cast)
156143 KBUILD_CFLAGS += -Wno-tautological-constant-out-of-range-compare
157144 KBUILD_CFLAGS += $(call cc-disable-warning, unaligned-access)
@@ -173,8 +160,25 @@ KBUILD_CFLAGS += -Wtype-limits · 15 unmodified lines
173160 KBUILD_CFLAGS += $(call cc-option, -Wmaybe-uninitialized)
174161 KBUILD_CFLAGS += $(call cc-option, -Wunused-macros)
175162
163+ifdef CONFIG_CC_IS_CLANG
164+KBUILD_CFLAGS += -Winitializer-overrides
165+endif
166+
176167 KBUILD_CPPFLAGS += -DKBUILD_EXTRA_WARN2
177168
169+else
170+
171+# The following turn off the warnings enabled by -Wextra
172+KBUILD_CFLAGS += -Wno-missing-field-initializers
173+KBUILD_CFLAGS += -Wno-type-limits
174+KBUILD_CFLAGS += -Wno-shift-negative-value
175+
176+ifdef CONFIG_CC_IS_CLANG
177+KBUILD_CFLAGS += -Wno-initializer-overrides
178+else
179+KBUILD_CFLAGS += -Wno-maybe-uninitialized
180+endif
181+
178182 endif
179183
180184 #
@@ -196,6 +200,11 @@ KBUILD_CFLAGS += $(call cc-option, -Wpacked-bitfield-compat) · 15 unmodified lines
196200
197201 KBUILD_CPPFLAGS += -DKBUILD_EXTRA_WARN3
198202
203+else
204+
205+# The following turn off the warnings enabled by -Wextra
206+KBUILD_CFLAGS += -Wno-sign-compare
207+
199208 endif
200209
201210 #