Linux Audio

Check our new training course

Loading...
v6.2
  1# SPDX-License-Identifier: GPL-2.0
  2# ==========================================================================
  3# make W=... settings
  4#
  5# There are four warning groups enabled by W=1, W=2, W=3, and W=e
  6# They are independent, and can be combined like W=12 or W=123e.
  7# ==========================================================================
  8
  9KBUILD_CFLAGS += $(call cc-disable-warning, packed-not-aligned)
 
 
 
 
 
 
 
 
 
 
 
 
 10
 11# backward compatibility
 12KBUILD_EXTRA_WARN ?= $(KBUILD_ENABLE_EXTRA_GCC_CHECKS)
 
 
 
 
 
 13
 14ifeq ("$(origin W)", "command line")
 15  KBUILD_EXTRA_WARN := $(W)
 
 
 
 
 
 
 
 
 
 
 16endif
 17
 18export KBUILD_EXTRA_WARN
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 19
 20#
 21# W=1 - warnings which may be relevant and do not occur too often
 22#
 23ifneq ($(findstring 1, $(KBUILD_EXTRA_WARN)),)
 24
 25KBUILD_CFLAGS += -Wextra -Wunused -Wno-unused-parameter
 26KBUILD_CFLAGS += -Wmissing-declarations
 27KBUILD_CFLAGS += -Wmissing-format-attribute
 28KBUILD_CFLAGS += -Wmissing-prototypes
 29KBUILD_CFLAGS += -Wold-style-definition
 30KBUILD_CFLAGS += -Wmissing-include-dirs
 31KBUILD_CFLAGS += $(call cc-option, -Wunused-but-set-variable)
 32KBUILD_CFLAGS += $(call cc-option, -Wunused-const-variable)
 33KBUILD_CFLAGS += $(call cc-option, -Wpacked-not-aligned)
 34KBUILD_CFLAGS += $(call cc-option, -Wstringop-truncation)
 35# The following turn off the warnings enabled by -Wextra
 36KBUILD_CFLAGS += -Wno-missing-field-initializers
 37KBUILD_CFLAGS += -Wno-sign-compare
 38KBUILD_CFLAGS += -Wno-type-limits
 39KBUILD_CFLAGS += -Wno-shift-negative-value
 40
 41KBUILD_CPPFLAGS += -Wundef
 42KBUILD_CPPFLAGS += -DKBUILD_EXTRA_WARN1
 43
 44else
 45
 46# Some diagnostics enabled by default are noisy.
 47# Suppress them by using -Wno... except for W=1.
 
 
 
 
 
 
 
 
 
 
 48
 49ifdef CONFIG_CC_IS_CLANG
 50KBUILD_CFLAGS += -Wno-initializer-overrides
 51# Clang before clang-16 would warn on default argument promotions.
 52ifneq ($(call clang-min-version, 160000),y)
 53# Disable -Wformat
 54KBUILD_CFLAGS += -Wno-format
 55# Then re-enable flags that were part of the -Wformat group that aren't
 56# problematic.
 57KBUILD_CFLAGS += -Wformat-extra-args -Wformat-invalid-specifier
 58KBUILD_CFLAGS += -Wformat-zero-length -Wnonnull
 59# Requires clang-12+.
 60ifeq ($(call clang-min-version, 120000),y)
 61KBUILD_CFLAGS += -Wformat-insufficient-args
 62endif
 63endif
 64KBUILD_CFLAGS += -Wno-sign-compare
 65KBUILD_CFLAGS += $(call cc-disable-warning, pointer-to-enum-cast)
 66KBUILD_CFLAGS += -Wno-tautological-constant-out-of-range-compare
 67KBUILD_CFLAGS += $(call cc-disable-warning, unaligned-access)
 68KBUILD_CFLAGS += $(call cc-disable-warning, cast-function-type-strict)
 69endif
 70
 71endif
 72
 73#
 74# W=2 - warnings which occur quite often but may still be relevant
 75#
 76ifneq ($(findstring 2, $(KBUILD_EXTRA_WARN)),)
 77
 78KBUILD_CFLAGS += -Wdisabled-optimization
 79KBUILD_CFLAGS += -Wshadow
 80KBUILD_CFLAGS += $(call cc-option, -Wlogical-op)
 81KBUILD_CFLAGS += -Wmissing-field-initializers
 82KBUILD_CFLAGS += -Wtype-limits
 83KBUILD_CFLAGS += $(call cc-option, -Wmaybe-uninitialized)
 84KBUILD_CFLAGS += $(call cc-option, -Wunused-macros)
 85
 86KBUILD_CPPFLAGS += -DKBUILD_EXTRA_WARN2
 87
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 88endif
 89
 90#
 91# W=3 - more obscure warnings, can most likely be ignored
 92#
 93ifneq ($(findstring 3, $(KBUILD_EXTRA_WARN)),)
 94
 95KBUILD_CFLAGS += -Wbad-function-cast
 96KBUILD_CFLAGS += -Wcast-align
 97KBUILD_CFLAGS += -Wcast-qual
 98KBUILD_CFLAGS += -Wconversion
 99KBUILD_CFLAGS += -Wpacked
