History

kbuild: refactor scripts/Makefile.extrawarn

Instead of the warning-[123] magic, let's accumulate compiler options to KBUILD_CFLAGS directly as the top Makefile does. I think this makes it easier to understand what is going on in this file. This commit slightly changes the behavior, I think all of which are OK. [1] Currently, cc-option calls are needlessly evaluated. For example, warning-3 += $(call cc-option, -Wpacked-bitfield-compat) needs evaluating only when W=3, but it is actually evaluated for W=1, W=2 as well. With this commit, only relevant cc-option calls will be evaluated. This is a slight optimization. [2] Currently, unsupported level like W=4 is checked by: $(error W=$(KBUILD_ENABLE_EXTRA_GCC_CHECKS) is unknown) This will no longer be checked, but I do not think it is a big deal. [3] Currently, 4 Clang warnings (Winitializer-overrides, Wformat, Wsign-compare, Wformat-zero-length) are shown by any of W=1, W=2, and W=3. With this commit, they will be warned only by W=1. I think this is a more correct behavior since each warning belongs to only one group. For understanding this commit correctly: We have 3 warning groups, W=1, W=2, and W=3. You may think W=3 has a higher level than W=1, but they are actually independent. If you like, you can combine them like W=13. To enable all the warnings, you can pass W=123. It is shown by 'make help', but not noticed much. Since we support W= combination, there should not exist intersection among the three groups. If we enable Winitializer-overrides for W=1, we do not need to for W=2 or W=3. This is the reason why I think the change [3] makes sense. The documentation says -Winitializer-overrides is enabled by default. (https://clang.llvm.org/docs/DiagnosticsReference.html#winitializer-overrides) We negate it by passing -Wno-initializer-overrides for the normal build, but we do not do that for W=1. This means, W=1 effectively enables -Winitializer-overrides by the clang's default. The same for the other three. Add comments in case people are confused with the code.

Masahiro Yamada committed 7 years ago

Commit 64a91901 parent 60bef521 file · +56 −50Browse files

Unified · Split

scripts/Makefile.extrawarn+56−50
@@ -1,14 +1,9 @@
1# SPDX-License-Identifier: GPL-2.01# SPDX-License-Identifier: GPL-2.0
2# ==========================================================================2# ==========================================================================
3#
4# make W=... settings3# make W=... settings
5#4#
6# W=1 - warnings that may be relevant and does not occur too often5# There are three warning groups enabled by W=1, W=2, W=3.
7# W=2 - warnings that occur quite often but may still be relevant6# They are independent, and can be combined like W=12 or W=123.
8# W=3 - the more obscure warnings, can most likely be ignored
9#
10# $(call cc-option, -W...) handles gcc -W.. options which
11# are not supported by all versions of the compiler
12# ==========================================================================7# ==========================================================================
13 8
14KBUILD_CFLAGS += $(call cc-disable-warning, packed-not-aligned)9KBUILD_CFLAGS += $(call cc-disable-warning, packed-not-aligned)
@@ -17,58 +12,69 @@ ifeq ("$(origin W)", "command line") · 2 unmodified lines
17 export KBUILD_ENABLE_EXTRA_GCC_CHECKS := $(W)12 export KBUILD_ENABLE_EXTRA_GCC_CHECKS := $(W)
18endif13endif
19 14
20ifdef KBUILD_ENABLE_EXTRA_GCC_CHECKS15#
21warning- := $(empty)16# W=1 - warnings which may be relevant and do not occur too often
17#
18ifneq ($(findstring 1, $(KBUILD_ENABLE_EXTRA_GCC_CHECKS)),)
22 19
23warning-1 := -Wextra -Wunused -Wno-unused-parameter20KBUILD_CFLAGS += -Wextra -Wunused -Wno-unused-parameter
24warning-1 += -Wmissing-declarations21KBUILD_CFLAGS += -Wmissing-declarations
25warning-1 += -Wmissing-format-attribute22KBUILD_CFLAGS += -Wmissing-format-attribute
26warning-1 += -Wmissing-prototypes23KBUILD_CFLAGS += -Wmissing-prototypes
27warning-1 += -Wold-style-definition24KBUILD_CFLAGS += -Wold-style-definition
28warning-1 += -Wmissing-include-dirs25KBUILD_CFLAGS += -Wmissing-include-dirs
29warning-1 += $(call cc-option, -Wunused-but-set-variable)26KBUILD_CFLAGS += $(call cc-option, -Wunused-but-set-variable)
30warning-1 += $(call cc-option, -Wunused-const-variable)27KBUILD_CFLAGS += $(call cc-option, -Wunused-const-variable)
31warning-1 += $(call cc-option, -Wpacked-not-aligned)28KBUILD_CFLAGS += $(call cc-option, -Wpacked-not-aligned)
32warning-1 += $(call cc-option, -Wstringop-truncation)29KBUILD_CFLAGS += $(call cc-option, -Wstringop-truncation)
33# The following turn off the warnings enabled by -Wextra30# The following turn off the warnings enabled by -Wextra
34warning-1 += -Wno-missing-field-initializers31KBUILD_CFLAGS += -Wno-missing-field-initializers
35warning-1 += -Wno-sign-compare32KBUILD_CFLAGS += -Wno-sign-compare
36
37warning-2 += -Wcast-align
38warning-2 += -Wdisabled-optimization
39warning-2 += -Wnested-externs
40warning-2 += -Wshadow
41warning-2 += $(call cc-option, -Wlogical-op)
42warning-2 += -Wmissing-field-initializers
43warning-2 += -Wsign-compare
44warning-2 += $(call cc-option, -Wmaybe-uninitialized)
45warning-2 += $(call cc-option, -Wunused-macros)
46
47warning-3 := -Wbad-function-cast
48warning-3 += -Wcast-qual
49warning-3 += -Wconversion
50warning-3 += -Wpacked
51warning-3 += -Wpadded
52warning-3 += -Wpointer-arith
53warning-3 += -Wredundant-decls
54warning-3 += -Wswitch-default
55warning-3 += $(call cc-option, -Wpacked-bitfield-compat)
56
57warning := $(warning-$(findstring 1, $(KBUILD_ENABLE_EXTRA_GCC_CHECKS)))
58warning += $(warning-$(findstring 2, $(KBUILD_ENABLE_EXTRA_GCC_CHECKS)))
59warning += $(warning-$(findstring 3, $(KBUILD_ENABLE_EXTRA_GCC_CHECKS)))
60
61ifeq ("$(strip $(warning))","")
62 $(error W=$(KBUILD_ENABLE_EXTRA_GCC_CHECKS) is unknown)
63endif
64 33
65KBUILD_CFLAGS += $(warning)
66else34else
67 35
36# Some diagnostics enabled by default are noisy.
37# Suppress them by using -Wno... except for W=1.
38
68ifdef CONFIG_CC_IS_CLANG39ifdef CONFIG_CC_IS_CLANG
69KBUILD_CFLAGS += -Wno-initializer-overrides40KBUILD_CFLAGS += -Wno-initializer-overrides
70KBUILD_CFLAGS += -Wno-format41KBUILD_CFLAGS += -Wno-format
71KBUILD_CFLAGS += -Wno-sign-compare42KBUILD_CFLAGS += -Wno-sign-compare
72KBUILD_CFLAGS += -Wno-format-zero-length43KBUILD_CFLAGS += -Wno-format-zero-length
73endif44endif
45
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
74endif80endif