Skip to content

Commit f462465

Browse files
torvaldsVictorNogueiraRio
authored andcommitted
Stop the ad-hoc games with -Wno-maybe-initialized
We have some rather random rules about when we accept the "maybe-initialized" warnings, and when we don't. For example, we consider it unreliable for gcc versions < 4.9, but also if -O3 is enabled, or if optimizing for size. And then various kernel config options disabled it, because they know that they trigger that warning by confusing gcc sufficiently (ie PROFILE_ALL_BRANCHES). And now gcc-10 seems to be introducing a lot of those warnings too, so it falls under the same heading as 4.9 did. At the same time, we have a very straightforward way to _enable_ that warning when wanted: use "W=2" to enable more warnings. So stop playing these ad-hoc games, and just disable that warning by default, with the known and straight-forward "if you want to work on the extra compiler warnings, use W=123". Would it be great to have code that is always so obvious that it never confuses the compiler whether a variable is used initialized or not? Yes, it would. In a perfect world, the compilers would be smarter, and our source code would be simpler. That's currently not the world we live in, though. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 2dfb151 commit f462465

3 files changed

Lines changed: 3 additions & 23 deletions

File tree

Makefile

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -708,10 +708,6 @@ else ifdef CONFIG_CC_OPTIMIZE_FOR_SIZE
708708
KBUILD_CFLAGS += -Os
709709
endif
710710

711-
ifdef CONFIG_CC_DISABLE_WARN_MAYBE_UNINITIALIZED
712-
KBUILD_CFLAGS += -Wno-maybe-uninitialized
713-
endif
714-
715711
# Tell gcc to never replace conditional load with a non-conditional one
716712
KBUILD_CFLAGS += $(call cc-option,--param=allow-store-data-races=0)
717713

@@ -861,6 +857,9 @@ KBUILD_CFLAGS += -Wno-pointer-sign
861857
# disable stringop warnings in gcc 8+
862858
KBUILD_CFLAGS += $(call cc-disable-warning, stringop-truncation)
863859

860+
# Enabled with W=2, disabled by default as noisy
861+
KBUILD_CFLAGS += $(call cc-disable-warning, maybe-uninitialized)
862+
864863
# disable invalid "can't wrap" optimizations for signed / pointers
865864
KBUILD_CFLAGS += $(call cc-option,-fno-strict-overflow)
866865

init/Kconfig

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -36,22 +36,6 @@ config TOOLS_SUPPORT_RELR
3636
config CC_HAS_ASM_INLINE
3737
def_bool $(success,echo 'void foo(void) { asm inline (""); }' | $(CC) -x c - -c -o /dev/null)
3838

39-
config CC_HAS_WARN_MAYBE_UNINITIALIZED
40-
def_bool $(cc-option,-Wmaybe-uninitialized)
41-
help
42-
GCC >= 4.7 supports this option.
43-
44-
config CC_DISABLE_WARN_MAYBE_UNINITIALIZED
45-
bool
46-
depends on CC_HAS_WARN_MAYBE_UNINITIALIZED
47-
default CC_IS_GCC && GCC_VERSION < 40900 # unreliable for GCC < 4.9
48-
help
49-
GCC's -Wmaybe-uninitialized is not reliable by definition.
50-
Lots of false positive warnings are produced in some cases.
51-
52-
If this option is enabled, -Wno-maybe-uninitialzed is passed
53-
to the compiler to suppress maybe-uninitialized warnings.
54-
5539
config CONSTRUCTORS
5640
bool
5741
depends on !UML
@@ -1249,14 +1233,12 @@ config CC_OPTIMIZE_FOR_PERFORMANCE
12491233
config CC_OPTIMIZE_FOR_PERFORMANCE_O3
12501234
bool "Optimize more for performance (-O3)"
12511235
depends on ARC
1252-
imply CC_DISABLE_WARN_MAYBE_UNINITIALIZED # avoid false positives
12531236
help
12541237
Choosing this option will pass "-O3" to your compiler to optimize
12551238
the kernel yet more for performance.
12561239

12571240
config CC_OPTIMIZE_FOR_SIZE
12581241
bool "Optimize for size (-Os)"
1259-
imply CC_DISABLE_WARN_MAYBE_UNINITIALIZED # avoid false positives
12601242
help
12611243
Choosing this option will pass "-Os" to your compiler resulting
12621244
in a smaller kernel.

kernel/trace/Kconfig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,6 @@ config PROFILE_ANNOTATED_BRANCHES
466466
config PROFILE_ALL_BRANCHES
467467
bool "Profile all if conditionals" if !FORTIFY_SOURCE
468468
select TRACE_BRANCH_PROFILING
469-
imply CC_DISABLE_WARN_MAYBE_UNINITIALIZED # avoid false positives
470469
help
471470
This tracer profiles all branch conditions. Every if ()
472471
taken in the kernel is recorded whether it hit or miss.

0 commit comments

Comments
 (0)