blob: 62c275685b75e487a8646d8f7554122d1171009b [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
Behan Webster26ea6bb2014-07-31 21:08:25 -070054endif
Masahiro Yamada64a91902019-09-01 01:25:54 +090055
56endif
57
58#
59# W=2 - warnings which occur quite often but may still be relevant
60#
Masahiro Yamadae27128d2019-09-01 01:25:55 +090061ifneq ($(findstring 2, $(KBUILD_EXTRA_WARN)),)
Masahiro Yamada64a91902019-09-01 01:25:54 +090062
63KBUILD_CFLAGS += -Wcast-align
64KBUILD_CFLAGS += -Wdisabled-optimization
65KBUILD_CFLAGS += -Wnested-externs
66KBUILD_CFLAGS += -Wshadow
67KBUILD_CFLAGS += $(call cc-option, -Wlogical-op)
68KBUILD_CFLAGS += -Wmissing-field-initializers
69KBUILD_CFLAGS += -Wsign-compare
Rikard Falkeborn355a3582020-07-08 21:07:56 +020070KBUILD_CFLAGS += -Wtype-limits
Masahiro Yamada64a91902019-09-01 01:25:54 +090071KBUILD_CFLAGS += $(call cc-option, -Wmaybe-uninitialized)
72KBUILD_CFLAGS += $(call cc-option, -Wunused-macros)
73
Masahiro Yamada6863f562019-09-07 11:52:36 +090074KBUILD_CPPFLAGS += -DKBUILD_EXTRA_WARN2
75
Masahiro Yamada64a91902019-09-01 01:25:54 +090076endif
77
78#
79# W=3 - more obscure warnings, can most likely be ignored
80#
Masahiro Yamadae27128d2019-09-01 01:25:55 +090081ifneq ($(findstring 3, $(KBUILD_EXTRA_WARN)),)
Masahiro Yamada64a91902019-09-01 01:25:54 +090082
83KBUILD_CFLAGS += -Wbad-function-cast
84KBUILD_CFLAGS += -Wcast-qual
85KBUILD_CFLAGS += -Wconversion
86KBUILD_CFLAGS += -Wpacked
87KBUILD_CFLAGS += -Wpadded
88KBUILD_CFLAGS += -Wpointer-arith
89KBUILD_CFLAGS += -Wredundant-decls
90KBUILD_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