1# SPDX-License-Identifier: GPL-2.0 2# ========================================================================== 3# make W=... settings 4# 5# There are three warning groups enabled by W=1, W=2, W=3. 6# They are independent, and can be combined like W=12 or W=123. 7# ========================================================================== 8 9KBUILD_CFLAGS += $(call cc-disable-warning, packed-not-aligned) 10 11ifeq ("$(origin W)", "command line") 12 export KBUILD_ENABLE_EXTRA_GCC_CHECKS := $(W) 13endif 14 15# 16# W=1 - warnings which may be relevant and do not occur too often 17# 18ifneq ($(findstring 1, $(KBUILD_ENABLE_EXTRA_GCC_CHECKS)),) 19 20KBUILD_CFLAGS += -Wextra -Wunused -Wno-unused-parameter 21KBUILD_CFLAGS += -Wmissing-declarations 22KBUILD_CFLAGS += -Wmissing-format-attribute 23KBUILD_CFLAGS += -Wmissing-prototypes 24KBUILD_CFLAGS += -Wold-style-definition 25KBUILD_CFLAGS += -Wmissing-include-dirs 26KBUILD_CFLAGS += $(call cc-option, -Wunused-but-set-variable) 27KBUILD_CFLAGS += $(call cc-option, -Wunused-const-variable) 28KBUILD_CFLAGS += $(call cc-option, -Wpacked-not-aligned) 29KBUILD_CFLAGS += $(call cc-option, -Wstringop-truncation) 30# The following turn off the warnings enabled by -Wextra 31KBUILD_CFLAGS += -Wno-missing-field-initializers 32KBUILD_CFLAGS += -Wno-sign-compare 33 34else 35 36# Some diagnostics enabled by default are noisy. 37# Suppress them by using -Wno... except for W=1. 38 39ifdef CONFIG_CC_IS_CLANG 40KBUILD_CFLAGS += -Wno-initializer-overrides 41KBUILD_CFLAGS += -Wno-format 42KBUILD_CFLAGS += -Wno-sign-compare 43KBUILD_CFLAGS += -Wno-format-zero-length 44endif 45 46endif 47 48# 49# W=2 - warnings which occur quite often but may still be relevant 50# 51ifneq ($(findstring 2, $(KBUILD_ENABLE_EXTRA_GCC_CHECKS)),) 52 53KBUILD_CFLAGS += -Wcast-align 54KBUILD_CFLAGS += -Wdisabled-optimization 55KBUILD_CFLAGS += -Wnested-externs 56KBUILD_CFLAGS += -Wshadow 57KBUILD_CFLAGS += $(call cc-option, -Wlogical-op) 58KBUILD_CFLAGS += -Wmissing-field-initializers 59KBUILD_CFLAGS += -Wsign-compare 60KBUILD_CFLAGS += $(call cc-option, -Wmaybe-uninitialized) 61KBUILD_CFLAGS += $(call cc-option, -Wunused-macros) 62 63endif 64 65# 66# W=3 - more obscure warnings, can most likely be ignored 67# 68ifneq ($(findstring 3, $(KBUILD_ENABLE_EXTRA_GCC_CHECKS)),) 69 70KBUILD_CFLAGS += -Wbad-function-cast 71KBUILD_CFLAGS += -Wcast-qual 72KBUILD_CFLAGS += -Wconversion 73KBUILD_CFLAGS += -Wpacked 74KBUILD_CFLAGS += -Wpadded 75KBUILD_CFLAGS += -Wpointer-arith 76KBUILD_CFLAGS += -Wredundant-decls 77KBUILD_CFLAGS += -Wswitch-default 78KBUILD_CFLAGS += $(call cc-option, -Wpacked-bitfield-compat) 79 80endif 81