blob: 4aea7cf71d11f5660563b1252d0bd2e492221283 [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
Masahiro Yamadaa86fe352014-04-14 18:27:10 +090038
Masahiro Yamada6863f562019-09-07 11:52:36 +090039KBUILD_CPPFLAGS += -DKBUILD_EXTRA_WARN1
40
Behan Webster26ea6bb2014-07-31 21:08:25 -070041else
42
Masahiro Yamada64a91902019-09-01 01:25:54 +090043# Some diagnostics enabled by default are noisy.
44# Suppress them by using -Wno... except for W=1.
45
Masahiro Yamada076f4212018-10-30 22:26:33 +090046ifdef CONFIG_CC_IS_CLANG
Masahiro Yamadaa1494302019-05-10 23:10:09 +090047KBUILD_CFLAGS += -Wno-initializer-overrides
Masahiro Yamadaa1494302019-05-10 23:10:09 +090048KBUILD_CFLAGS += -Wno-format
49KBUILD_CFLAGS += -Wno-sign-compare
50KBUILD_CFLAGS += -Wno-format-zero-length
Nathan Chancellor82f2bc22020-03-11 12:41:21 -070051KBUILD_CFLAGS += $(call cc-disable-warning, pointer-to-enum-cast)
Nathan Chancellorafe956c2020-03-26 12:41:55 -070052KBUILD_CFLAGS += -Wno-tautological-constant-out-of-range-compare
Behan Webster26ea6bb2014-07-31 21:08:25 -070053endif
Masahiro Yamada64a91902019-09-01 01:25:54 +090054
55endif
56
57#
58# W=2 - warnings which occur quite often but may still be relevant
59#
Masahiro Yamadae27128d2019-09-01 01:25:55 +090060ifneq ($(findstring 2, $(KBUILD_EXTRA_WARN)),)
Masahiro Yamada64a91902019-09-01 01:25:54 +090061
62KBUILD_CFLAGS += -Wcast-align
63KBUILD_CFLAGS += -Wdisabled-optimization
64KBUILD_CFLAGS += -Wnested-externs
65KBUILD_CFLAGS += -Wshadow
66KBUILD_CFLAGS += $(call cc-option, -Wlogical-op)
67KBUILD_CFLAGS += -Wmissing-field-initializers
68KBUILD_CFLAGS += -Wsign-compare
69KBUILD_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
82KBUILD_CFLAGS += -Wcast-qual
83KBUILD_CFLAGS += -Wconversion
84KBUILD_CFLAGS += -Wpacked
85KBUILD_CFLAGS += -Wpadded
86KBUILD_CFLAGS += -Wpointer-arith
87KBUILD_CFLAGS += -Wredundant-decls
88KBUILD_CFLAGS += -Wswitch-default
89KBUILD_CFLAGS += $(call cc-option, -Wpacked-bitfield-compat)
90
Masahiro Yamada6863f562019-09-07 11:52:36 +090091KBUILD_CPPFLAGS += -DKBUILD_EXTRA_WARN3
92
Masahiro Yamadaa86fe352014-04-14 18:27:10 +090093endif