blob: 8be892887d71687085b94d4378c1b5dfa34df4b6 [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 Yamadae27128d2019-09-01 01:25:55 +090011# backward compatibility
12KBUILD_EXTRA_WARN ?= $(KBUILD_ENABLE_EXTRA_GCC_CHECKS)
13
Masahiro Yamadaa86fe352014-04-14 18:27:10 +090014ifeq ("$(origin W)", "command line")
Masahiro Yamadae27128d2019-09-01 01:25:55 +090015 KBUILD_EXTRA_WARN := $(W)
Masahiro Yamadaa86fe352014-04-14 18:27:10 +090016endif
17
Masahiro Yamadae27128d2019-09-01 01:25:55 +090018export KBUILD_EXTRA_WARN
19
Masahiro Yamada64a91902019-09-01 01:25:54 +090020#
21# W=1 - warnings which may be relevant and do not occur too often
22#
Masahiro Yamadae27128d2019-09-01 01:25:55 +090023ifneq ($(findstring 1, $(KBUILD_EXTRA_WARN)),)
Masahiro Yamadaa86fe352014-04-14 18:27:10 +090024
Masahiro Yamada64a91902019-09-01 01:25:54 +090025KBUILD_CFLAGS += -Wextra -Wunused -Wno-unused-parameter
26KBUILD_CFLAGS += -Wmissing-declarations
27KBUILD_CFLAGS += -Wmissing-format-attribute
28KBUILD_CFLAGS += -Wmissing-prototypes
29KBUILD_CFLAGS += -Wold-style-definition
30KBUILD_CFLAGS += -Wmissing-include-dirs
31KBUILD_CFLAGS += $(call cc-option, -Wunused-but-set-variable)
32KBUILD_CFLAGS += $(call cc-option, -Wunused-const-variable)
33KBUILD_CFLAGS += $(call cc-option, -Wpacked-not-aligned)
34KBUILD_CFLAGS += $(call cc-option, -Wstringop-truncation)
Masahiro Yamada4c8dd952019-05-09 15:46:35 +090035# The following turn off the warnings enabled by -Wextra
Masahiro Yamada64a91902019-09-01 01:25:54 +090036KBUILD_CFLAGS += -Wno-missing-field-initializers
37KBUILD_CFLAGS += -Wno-sign-compare
Rikard Falkeborn355a3582020-07-08 21:07:56 +020038KBUILD_CFLAGS += -Wno-type-limits
Masahiro Yamadaa86fe352014-04-14 18:27:10 +090039
Masahiro Yamada6863f562019-09-07 11:52:36 +090040KBUILD_CPPFLAGS += -DKBUILD_EXTRA_WARN1
41
Behan Webster26ea6bb2014-07-31 21:08:25 -070042else
43
Masahiro Yamada64a91902019-09-01 01:25:54 +090044# Some diagnostics enabled by default are noisy.
45# Suppress them by using -Wno... except for W=1.
46
Masahiro Yamada076f4212018-10-30 22:26:33 +090047ifdef CONFIG_CC_IS_CLANG
Masahiro Yamadaa1494302019-05-10 23:10:09 +090048KBUILD_CFLAGS += -Wno-initializer-overrides
Masahiro Yamadaa1494302019-05-10 23:10:09 +090049KBUILD_CFLAGS += -Wno-format
50KBUILD_CFLAGS += -Wno-sign-compare
51KBUILD_CFLAGS += -Wno-format-zero-length
Nathan Chancellor82f2bc22020-03-11 12:41:21 -070052KBUILD_CFLAGS += $(call cc-disable-warning, pointer-to-enum-cast)
Nathan Chancellorafe956c2020-03-26 12:41:55 -070053KBUILD_CFLAGS += -Wno-tautological-constant-out-of-range-compare
Nathan Chancellor1cf5f152022-02-02 16:05:16 -070054KBUILD_CFLAGS += $(call cc-disable-warning, unaligned-access)
Behan Webster26ea6bb2014-07-31 21:08:25 -070055endif
Masahiro Yamada64a91902019-09-01 01:25:54 +090056
57endif
58
59#
60# W=2 - warnings which occur quite often but may still be relevant
61#
Masahiro Yamadae27128d2019-09-01 01:25:55 +090062ifneq ($(findstring 2, $(KBUILD_EXTRA_WARN)),)
Masahiro Yamada64a91902019-09-01 01:25:54 +090063
Masahiro Yamada64a91902019-09-01 01:25:54 +090064KBUILD_CFLAGS += -Wdisabled-optimization
Masahiro Yamada64a91902019-09-01 01:25:54 +090065KBUILD_CFLAGS += -Wshadow
66KBUILD_CFLAGS += $(call cc-option, -Wlogical-op)
67KBUILD_CFLAGS += -Wmissing-field-initializers
Rikard Falkeborn355a3582020-07-08 21:07:56 +020068KBUILD_CFLAGS += -Wtype-limits
Masahiro Yamada64a91902019-09-01 01:25:54 +090069KBUILD_CFLAGS += $(call cc-option, -Wmaybe-uninitialized)
70KBUILD_CFLAGS += $(call cc-option, -Wunused-macros)
71
Masahiro Yamada6863f562019-09-07 11:52:36 +090072KBUILD_CPPFLAGS += -DKBUILD_EXTRA_WARN2
73
Masahiro Yamada64a91902019-09-01 01:25:54 +090074endif
75
76#
77# W=3 - more obscure warnings, can most likely be ignored
78#
Masahiro Yamadae27128d2019-09-01 01:25:55 +090079ifneq ($(findstring 3, $(KBUILD_EXTRA_WARN)),)
Masahiro Yamada64a91902019-09-01 01:25:54 +090080
81KBUILD_CFLAGS += -Wbad-function-cast
Arnd Bergmann095fbca2020-10-26 23:03:13 +010082KBUILD_CFLAGS += -Wcast-align
Masahiro Yamada64a91902019-09-01 01:25:54 +090083KBUILD_CFLAGS += -Wcast-qual
84KBUILD_CFLAGS += -Wconversion
85KBUILD_CFLAGS += -Wpacked
86KBUILD_CFLAGS += -Wpadded
87KBUILD_CFLAGS += -Wpointer-arith
88KBUILD_CFLAGS += -Wredundant-decls
Joe Perchesa97ea932020-07-21 21:57:43 -070089KBUILD_CFLAGS += -Wsign-compare
Masahiro Yamada64a91902019-09-01 01:25:54 +090090KBUILD_CFLAGS += -Wswitch-default
91KBUILD_CFLAGS += $(call cc-option, -Wpacked-bitfield-compat)
92
Masahiro Yamada6863f562019-09-07 11:52:36 +090093KBUILD_CPPFLAGS += -DKBUILD_EXTRA_WARN3
94
Masahiro Yamadaa86fe352014-04-14 18:27:10 +090095endif