1b2441318SGreg Kroah-Hartman# SPDX-License-Identifier: GPL-2.0 2a86fe353SMasahiro Yamada# ========================================================================== 3a86fe353SMasahiro Yamada# make W=... settings 4a86fe353SMasahiro Yamada# 5c77d06e7SYann Droneaud# There are four warning groups enabled by W=1, W=2, W=3, and W=e 6c77d06e7SYann Droneaud# They are independent, and can be combined like W=12 or W=123e. 7a86fe353SMasahiro Yamada# ========================================================================== 8a86fe353SMasahiro Yamada 9321cb030SXiongfeng WangKBUILD_CFLAGS += $(call cc-disable-warning, packed-not-aligned) 10321cb030SXiongfeng Wang 11e27128dbSMasahiro Yamada# backward compatibility 12e27128dbSMasahiro YamadaKBUILD_EXTRA_WARN ?= $(KBUILD_ENABLE_EXTRA_GCC_CHECKS) 13e27128dbSMasahiro Yamada 14a86fe353SMasahiro Yamadaifeq ("$(origin W)", "command line") 15e27128dbSMasahiro Yamada KBUILD_EXTRA_WARN := $(W) 16a86fe353SMasahiro Yamadaendif 17a86fe353SMasahiro Yamada 18e27128dbSMasahiro Yamadaexport KBUILD_EXTRA_WARN 19e27128dbSMasahiro Yamada 2064a91907SMasahiro Yamada# 2164a91907SMasahiro Yamada# W=1 - warnings which may be relevant and do not occur too often 2264a91907SMasahiro Yamada# 23e27128dbSMasahiro Yamadaifneq ($(findstring 1, $(KBUILD_EXTRA_WARN)),) 24a86fe353SMasahiro Yamada 2564a91907SMasahiro YamadaKBUILD_CFLAGS += -Wextra -Wunused -Wno-unused-parameter 2664a91907SMasahiro YamadaKBUILD_CFLAGS += -Wmissing-declarations 2764a91907SMasahiro YamadaKBUILD_CFLAGS += -Wmissing-format-attribute 2864a91907SMasahiro YamadaKBUILD_CFLAGS += -Wmissing-prototypes 2964a91907SMasahiro YamadaKBUILD_CFLAGS += -Wold-style-definition 3064a91907SMasahiro YamadaKBUILD_CFLAGS += -Wmissing-include-dirs 3164a91907SMasahiro YamadaKBUILD_CFLAGS += $(call cc-option, -Wunused-but-set-variable) 3264a91907SMasahiro YamadaKBUILD_CFLAGS += $(call cc-option, -Wunused-const-variable) 3364a91907SMasahiro YamadaKBUILD_CFLAGS += $(call cc-option, -Wpacked-not-aligned) 3464a91907SMasahiro YamadaKBUILD_CFLAGS += $(call cc-option, -Wstringop-truncation) 354c8dd95aSMasahiro Yamada# The following turn off the warnings enabled by -Wextra 3664a91907SMasahiro YamadaKBUILD_CFLAGS += -Wno-missing-field-initializers 3764a91907SMasahiro YamadaKBUILD_CFLAGS += -Wno-sign-compare 38355a3587SRikard FalkebornKBUILD_CFLAGS += -Wno-type-limits 391344794aSArnd BergmannKBUILD_CFLAGS += -Wno-shift-negative-value 40a86fe353SMasahiro Yamada 416863f564SMasahiro YamadaKBUILD_CPPFLAGS += -DKBUILD_EXTRA_WARN1 426863f564SMasahiro Yamada 4326ea6bb1SBehan Websterelse 4426ea6bb1SBehan Webster 4564a91907SMasahiro Yamada# Some diagnostics enabled by default are noisy. 4664a91907SMasahiro Yamada# Suppress them by using -Wno... except for W=1. 4764a91907SMasahiro Yamada 48076f421dSMasahiro Yamadaifdef CONFIG_CC_IS_CLANG 49a1494304SMasahiro YamadaKBUILD_CFLAGS += -Wno-initializer-overrides 50b0839b28SNick Desaulniers# Clang before clang-16 would warn on default argument promotions. 51*88b61e3bSNick Desaulniersifneq ($(call clang-min-version, 160000),y) 52b0839b28SNick Desaulniers# Disable -Wformat 5321f9c8a1SLinus TorvaldsKBUILD_CFLAGS += -Wno-format 54b0839b28SNick Desaulniers# Then re-enable flags that were part of the -Wformat group that aren't 55b0839b28SNick Desaulniers# problematic. 56b0839b28SNick DesaulniersKBUILD_CFLAGS += -Wformat-extra-args -Wformat-invalid-specifier 57b0839b28SNick DesaulniersKBUILD_CFLAGS += -Wformat-zero-length -Wnonnull 58b0839b28SNick Desaulniers# Requires clang-12+. 59*88b61e3bSNick Desaulniersifeq ($(call clang-min-version, 120000),y) 60b0839b28SNick DesaulniersKBUILD_CFLAGS += -Wformat-insufficient-args 61b0839b28SNick Desaulniersendif 62b0839b28SNick Desaulniersendif 63a1494304SMasahiro YamadaKBUILD_CFLAGS += -Wno-sign-compare 6482f2bc2fSNathan ChancellorKBUILD_CFLAGS += $(call cc-disable-warning, pointer-to-enum-cast) 65afe956c5SNathan ChancellorKBUILD_CFLAGS += -Wno-tautological-constant-out-of-range-compare 661cf5f151SNathan ChancellorKBUILD_CFLAGS += $(call cc-disable-warning, unaligned-access) 6726ea6bb1SBehan Websterendif 6864a91907SMasahiro Yamada 6964a91907SMasahiro Yamadaendif 7064a91907SMasahiro Yamada 7164a91907SMasahiro Yamada# 7264a91907SMasahiro Yamada# W=2 - warnings which occur quite often but may still be relevant 7364a91907SMasahiro Yamada# 74e27128dbSMasahiro Yamadaifneq ($(findstring 2, $(KBUILD_EXTRA_WARN)),) 7564a91907SMasahiro Yamada 7664a91907SMasahiro YamadaKBUILD_CFLAGS += -Wdisabled-optimization 7764a91907SMasahiro YamadaKBUILD_CFLAGS += -Wshadow 7864a91907SMasahiro YamadaKBUILD_CFLAGS += $(call cc-option, -Wlogical-op) 7964a91907SMasahiro YamadaKBUILD_CFLAGS += -Wmissing-field-initializers 80355a3587SRikard FalkebornKBUILD_CFLAGS += -Wtype-limits 8164a91907SMasahiro YamadaKBUILD_CFLAGS += $(call cc-option, -Wmaybe-uninitialized) 8264a91907SMasahiro YamadaKBUILD_CFLAGS += $(call cc-option, -Wunused-macros) 8364a91907SMasahiro Yamada 846863f564SMasahiro YamadaKBUILD_CPPFLAGS += -DKBUILD_EXTRA_WARN2 856863f564SMasahiro Yamada 8664a91907SMasahiro Yamadaendif 8764a91907SMasahiro Yamada 8864a91907SMasahiro Yamada# 8964a91907SMasahiro Yamada# W=3 - more obscure warnings, can most likely be ignored 9064a91907SMasahiro Yamada# 91e27128dbSMasahiro Yamadaifneq ($(findstring 3, $(KBUILD_EXTRA_WARN)),) 9264a91907SMasahiro Yamada 9364a91907SMasahiro YamadaKBUILD_CFLAGS += -Wbad-function-cast 94095fbca0SArnd BergmannKBUILD_CFLAGS += -Wcast-align 9564a91907SMasahiro YamadaKBUILD_CFLAGS += -Wcast-qual 9664a91907SMasahiro YamadaKBUILD_CFLAGS += -Wconversion 9764a91907SMasahiro YamadaKBUILD_CFLAGS += -Wpacked 9864a91907SMasahiro YamadaKBUILD_CFLAGS += -Wpadded 9964a91907SMasahiro YamadaKBUILD_CFLAGS += -Wpointer-arith 10064a91907SMasahiro YamadaKBUILD_CFLAGS += -Wredundant-decls 101a97ea93eSJoe PerchesKBUILD_CFLAGS += -Wsign-compare 10264a91907SMasahiro YamadaKBUILD_CFLAGS += -Wswitch-default 10364a91907SMasahiro YamadaKBUILD_CFLAGS += $(call cc-option, -Wpacked-bitfield-compat) 10464a91907SMasahiro Yamada 1056863f564SMasahiro YamadaKBUILD_CPPFLAGS += -DKBUILD_EXTRA_WARN3 1066863f564SMasahiro Yamada 107a86fe353SMasahiro Yamadaendif 108c77d06e7SYann Droneaud 109c77d06e7SYann Droneaud# 110c77d06e7SYann Droneaud# W=e - error out on warnings 111c77d06e7SYann Droneaud# 112c77d06e7SYann Droneaudifneq ($(findstring e, $(KBUILD_EXTRA_WARN)),) 113c77d06e7SYann Droneaud 114c77d06e7SYann DroneaudKBUILD_CFLAGS += -Werror 115c77d06e7SYann Droneaud 116c77d06e7SYann Droneaudendif 117