100KBUILD_CFLAGS += -Wpadded
101KBUILD_CFLAGS += -Wpointer-arith
102KBUILD_CFLAGS += -Wredundant-decls
103KBUILD_CFLAGS += -Wsign-compare
104KBUILD_CFLAGS += -Wswitch-default
105KBUILD_CFLAGS += $(call cc-option, -Wpacked-bitfield-compat)
106
107KBUILD_CPPFLAGS += -DKBUILD_EXTRA_WARN3
 
 
 
 
 
 
108
109endif
110
111#
112# W=e - error out on warnings
113#
114ifneq ($(findstring e, $(KBUILD_EXTRA_WARN)),)
115
116KBUILD_CFLAGS += -Werror
117
118endif
v6.13.7
  1# SPDX-License-Identifier: GPL-2.0
  2# ==========================================================================
  3# make W=... settings
  4#
  5# There are four warning groups enabled by W=1, W=2, W=3, and W=e
  6# They are independent, and can be combined like W=12 or W=123e.
  7# ==========================================================================
  8
  9# Default set of warnings, always enabled
 10KBUILD_CFLAGS += -Wall
 11KBUILD_CFLAGS += -Wundef
 12KBUILD_CFLAGS += -Werror=implicit-function-declaration
 13KBUILD_CFLAGS += -Werror=implicit-int
 14KBUILD_CFLAGS += -Werror=return-type
 15KBUILD_CFLAGS += -Werror=strict-prototypes
 16KBUILD_CFLAGS += -Wno-format-security
 17KBUILD_CFLAGS += -Wno-trigraphs
 18KBUILD_CFLAGS += $(call cc-disable-warning,frame-address,)
 19KBUILD_CFLAGS += $(call cc-disable-warning, address-of-packed-member)
 20KBUILD_CFLAGS += -Wmissing-declarations
 21KBUILD_CFLAGS += -Wmissing-prototypes
 22
 23ifneq ($(CONFIG_FRAME_WARN),0)
 24KBUILD_CFLAGS += -Wframe-larger-than=$(CONFIG_FRAME_WARN)
 25endif
 26
 27KBUILD_CPPFLAGS-$(CONFIG_WERROR) += -Werror
 28KBUILD_CPPFLAGS += $(KBUILD_CPPFLAGS-y)
 29KBUILD_CFLAGS-$(CONFIG_CC_NO_ARRAY_BOUNDS) += -Wno-array-bounds
 30
 31ifdef CONFIG_CC_IS_CLANG
 32# The kernel builds with '-std=gnu11' so use of GNU extensions is acceptable.
 33KBUILD_CFLAGS += -Wno-gnu
 34
 35# Clang checks for overflow/truncation with '%p', while GCC does not:
 36# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111219
 37KBUILD_CFLAGS += $(call cc-disable-warning, format-overflow-non-kprintf)
 38KBUILD_CFLAGS += $(call cc-disable-warning, format-truncation-non-kprintf)
 39else
 40
 41# gcc inanely warns about local variables called 'main'
 42KBUILD_CFLAGS += -Wno-main
 43endif
 44
 45# These result in bogus false positives
 46KBUILD_CFLAGS += $(call cc-disable-warning, dangling-pointer)
 47
 48# Variable Length Arrays (VLAs) should not be used anywhere in the kernel
 49KBUILD_CFLAGS += -Wvla
 50
 51# disable pointer signed / unsigned warnings in gcc 4.0
 52KBUILD_CFLAGS += -Wno-pointer-sign
 53
 54# In order to make sure new function cast mismatches are not introduced
 55# in the kernel (to avoid tripping CFI checking), the kernel should be
 56# globally built with -Wcast-function-type.
 57KBUILD_CFLAGS += $(call cc-option, -Wcast-function-type)
 58
 59# The allocators already balk at large sizes, so silence the compiler
 60# warnings for bounds checks involving those possible values. While
 61# -Wno-alloc-size-larger-than would normally be used here, earlier versions
 62# of gcc (<9.1) weirdly don't handle the option correctly when _other_
 63# warnings are produced (?!). Using -Walloc-size-larger-than=SIZE_MAX
 64# doesn't work (as it is documented to), silently resolving to "0" prior to
 65# version 9.1 (and producing an error more recently). Numeric values larger
 66# than PTRDIFF_MAX also don't work prior to version 9.1, which are silently
 67# ignored, continuing to default to PTRDIFF_MAX. So, left with no other
 68# choice, we must perform a versioned check to disable this warning.
 69# https://lore.kernel.org/lkml/20210824115859.187f272f@canb.auug.org.au
 70KBUILD_CFLAGS-$(call gcc-min-version, 90100) += -Wno-alloc-size-larger-than
 71KBUILD_CFLAGS += $(KBUILD_CFLAGS-y) $(CONFIG_CC_IMPLICIT_FALLTHROUGH)
 72
 73# Prohibit date/time macros, which would make the build non-deterministic
 74KBUILD_CFLAGS += -Werror=date-time
 75
 76# enforce correct pointer usage
 77KBUILD_CFLAGS += $(call cc-option,-Werror=incompatible-pointer-types)
 78
 79# Require designated initializers for all marked structures
 80KBUILD_CFLAGS += $(call cc-option,-Werror=designated-init)
 81
 82# Warn if there is an enum types mismatch
 83KBUILD_CFLAGS += $(call cc-option,-Wenum-conversion)
 84
 85# Explicitly clear padding bits during variable initialization
 86KBUILD_CFLAGS += $(call cc-option,-fzero-init-padding-bits=all)
 87
 88KBUILD_CFLAGS += -Wextra
 89KBUILD_CFLAGS += -Wunused
 90
 91#
 92# W=1 - warnings which may be relevant and do not occur too often
 93#
 94ifneq ($(findstring 1, $(KBUILD_EXTRA_WARN)),)
 95
 
 
 96KBUILD_CFLAGS += -Wmissing-format-attribute
 
 
 97KBUILD_CFLAGS += -Wmissing-include-dirs
 
 98KBUILD_CFLAGS += $(call cc-option, -Wunused-const-variable)
 
 
 
 
 
 
 
 99
