b24413180f560 (Greg Kroah-Hartman 2017-11-01 15:07:57 +0100 1) # SPDX-License-Identifier: GPL-2.0
a86fe35373506 (Masahiro Yamada 2014-04-14 18:27:10 +0900 2) # ==========================================================================
a86fe35373506 (Masahiro Yamada 2014-04-14 18:27:10 +0900 3) # make W=... settings
a86fe35373506 (Masahiro Yamada 2014-04-14 18:27:10 +0900 4) #
64a91907c8962 (Masahiro Yamada 2019-09-01 01:25:54 +0900 5) # There are three warning groups enabled by W=1, W=2, W=3.
64a91907c8962 (Masahiro Yamada 2019-09-01 01:25:54 +0900 6) # They are independent, and can be combined like W=12 or W=123.
a86fe35373506 (Masahiro Yamada 2014-04-14 18:27:10 +0900 7) # ==========================================================================
a86fe35373506 (Masahiro Yamada 2014-04-14 18:27:10 +0900 8)
321cb0308a9e7 (Xiongfeng Wang 2018-01-11 17:22:29 +0800 9) KBUILD_CFLAGS += $(call cc-disable-warning, packed-not-aligned)
321cb0308a9e7 (Xiongfeng Wang 2018-01-11 17:22:29 +0800 10)
e27128db62834 (Masahiro Yamada 2019-09-01 01:25:55 +0900 11) # backward compatibility
e27128db62834 (Masahiro Yamada 2019-09-01 01:25:55 +0900 12) KBUILD_EXTRA_WARN ?= $(KBUILD_ENABLE_EXTRA_GCC_CHECKS)
e27128db62834 (Masahiro Yamada 2019-09-01 01:25:55 +0900 13)
a86fe35373506 (Masahiro Yamada 2014-04-14 18:27:10 +0900 14) ifeq ("$(origin W)", "command line")
e27128db62834 (Masahiro Yamada 2019-09-01 01:25:55 +0900 15) KBUILD_EXTRA_WARN := $(W)
a86fe35373506 (Masahiro Yamada 2014-04-14 18:27:10 +0900 16) endif
a86fe35373506 (Masahiro Yamada 2014-04-14 18:27:10 +0900 17)
e27128db62834 (Masahiro Yamada 2019-09-01 01:25:55 +0900 18) export KBUILD_EXTRA_WARN
e27128db62834 (Masahiro Yamada 2019-09-01 01:25:55 +0900 19)
64a91907c8962 (Masahiro Yamada 2019-09-01 01:25:54 +0900 20) #
64a91907c8962 (Masahiro Yamada 2019-09-01 01:25:54 +0900 21) # W=1 - warnings which may be relevant and do not occur too often
64a91907c8962 (Masahiro Yamada 2019-09-01 01:25:54 +0900 22) #
e27128db62834 (Masahiro Yamada 2019-09-01 01:25:55 +0900 23) ifneq ($(findstring 1, $(KBUILD_EXTRA_WARN)),)
a86fe35373506 (Masahiro Yamada 2014-04-14 18:27:10 +0900 24)
64a91907c8962 (Masahiro Yamada 2019-09-01 01:25:54 +0900 25) KBUILD_CFLAGS += -Wextra -Wunused -Wno-unused-parameter
64a91907c8962 (Masahiro Yamada 2019-09-01 01:25:54 +0900 26) KBUILD_CFLAGS += -Wmissing-declarations
64a91907c8962 (Masahiro Yamada 2019-09-01 01:25:54 +0900 27) KBUILD_CFLAGS += -Wmissing-format-attribute
64a91907c8962 (Masahiro Yamada 2019-09-01 01:25:54 +0900 28) KBUILD_CFLAGS += -Wmissing-prototypes
64a91907c8962 (Masahiro Yamada 2019-09-01 01:25:54 +0900 29) KBUILD_CFLAGS += -Wold-style-definition
64a91907c8962 (Masahiro Yamada 2019-09-01 01:25:54 +0900 30) KBUILD_CFLAGS += -Wmissing-include-dirs
64a91907c8962 (Masahiro Yamada 2019-09-01 01:25:54 +0900 31) KBUILD_CFLAGS += $(call cc-option, -Wunused-but-set-variable)
64a91907c8962 (Masahiro Yamada 2019-09-01 01:25:54 +0900 32) KBUILD_CFLAGS += $(call cc-option, -Wunused-const-variable)
64a91907c8962 (Masahiro Yamada 2019-09-01 01:25:54 +0900 33) KBUILD_CFLAGS += $(call cc-option, -Wpacked-not-aligned)
64a91907c8962 (Masahiro Yamada 2019-09-01 01:25:54 +0900 34) KBUILD_CFLAGS += $(call cc-option, -Wstringop-truncation)
4c8dd95a723d9 (Masahiro Yamada 2019-05-09 15:46:35 +0900 35) # The following turn off the warnings enabled by -Wextra
64a91907c8962 (Masahiro Yamada 2019-09-01 01:25:54 +0900 36) KBUILD_CFLAGS += -Wno-missing-field-initializers
64a91907c8962 (Masahiro Yamada 2019-09-01 01:25:54 +0900 37) KBUILD_CFLAGS += -Wno-sign-compare
355a3587d4ca0 (Rikard Falkeborn 2020-07-08 21:07:56 +0200 38) KBUILD_CFLAGS += -Wno-type-limits
a86fe35373506 (Masahiro Yamada 2014-04-14 18:27:10 +0900 39)
6863f5643dd71 (Masahiro Yamada 2019-09-07 11:52:36 +0900 40) KBUILD_CPPFLAGS += -DKBUILD_EXTRA_WARN1
6863f5643dd71 (Masahiro Yamada 2019-09-07 11:52:36 +0900 41)
26ea6bb1fef06 (Behan Webster 2014-07-31 21:08:25 -0700 42) else
26ea6bb1fef06 (Behan Webster 2014-07-31 21:08:25 -0700 43)
64a91907c8962 (Masahiro Yamada 2019-09-01 01:25:54 +0900 44) # Some diagnostics enabled by default are noisy.
64a91907c8962 (Masahiro Yamada 2019-09-01 01:25:54 +0900 45) # Suppress them by using -Wno... except for W=1.
64a91907c8962 (Masahiro Yamada 2019-09-01 01:25:54 +0900 46)
076f421da5d45 (Masahiro Yamada 2018-10-30 22:26:33 +0900 47) ifdef CONFIG_CC_IS_CLANG
a1494304346a3 (Masahiro Yamada 2019-05-10 23:10:09 +0900 48) KBUILD_CFLAGS += -Wno-initializer-overrides
a1494304346a3 (Masahiro Yamada 2019-05-10 23:10:09 +0900 49) KBUILD_CFLAGS += -Wno-format
a1494304346a3 (Masahiro Yamada 2019-05-10 23:10:09 +0900 50) KBUILD_CFLAGS += -Wno-sign-compare
a1494304346a3 (Masahiro Yamada 2019-05-10 23:10:09 +0900 51) KBUILD_CFLAGS += -Wno-format-zero-length
82f2bc2fcc016 (Nathan Chancellor 2020-03-11 12:41:21 -0700 52) KBUILD_CFLAGS += $(call cc-disable-warning, pointer-to-enum-cast)
afe956c577b2d (Nathan Chancellor 2020-03-26 12:41:55 -0700 53) KBUILD_CFLAGS += -Wno-tautological-constant-out-of-range-compare
26ea6bb1fef06 (Behan Webster 2014-07-31 21:08:25 -0700 54) endif
64a91907c8962 (Masahiro Yamada 2019-09-01 01:25:54 +0900 55)
64a91907c8962 (Masahiro Yamada 2019-09-01 01:25:54 +0900 56) endif
64a91907c8962 (Masahiro Yamada 2019-09-01 01:25:54 +0900 57)
64a91907c8962 (Masahiro Yamada 2019-09-01 01:25:54 +0900 58) #
64a91907c8962 (Masahiro Yamada 2019-09-01 01:25:54 +0900 59) # W=2 - warnings which occur quite often but may still be relevant
64a91907c8962 (Masahiro Yamada 2019-09-01 01:25:54 +0900 60) #
e27128db62834 (Masahiro Yamada 2019-09-01 01:25:55 +0900 61) ifneq ($(findstring 2, $(KBUILD_EXTRA_WARN)),)
64a91907c8962 (Masahiro Yamada 2019-09-01 01:25:54 +0900 62)
64a91907c8962 (Masahiro Yamada 2019-09-01 01:25:54 +0900 63) KBUILD_CFLAGS += -Wdisabled-optimization
64a91907c8962 (Masahiro Yamada 2019-09-01 01:25:54 +0900 64) KBUILD_CFLAGS += -Wshadow
64a91907c8962 (Masahiro Yamada 2019-09-01 01:25:54 +0900 65) KBUILD_CFLAGS += $(call cc-option, -Wlogical-op)
64a91907c8962 (Masahiro Yamada 2019-09-01 01:25:54 +0900 66) KBUILD_CFLAGS += -Wmissing-field-initializers
355a3587d4ca0 (Rikard Falkeborn 2020-07-08 21:07:56 +0200 67) KBUILD_CFLAGS += -Wtype-limits
64a91907c8962 (Masahiro Yamada 2019-09-01 01:25:54 +0900 68) KBUILD_CFLAGS += $(call cc-option, -Wmaybe-uninitialized)
64a91907c8962 (Masahiro Yamada 2019-09-01 01:25:54 +0900 69) KBUILD_CFLAGS += $(call cc-option, -Wunused-macros)
64a91907c8962 (Masahiro Yamada 2019-09-01 01:25:54 +0900 70)
6863f5643dd71 (Masahiro Yamada 2019-09-07 11:52:36 +0900 71) KBUILD_CPPFLAGS += -DKBUILD_EXTRA_WARN2
6863f5643dd71 (Masahiro Yamada 2019-09-07 11:52:36 +0900 72)
64a91907c8962 (Masahiro Yamada 2019-09-01 01:25:54 +0900 73) endif
64a91907c8962 (Masahiro Yamada 2019-09-01 01:25:54 +0900 74)
64a91907c8962 (Masahiro Yamada 2019-09-01 01:25:54 +0900 75) #
64a91907c8962 (Masahiro Yamada 2019-09-01 01:25:54 +0900 76) # W=3 - more obscure warnings, can most likely be ignored
64a91907c8962 (Masahiro Yamada 2019-09-01 01:25:54 +0900 77) #
e27128db62834 (Masahiro Yamada 2019-09-01 01:25:55 +0900 78) ifneq ($(findstring 3, $(KBUILD_EXTRA_WARN)),)
64a91907c8962 (Masahiro Yamada 2019-09-01 01:25:54 +0900 79)
64a91907c8962 (Masahiro Yamada 2019-09-01 01:25:54 +0900 80) KBUILD_CFLAGS += -Wbad-function-cast
095fbca0a9493 (Arnd Bergmann 2020-10-26 23:03:13 +0100 81) KBUILD_CFLAGS += -Wcast-align
64a91907c8962 (Masahiro Yamada 2019-09-01 01:25:54 +0900 82) KBUILD_CFLAGS += -Wcast-qual
64a91907c8962 (Masahiro Yamada 2019-09-01 01:25:54 +0900 83) KBUILD_CFLAGS += -Wconversion
64a91907c8962 (Masahiro Yamada 2019-09-01 01:25:54 +0900 84) KBUILD_CFLAGS += -Wpacked
64a91907c8962 (Masahiro Yamada 2019-09-01 01:25:54 +0900 85) KBUILD_CFLAGS += -Wpadded
64a91907c8962 (Masahiro Yamada 2019-09-01 01:25:54 +0900 86) KBUILD_CFLAGS += -Wpointer-arith
64a91907c8962 (Masahiro Yamada 2019-09-01 01:25:54 +0900 87) KBUILD_CFLAGS += -Wredundant-decls
a97ea93ed5b64 (Joe Perches 2020-07-21 21:57:43 -0700 88) KBUILD_CFLAGS += -Wsign-compare
64a91907c8962 (Masahiro Yamada 2019-09-01 01:25:54 +0900 89) KBUILD_CFLAGS += -Wswitch-default
64a91907c8962 (Masahiro Yamada 2019-09-01 01:25:54 +0900 90) KBUILD_CFLAGS += $(call cc-option, -Wpacked-bitfield-compat)
64a91907c8962 (Masahiro Yamada 2019-09-01 01:25:54 +0900 91)
6863f5643dd71 (Masahiro Yamada 2019-09-07 11:52:36 +0900 92) KBUILD_CPPFLAGS += -DKBUILD_EXTRA_WARN3
6863f5643dd71 (Masahiro Yamada 2019-09-07 11:52:36 +0900 93)
a86fe35373506 (Masahiro Yamada 2014-04-14 18:27:10 +0900 94) endif