blob: d226c5fb13e28313203c4a2ece531f350a30c3ea [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001# SPDX-License-Identifier: GPL-2.0
Masahiro Yamadaa86fe352014-04-14 18:27:10 +09002# ==========================================================================
Masahiro Yamadaa86fe352014-04-14 18:27:10 +09003# make W=... settings
4#
Masahiro Yamada64a91902019-09-01 01:25:54 +09005# 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.
Masahiro Yamadaa86fe352014-04-14 18:27:10 +09007# ==========================================================================
8
Xiongfeng Wang321cb032018-01-11 17:22:29 +08009KBUILD_CFLAGS += $(call cc-disable-warning, packed-not-aligned)
10
Masahiro Yamadaa86fe352014-04-14 18:27:10 +090011ifeq ("$(origin W)", "command line")
12 export KBUILD_ENABLE_EXTRA_GCC_CHECKS := $(W)
13endif
14
Masahiro Yamada64a91902019-09-01 01:25:54 +090015#
16# W=1 - warnings which may be relevant and do not occur too often
17#
18ifneq ($(findstring 1, $(KBUILD_ENABLE_EXTRA_GCC_CHECKS)),)
Masahiro Yamadaa86fe352014-04-14 18:27:10 +090019
Masahiro Yamada64a91902019-09-01 01:25:54 +090020KBUILD_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)
Masahiro Yamada4c8dd952019-05-09 15:46:35 +090030# The following turn off the warnings enabled by -Wextra
Masahiro Yamada64a91902019-09-01 01:25:54 +090031KBUILD_CFLAGS += -Wno-missing-field-initializers
32KBUILD_CFLAGS += -Wno-sign-compare
Masahiro Yamadaa86fe352014-04-14 18:27:10 +090033
Behan Webster26ea6bb2014-07-31 21:08:25 -070034else
35
Masahiro Yamada64a91902019-09-01 01:25:54 +090036# Some diagnostics enabled by default are noisy.
37# Suppress them by using -Wno... except for W=1.
38
Masahiro Yamada076f4212018-10-30 22:26:33 +090039ifdef CONFIG_CC_IS_CLANG
Masahiro Yamadaa1494302019-05-10 23:10:09 +090040KBUILD_CFLAGS += -Wno-initializer-overrides
Masahiro Yamadaa1494302019-05-10 23:10:09 +090041KBUILD_CFLAGS += -Wno-format
42KBUILD_CFLAGS += -Wno-sign-compare
43KBUILD_CFLAGS += -Wno-format-zero-length
Behan Webster26ea6bb2014-07-31 21:08:25 -070044endif
Masahiro Yamada64a91902019-09-01 01:25:54 +090045
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
Masahiro Yamadaa86fe352014-04-14 18:27:10 +090080endif