]> Git Repo - linux.git/blob - scripts/Makefile.extrawarn
Linux 6.14-rc3
[linux.git] / scripts / Makefile.extrawarn
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
10 KBUILD_CFLAGS += -Wall
11 KBUILD_CFLAGS += -Wundef
12 KBUILD_CFLAGS += -Werror=implicit-function-declaration
13 KBUILD_CFLAGS += -Werror=implicit-int
14 KBUILD_CFLAGS += -Werror=return-type
15 KBUILD_CFLAGS += -Werror=strict-prototypes
16 KBUILD_CFLAGS += -Wno-format-security
17 KBUILD_CFLAGS += -Wno-trigraphs
18 KBUILD_CFLAGS += $(call cc-disable-warning,frame-address,)
19 KBUILD_CFLAGS += $(call cc-disable-warning, address-of-packed-member)
20 KBUILD_CFLAGS += -Wmissing-declarations
21 KBUILD_CFLAGS += -Wmissing-prototypes
22
23 ifneq ($(CONFIG_FRAME_WARN),0)
24 KBUILD_CFLAGS += -Wframe-larger-than=$(CONFIG_FRAME_WARN)
25 endif
26
27 KBUILD_CPPFLAGS-$(CONFIG_WERROR) += -Werror
28 KBUILD_CPPFLAGS += $(KBUILD_CPPFLAGS-y)
29 KBUILD_CFLAGS-$(CONFIG_CC_NO_ARRAY_BOUNDS) += -Wno-array-bounds
30
31 ifdef CONFIG_CC_IS_CLANG
32 # The kernel builds with '-std=gnu11' so use of GNU extensions is acceptable.
33 KBUILD_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
37 KBUILD_CFLAGS += $(call cc-disable-warning, format-overflow-non-kprintf)
38 KBUILD_CFLAGS += $(call cc-disable-warning, format-truncation-non-kprintf)
39 else
40
41 # gcc inanely warns about local variables called 'main'
42 KBUILD_CFLAGS += -Wno-main
43 endif
44
45 # These result in bogus false positives
46 KBUILD_CFLAGS += $(call cc-disable-warning, dangling-pointer)
47
48 # Variable Length Arrays (VLAs) should not be used anywhere in the kernel
49 KBUILD_CFLAGS += -Wvla
50
51 # disable pointer signed / unsigned warnings in gcc 4.0
52 KBUILD_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.
57 KBUILD_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/[email protected]
70 KBUILD_CFLAGS-$(call gcc-min-version, 90100) += -Wno-alloc-size-larger-than
71 KBUILD_CFLAGS += $(KBUILD_CFLAGS-y) $(CONFIG_CC_IMPLICIT_FALLTHROUGH)
72
73 # Prohibit date/time macros, which would make the build non-deterministic
74 KBUILD_CFLAGS += -Werror=date-time
75
76 # enforce correct pointer usage
77 KBUILD_CFLAGS += $(call cc-option,-Werror=incompatible-pointer-types)
78
79 # Require designated initializers for all marked structures
80 KBUILD_CFLAGS += $(call cc-option,-Werror=designated-init)
81
82 # Warn if there is an enum types mismatch
83 KBUILD_CFLAGS += $(call cc-option,-Wenum-conversion)
84
85 # Explicitly clear padding bits during variable initialization
86 KBUILD_CFLAGS += $(call cc-option,-fzero-init-padding-bits=all)
87
88 KBUILD_CFLAGS += -Wextra
89 KBUILD_CFLAGS += -Wunused
90
91 #
92 # W=1 - warnings which may be relevant and do not occur too often
93 #
94 ifneq ($(findstring 1, $(KBUILD_EXTRA_WARN)),)
95
96 KBUILD_CFLAGS += -Wmissing-format-attribute
97 KBUILD_CFLAGS += -Wmissing-include-dirs
98 KBUILD_CFLAGS += $(call cc-option, -Wunused-const-variable)
99
100 KBUILD_CPPFLAGS += -Wundef
101 KBUILD_CPPFLAGS += -DKBUILD_EXTRA_WARN1
102
103 else
104
105 # Some diagnostics enabled by default are noisy.
106 # Suppress them by using -Wno... except for W=1.
107 KBUILD_CFLAGS += $(call cc-disable-warning, unused-but-set-variable)
108 KBUILD_CFLAGS += $(call cc-disable-warning, unused-const-variable)
109 KBUILD_CFLAGS += $(call cc-disable-warning, packed-not-aligned)
110 KBUILD_CFLAGS += $(call cc-disable-warning, format-overflow)
111 ifdef CONFIG_CC_IS_GCC
112 KBUILD_CFLAGS += $(call cc-disable-warning, format-truncation)
113 endif
114 KBUILD_CFLAGS += $(call cc-disable-warning, stringop-truncation)
115
116 KBUILD_CFLAGS += -Wno-override-init # alias for -Wno-initializer-overrides in clang
117
118 ifdef CONFIG_CC_IS_CLANG
119 # Clang before clang-16 would warn on default argument promotions.
120 ifneq ($(call clang-min-version, 160000),y)
121 # Disable -Wformat
122 KBUILD_CFLAGS += -Wno-format
123 # Then re-enable flags that were part of the -Wformat group that aren't
124 # problematic.
125 KBUILD_CFLAGS += -Wformat-extra-args -Wformat-invalid-specifier
126 KBUILD_CFLAGS += -Wformat-zero-length -Wnonnull
127 # Requires clang-12+.
128 ifeq ($(call clang-min-version, 120000),y)
129 KBUILD_CFLAGS += -Wformat-insufficient-args
130 endif
131 endif
132 KBUILD_CFLAGS += $(call cc-disable-warning, pointer-to-enum-cast)
133 KBUILD_CFLAGS += -Wno-tautological-constant-out-of-range-compare
134 KBUILD_CFLAGS += $(call cc-disable-warning, unaligned-access)
135 KBUILD_CFLAGS += -Wno-enum-compare-conditional
136 endif
137
138 endif
139
140 #
141 # W=2 - warnings which occur quite often but may still be relevant
142 #
143 ifneq ($(findstring 2, $(KBUILD_EXTRA_WARN)),)
144
145 KBUILD_CFLAGS += -Wdisabled-optimization
146 KBUILD_CFLAGS += -Wshadow
147 KBUILD_CFLAGS += $(call cc-option, -Wlogical-op)
148 KBUILD_CFLAGS += $(call cc-option, -Wunused-macros)
149
150 KBUILD_CPPFLAGS += -DKBUILD_EXTRA_WARN2
151
152 else
153
154 # The following turn off the warnings enabled by -Wextra
155 KBUILD_CFLAGS += -Wno-missing-field-initializers
156 KBUILD_CFLAGS += -Wno-type-limits
157 KBUILD_CFLAGS += -Wno-shift-negative-value
158
159 ifdef CONFIG_CC_IS_CLANG
160 KBUILD_CFLAGS += -Wno-enum-enum-conversion
161 endif
162
163 ifdef CONFIG_CC_IS_GCC
164 KBUILD_CFLAGS += -Wno-maybe-uninitialized
165 endif
166
167 endif
168
169 #
170 # W=3 - more obscure warnings, can most likely be ignored
171 #
172 ifneq ($(findstring 3, $(KBUILD_EXTRA_WARN)),)
173
174 KBUILD_CFLAGS += -Wbad-function-cast
175 KBUILD_CFLAGS += -Wcast-align
176 KBUILD_CFLAGS += -Wcast-qual
177 KBUILD_CFLAGS += -Wconversion
178 KBUILD_CFLAGS += -Wpacked
179 KBUILD_CFLAGS += -Wpadded
180 KBUILD_CFLAGS += -Wpointer-arith
181 KBUILD_CFLAGS += -Wredundant-decls
182 KBUILD_CFLAGS += -Wsign-compare
183 KBUILD_CFLAGS += -Wswitch-default
184
185 KBUILD_CPPFLAGS += -DKBUILD_EXTRA_WARN3
186
187 else
188
189 # The following turn off the warnings enabled by -Wextra
190 KBUILD_CFLAGS += -Wno-sign-compare
191 KBUILD_CFLAGS += -Wno-unused-parameter
192
193 endif
194
195 #
196 # W=e - error out on warnings
197 #
198 ifneq ($(findstring e, $(KBUILD_EXTRA_WARN)),)
199
200 KBUILD_CFLAGS += -Werror
201
202 endif
This page took 0.040614 seconds and 4 git commands to generate.