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

Configure Feed

Select the types of activity you want to include in your feed.

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>

+3 -23
+3 -4
Makefile
··· 729 729 KBUILD_CFLAGS += -Os 730 730 endif 731 731 732 - ifdef CONFIG_CC_DISABLE_WARN_MAYBE_UNINITIALIZED 733 - KBUILD_CFLAGS += -Wno-maybe-uninitialized 734 - endif 735 - 736 732 # Tell gcc to never replace conditional load with a non-conditional one 737 733 KBUILD_CFLAGS += $(call cc-option,--param=allow-store-data-races=0) 738 734 KBUILD_CFLAGS += $(call cc-option,-fno-allow-store-data-races) ··· 876 880 877 881 # disable stringop warnings in gcc 8+ 878 882 KBUILD_CFLAGS += $(call cc-disable-warning, stringop-truncation) 883 + 884 + # Enabled with W=2, disabled by default as noisy 885 + KBUILD_CFLAGS += $(call cc-disable-warning, maybe-uninitialized) 879 886 880 887 # disable invalid "can't wrap" optimizations for signed / pointers 881 888 KBUILD_CFLAGS += $(call cc-option,-fno-strict-overflow)
-18
init/Kconfig
··· 39 39 config CC_HAS_ASM_INLINE 40 40 def_bool $(success,echo 'void foo(void) { asm inline (""); }' | $(CC) -x c - -c -o /dev/null) 41 41 42 - config CC_HAS_WARN_MAYBE_UNINITIALIZED 43 - def_bool $(cc-option,-Wmaybe-uninitialized) 44 - help 45 - GCC >= 4.7 supports this option. 46 - 47 - config CC_DISABLE_WARN_MAYBE_UNINITIALIZED 48 - bool 49 - depends on CC_HAS_WARN_MAYBE_UNINITIALIZED 50 - default CC_IS_GCC && GCC_VERSION < 40900 # unreliable for GCC < 4.9 51 - help 52 - GCC's -Wmaybe-uninitialized is not reliable by definition. 53 - Lots of false positive warnings are produced in some cases. 54 - 55 - If this option is enabled, -Wno-maybe-uninitialzed is passed 56 - to the compiler to suppress maybe-uninitialized warnings. 57 - 58 42 config CONSTRUCTORS 59 43 bool 60 44 depends on !UML ··· 1241 1257 config CC_OPTIMIZE_FOR_PERFORMANCE_O3 1242 1258 bool "Optimize more for performance (-O3)" 1243 1259 depends on ARC 1244 - imply CC_DISABLE_WARN_MAYBE_UNINITIALIZED # avoid false positives 1245 1260 help 1246 1261 Choosing this option will pass "-O3" to your compiler to optimize 1247 1262 the kernel yet more for performance. 1248 1263 1249 1264 config CC_OPTIMIZE_FOR_SIZE 1250 1265 bool "Optimize for size (-Os)" 1251 - imply CC_DISABLE_WARN_MAYBE_UNINITIALIZED # avoid false positives 1252 1266 help 1253 1267 Choosing this option will pass "-Os" to your compiler resulting 1254 1268 in a smaller kernel.
-1
kernel/trace/Kconfig
··· 466 466 config PROFILE_ALL_BRANCHES 467 467 bool "Profile all if conditionals" if !FORTIFY_SOURCE 468 468 select TRACE_BRANCH_PROFILING 469 - imply CC_DISABLE_WARN_MAYBE_UNINITIALIZED # avoid false positives 470 469 help 471 470 This tracer profiles all branch conditions. Every if () 472 471 taken in the kernel is recorded whether it hit or miss.