100KBUILD_CPPFLAGS += -Wundef
101KBUILD_CPPFLAGS += -DKBUILD_EXTRA_WARN1
102
103else
104
105# Some diagnostics enabled by default are noisy.
106# Suppress them by using -Wno... except for W=1.
107KBUILD_CFLAGS += $(call cc-disable-warning, unused-but-set-variable)
108KBUILD_CFLAGS += $(call cc-disable-warning, unused-const-variable)
109KBUILD_CFLAGS += $(call cc-disable-warning, packed-not-aligned)
110KBUILD_CFLAGS += $(call cc-disable-warning, format-overflow)
111ifdef CONFIG_CC_IS_GCC
112KBUILD_CFLAGS += $(call cc-disable-warning, format-truncation)
113endif
114KBUILD_CFLAGS += $(call cc-disable-warning, stringop-truncation)
115
116KBUILD_CFLAGS += -Wno-override-init # alias for -Wno-initializer-overrides in clang
117
118ifdef CONFIG_CC_IS_CLANG
 
119# Clang before clang-16 would warn on default argument promotions.
120ifneq ($(call clang-min-version, 160000),y)
121# Disable -Wformat
122KBUILD_CFLAGS += -Wno-format
123# Then re-enable flags that were part of the -Wformat group that aren't
124# problematic.
125KBUILD_CFLAGS += -Wformat-extra-args -Wformat-invalid-specifier
126KBUILD_CFLAGS += -Wformat-zero-length -Wnonnull
127# Requires clang-12+.
128ifeq ($(call clang-min-version, 120000),y)
129KBUILD_CFLAGS += -Wformat-insufficient-args
130endif
131endif
 
132KBUILD_CFLAGS += $(call cc-disable-warning, pointer-to-enum-cast)
133KBUILD_CFLAGS += -Wno-tautological-constant-out-of-range-compare
134KBUILD_CFLAGS += $(call cc-disable-warning, unaligned-access)
135KBUILD_CFLAGS += -Wno-enum-compare-conditional
136endif
137
138endif
139
140#
141# W=2 - warnings which occur quite often but may still be relevant
142#
143ifneq ($(findstring 2, $(KBUILD_EXTRA_WARN)),)
144
145KBUILD_CFLAGS += -Wdisabled-optimization
146KBUILD_CFLAGS += -Wshadow
147KBUILD_CFLAGS += $(call cc-option, -Wlogical-op)
 
 
 
148KBUILD_CFLAGS += $(call cc-option, -Wunused-macros)
149
150KBUILD_CPPFLAGS += -DKBUILD_EXTRA_WARN2
151
152else
153
154# The following turn off the warnings enabled by -Wextra
155KBUILD_CFLAGS += -Wno-missing-field-initializers
156KBUILD_CFLAGS += -Wno-type-limits
157KBUILD_CFLAGS += -Wno-shift-negative-value
158
159ifdef CONFIG_CC_IS_CLANG
160KBUILD_CFLAGS += -Wno-enum-enum-conversion
161endif
162
163ifdef CONFIG_CC_IS_GCC
164KBUILD_CFLAGS += -Wno-maybe-uninitialized
165endif
166
167endif
168
169#
170# W=3 - more obscure warnings, can most likely be ignored
171#
172ifneq ($(findstring 3, $(KBUILD_EXTRA_WARN)),)
173
174KBUILD_CFLAGS += -Wbad-function-cast
175KBUILD_CFLAGS += -Wcast-align
176KBUILD_CFLAGS += -Wcast-qual
177KBUILD_CFLAGS += -Wconversion
178KBUILD_CFLAGS += -Wpacked
179KBUILD_CFLAGS += -Wpadded
180KBUILD_CFLAGS += -Wpointer-arith
181KBUILD_CFLAGS += -Wredundant-decls
182KBUILD_CFLAGS += -Wsign-compare
183KBUILD_CFLAGS += -Wswitch-default
 
184
185KBUILD_CPPFLAGS += -DKBUILD_EXTRA_WARN3
186
187else
188
189# The following turn off the warnings enabled by -Wextra
190KBUILD_CFLAGS += -Wno-sign-compare
191KBUILD_CFLAGS += -Wno-unused-parameter
192
193endif
194
195#
196# W=e - error out on warnings
197#
198ifneq ($(findstring e, $(KBUILD_EXTRA_WARN)),)
199
200KBUILD_CFLAGS += -Werror
201
202endif