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