mirror of
				https://github.com/torvalds/linux.git
				synced 2025-11-04 02:30:34 +02:00 
			
		
		
		
	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>
This commit is contained in:
		
							parent
							
								
									1d3962ae3b
								
							
						
					
					
						commit
						78a5255ffb
					
				
					 3 changed files with 3 additions and 23 deletions
				
			
		
							
								
								
									
										7
									
								
								Makefile
									
									
									
									
									
								
							
							
						
						
									
										7
									
								
								Makefile
									
									
									
									
									
								
							| 
						 | 
					@ -729,10 +729,6 @@ else ifdef CONFIG_CC_OPTIMIZE_FOR_SIZE
 | 
				
			||||||
KBUILD_CFLAGS += -Os
 | 
					KBUILD_CFLAGS += -Os
 | 
				
			||||||
endif
 | 
					endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
ifdef CONFIG_CC_DISABLE_WARN_MAYBE_UNINITIALIZED
 | 
					 | 
				
			||||||
KBUILD_CFLAGS   += -Wno-maybe-uninitialized
 | 
					 | 
				
			||||||
endif
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
# Tell gcc to never replace conditional load with a non-conditional one
 | 
					# Tell gcc to never replace conditional load with a non-conditional one
 | 
				
			||||||
KBUILD_CFLAGS	+= $(call cc-option,--param=allow-store-data-races=0)
 | 
					KBUILD_CFLAGS	+= $(call cc-option,--param=allow-store-data-races=0)
 | 
				
			||||||
KBUILD_CFLAGS	+= $(call cc-option,-fno-allow-store-data-races)
 | 
					KBUILD_CFLAGS	+= $(call cc-option,-fno-allow-store-data-races)
 | 
				
			||||||
| 
						 | 
					@ -881,6 +877,9 @@ KBUILD_CFLAGS += -Wno-pointer-sign
 | 
				
			||||||
# disable stringop warnings in gcc 8+
 | 
					# disable stringop warnings in gcc 8+
 | 
				
			||||||
KBUILD_CFLAGS += $(call cc-disable-warning, stringop-truncation)
 | 
					KBUILD_CFLAGS += $(call cc-disable-warning, stringop-truncation)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# Enabled with W=2, disabled by default as noisy
 | 
				
			||||||
 | 
					KBUILD_CFLAGS += $(call cc-disable-warning, maybe-uninitialized)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# disable invalid "can't wrap" optimizations for signed / pointers
 | 
					# disable invalid "can't wrap" optimizations for signed / pointers
 | 
				
			||||||
KBUILD_CFLAGS	+= $(call cc-option,-fno-strict-overflow)
 | 
					KBUILD_CFLAGS	+= $(call cc-option,-fno-strict-overflow)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										18
									
								
								init/Kconfig
									
									
									
									
									
								
							
							
						
						
									
										18
									
								
								init/Kconfig
									
									
									
									
									
								
							| 
						 | 
					@ -39,22 +39,6 @@ config TOOLS_SUPPORT_RELR
 | 
				
			||||||
config CC_HAS_ASM_INLINE
 | 
					config CC_HAS_ASM_INLINE
 | 
				
			||||||
	def_bool $(success,echo 'void foo(void) { asm inline (""); }' | $(CC) -x c - -c -o /dev/null)
 | 
						def_bool $(success,echo 'void foo(void) { asm inline (""); }' | $(CC) -x c - -c -o /dev/null)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
config CC_HAS_WARN_MAYBE_UNINITIALIZED
 | 
					 | 
				
			||||||
	def_bool $(cc-option,-Wmaybe-uninitialized)
 | 
					 | 
				
			||||||
	help
 | 
					 | 
				
			||||||
	  GCC >= 4.7 supports this option.
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
config CC_DISABLE_WARN_MAYBE_UNINITIALIZED
 | 
					 | 
				
			||||||
	bool
 | 
					 | 
				
			||||||
	depends on CC_HAS_WARN_MAYBE_UNINITIALIZED
 | 
					 | 
				
			||||||
	default CC_IS_GCC && GCC_VERSION < 40900  # unreliable for GCC < 4.9
 | 
					 | 
				
			||||||
	help
 | 
					 | 
				
			||||||
	  GCC's -Wmaybe-uninitialized is not reliable by definition.
 | 
					 | 
				
			||||||
	  Lots of false positive warnings are produced in some cases.
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	  If this option is enabled, -Wno-maybe-uninitialzed is passed
 | 
					 | 
				
			||||||
	  to the compiler to suppress maybe-uninitialized warnings.
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
config CONSTRUCTORS
 | 
					config CONSTRUCTORS
 | 
				
			||||||
	bool
 | 
						bool
 | 
				
			||||||
	depends on !UML
 | 
						depends on !UML
 | 
				
			||||||
| 
						 | 
					@ -1257,14 +1241,12 @@ config CC_OPTIMIZE_FOR_PERFORMANCE
 | 
				
			||||||
config CC_OPTIMIZE_FOR_PERFORMANCE_O3
 | 
					config CC_OPTIMIZE_FOR_PERFORMANCE_O3
 | 
				
			||||||
	bool "Optimize more for performance (-O3)"
 | 
						bool "Optimize more for performance (-O3)"
 | 
				
			||||||
	depends on ARC
 | 
						depends on ARC
 | 
				
			||||||
	imply CC_DISABLE_WARN_MAYBE_UNINITIALIZED  # avoid false positives
 | 
					 | 
				
			||||||
	help
 | 
						help
 | 
				
			||||||
	  Choosing this option will pass "-O3" to your compiler to optimize
 | 
						  Choosing this option will pass "-O3" to your compiler to optimize
 | 
				
			||||||
	  the kernel yet more for performance.
 | 
						  the kernel yet more for performance.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
config CC_OPTIMIZE_FOR_SIZE
 | 
					config CC_OPTIMIZE_FOR_SIZE
 | 
				
			||||||
	bool "Optimize for size (-Os)"
 | 
						bool "Optimize for size (-Os)"
 | 
				
			||||||
	imply CC_DISABLE_WARN_MAYBE_UNINITIALIZED  # avoid false positives
 | 
					 | 
				
			||||||
	help
 | 
						help
 | 
				
			||||||
	  Choosing this option will pass "-Os" to your compiler resulting
 | 
						  Choosing this option will pass "-Os" to your compiler resulting
 | 
				
			||||||
	  in a smaller kernel.
 | 
						  in a smaller kernel.
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -466,7 +466,6 @@ config PROFILE_ANNOTATED_BRANCHES
 | 
				
			||||||
config PROFILE_ALL_BRANCHES
 | 
					config PROFILE_ALL_BRANCHES
 | 
				
			||||||
	bool "Profile all if conditionals" if !FORTIFY_SOURCE
 | 
						bool "Profile all if conditionals" if !FORTIFY_SOURCE
 | 
				
			||||||
	select TRACE_BRANCH_PROFILING
 | 
						select TRACE_BRANCH_PROFILING
 | 
				
			||||||
	imply CC_DISABLE_WARN_MAYBE_UNINITIALIZED  # avoid false positives
 | 
					 | 
				
			||||||
	help
 | 
						help
 | 
				
			||||||
	  This tracer profiles all branch conditions. Every if ()
 | 
						  This tracer profiles all branch conditions. Every if ()
 | 
				
			||||||
	  taken in the kernel is recorded whether it hit or miss.
 | 
						  taken in the kernel is recorded whether it hit or miss.
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue