Back to home page

OSCL-LXR

 
 

    


0001 # SPDX-License-Identifier: GPL-2.0
0002 # ==========================================================================
0003 # make W=... settings
0004 #
0005 # There are four warning groups enabled by W=1, W=2, W=3, and W=e
0006 # They are independent, and can be combined like W=12 or W=123e.
0007 # ==========================================================================
0008 
0009 KBUILD_CFLAGS += $(call cc-disable-warning, packed-not-aligned)
0010 
0011 # backward compatibility
0012 KBUILD_EXTRA_WARN ?= $(KBUILD_ENABLE_EXTRA_GCC_CHECKS)
0013 
0014 ifeq ("$(origin W)", "command line")
0015   KBUILD_EXTRA_WARN := $(W)
0016 endif
0017 
0018 export KBUILD_EXTRA_WARN
0019 
0020 #
0021 # W=1 - warnings which may be relevant and do not occur too often
0022 #
0023 ifneq ($(findstring 1, $(KBUILD_EXTRA_WARN)),)
0024 
0025 KBUILD_CFLAGS += -Wextra -Wunused -Wno-unused-parameter
0026 KBUILD_CFLAGS += -Wmissing-declarations
0027 KBUILD_CFLAGS += -Wmissing-format-attribute
0028 KBUILD_CFLAGS += -Wmissing-prototypes
0029 KBUILD_CFLAGS += -Wold-style-definition
0030 KBUILD_CFLAGS += -Wmissing-include-dirs
0031 KBUILD_CFLAGS += $(call cc-option, -Wunused-but-set-variable)
0032 KBUILD_CFLAGS += $(call cc-option, -Wunused-const-variable)
0033 KBUILD_CFLAGS += $(call cc-option, -Wpacked-not-aligned)
0034 KBUILD_CFLAGS += $(call cc-option, -Wstringop-truncation)
0035 # The following turn off the warnings enabled by -Wextra
0036 KBUILD_CFLAGS += -Wno-missing-field-initializers
0037 KBUILD_CFLAGS += -Wno-sign-compare
0038 KBUILD_CFLAGS += -Wno-type-limits
0039 KBUILD_CFLAGS += -Wno-shift-negative-value
0040 
0041 KBUILD_CPPFLAGS += -DKBUILD_EXTRA_WARN1
0042 
0043 else
0044 
0045 # Some diagnostics enabled by default are noisy.
0046 # Suppress them by using -Wno... except for W=1.
0047 
0048 ifdef CONFIG_CC_IS_CLANG
0049 KBUILD_CFLAGS += -Wno-initializer-overrides
0050 # Clang before clang-16 would warn on default argument promotions.
0051 ifeq ($(shell [ $(CONFIG_CLANG_VERSION) -lt 160000 ] && echo y),y)
0052 # Disable -Wformat
0053 KBUILD_CFLAGS += -Wno-format
0054 # Then re-enable flags that were part of the -Wformat group that aren't
0055 # problematic.
0056 KBUILD_CFLAGS += -Wformat-extra-args -Wformat-invalid-specifier
0057 KBUILD_CFLAGS += -Wformat-zero-length -Wnonnull
0058 # Requires clang-12+.
0059 ifeq ($(shell [ $(CONFIG_CLANG_VERSION) -ge 120000 ] && echo y),y)
0060 KBUILD_CFLAGS += -Wformat-insufficient-args
0061 endif
0062 endif
0063 KBUILD_CFLAGS += -Wno-sign-compare
0064 KBUILD_CFLAGS += $(call cc-disable-warning, pointer-to-enum-cast)
0065 KBUILD_CFLAGS += -Wno-tautological-constant-out-of-range-compare
0066 KBUILD_CFLAGS += $(call cc-disable-warning, unaligned-access)
0067 KBUILD_CFLAGS += $(call cc-disable-warning, cast-function-type-strict)
0068 endif
0069 
0070 endif
0071 
0072 #
0073 # W=2 - warnings which occur quite often but may still be relevant
0074 #
0075 ifneq ($(findstring 2, $(KBUILD_EXTRA_WARN)),)
0076 
0077 KBUILD_CFLAGS += -Wdisabled-optimization
0078 KBUILD_CFLAGS += -Wshadow
0079 KBUILD_CFLAGS += $(call cc-option, -Wlogical-op)
0080 KBUILD_CFLAGS += -Wmissing-field-initializers
0081 KBUILD_CFLAGS += -Wtype-limits
0082 KBUILD_CFLAGS += $(call cc-option, -Wmaybe-uninitialized)
0083 KBUILD_CFLAGS += $(call cc-option, -Wunused-macros)
0084 
0085 KBUILD_CPPFLAGS += -DKBUILD_EXTRA_WARN2
0086 
0087 endif
0088 
0089 #
0090 # W=3 - more obscure warnings, can most likely be ignored
0091 #
0092 ifneq ($(findstring 3, $(KBUILD_EXTRA_WARN)),)
0093 
0094 KBUILD_CFLAGS += -Wbad-function-cast
0095 KBUILD_CFLAGS += -Wcast-align
0096 KBUILD_CFLAGS += -Wcast-qual
0097 KBUILD_CFLAGS += -Wconversion
0098 KBUILD_CFLAGS += -Wpacked
0099 KBUILD_CFLAGS += -Wpadded
0100 KBUILD_CFLAGS += -Wpointer-arith
0101 KBUILD_CFLAGS += -Wredundant-decls
0102 KBUILD_CFLAGS += -Wsign-compare
0103 KBUILD_CFLAGS += -Wswitch-default
0104 KBUILD_CFLAGS += $(call cc-option, -Wpacked-bitfield-compat)
0105 
0106 KBUILD_CPPFLAGS += -DKBUILD_EXTRA_WARN3
0107 
0108 endif
0109 
0110 #
0111 # W=e - error out on warnings
0112 #
0113 ifneq ($(findstring e, $(KBUILD_EXTRA_WARN)),)
0114 
0115 KBUILD_CFLAGS += -Werror
0116 
0117 endif