117 lines · 3.5 KB · Text
RawDownload
# SPDX-License-Identifier: GPL-2.0# ==========================================================================# make W=... settings## There are four warning groups enabled by W=1, W=2, W=3, and W=e# They are independent, and can be combined like W=12 or W=123e.# ========================================================================== KBUILD_CFLAGS += $(call cc-disable-warning, packed-not-aligned) # backward compatibilityKBUILD_EXTRA_WARN ?= $(KBUILD_ENABLE_EXTRA_GCC_CHECKS) ifeq ("$(origin W)", "command line")  KBUILD_EXTRA_WARN := $(W)endif export KBUILD_EXTRA_WARN ## W=1 - warnings which may be relevant and do not occur too often#ifneq ($(findstring 1, $(KBUILD_EXTRA_WARN)),) KBUILD_CFLAGS += -Wextra -Wunused -Wno-unused-parameterKBUILD_CFLAGS += -Wmissing-declarationsKBUILD_CFLAGS += -Wmissing-format-attributeKBUILD_CFLAGS += -Wmissing-prototypesKBUILD_CFLAGS += -Wold-style-definitionKBUILD_CFLAGS += -Wmissing-include-dirsKBUILD_CFLAGS += $(call cc-option, -Wunused-but-set-variable)KBUILD_CFLAGS += $(call cc-option, -Wunused-const-variable)KBUILD_CFLAGS += $(call cc-option, -Wpacked-not-aligned)KBUILD_CFLAGS += $(call cc-option, -Wstringop-truncation)# The following turn off the warnings enabled by -WextraKBUILD_CFLAGS += -Wno-missing-field-initializersKBUILD_CFLAGS += -Wno-sign-compareKBUILD_CFLAGS += -Wno-type-limitsKBUILD_CFLAGS += -Wno-shift-negative-value KBUILD_CPPFLAGS += -DKBUILD_EXTRA_WARN1 else # Some diagnostics enabled by default are noisy.# Suppress them by using -Wno... except for W=1. ifdef CONFIG_CC_IS_CLANGKBUILD_CFLAGS += -Wno-initializer-overrides# Clang before clang-16 would warn on default argument promotions.ifneq ($(call clang-min-version, 160000),y)# Disable -WformatKBUILD_CFLAGS += -Wno-format# Then re-enable flags that were part of the -Wformat group that aren't# problematic.KBUILD_CFLAGS += -Wformat-extra-args -Wformat-invalid-specifierKBUILD_CFLAGS += -Wformat-zero-length -Wnonnull# Requires clang-12+.ifeq ($(call clang-min-version, 120000),y)KBUILD_CFLAGS += -Wformat-insufficient-argsendifendifKBUILD_CFLAGS += -Wno-sign-compareKBUILD_CFLAGS += $(call cc-disable-warning, pointer-to-enum-cast)KBUILD_CFLAGS += -Wno-tautological-constant-out-of-range-compareKBUILD_CFLAGS += $(call cc-disable-warning, unaligned-access)KBUILD_CFLAGS += $(call cc-disable-warning, cast-function-type-strict)endif endif ## W=2 - warnings which occur quite often but may still be relevant#ifneq ($(findstring 2, $(KBUILD_EXTRA_WARN)),) KBUILD_CFLAGS += -Wdisabled-optimizationKBUILD_CFLAGS += -WshadowKBUILD_CFLAGS += $(call cc-option, -Wlogical-op)KBUILD_CFLAGS += -Wmissing-field-initializersKBUILD_CFLAGS += -Wtype-limitsKBUILD_CFLAGS += $(call cc-option, -Wmaybe-uninitialized)KBUILD_CFLAGS += $(call cc-option, -Wunused-macros) KBUILD_CPPFLAGS += -DKBUILD_EXTRA_WARN2 endif ## W=3 - more obscure warnings, can most likely be ignored#ifneq ($(findstring 3, $(KBUILD_EXTRA_WARN)),) KBUILD_CFLAGS += -Wbad-function-castKBUILD_CFLAGS += -Wcast-alignKBUILD_CFLAGS += -Wcast-qualKBUILD_CFLAGS += -WconversionKBUILD_CFLAGS += -WpackedKBUILD_CFLAGS += -WpaddedKBUILD_CFLAGS += -Wpointer-arithKBUILD_CFLAGS += -Wredundant-declsKBUILD_CFLAGS += -Wsign-compareKBUILD_CFLAGS += -Wswitch-defaultKBUILD_CFLAGS += $(call cc-option, -Wpacked-bitfield-compat) KBUILD_CPPFLAGS += -DKBUILD_EXTRA_WARN3 endif ## W=e - error out on warnings#ifneq ($(findstring e, $(KBUILD_EXTRA_WARN)),) KBUILD_CFLAGS += -Werror endif