diff options
author | Masahiro Yamada <yamada.masahiro@socionext.com> | 2019-09-07 11:52:36 +0900 |
---|---|---|
committer | Masahiro Yamada <yamada.masahiro@socionext.com> | 2019-09-09 23:55:43 +0900 |
commit | 6863f5643dd717376c2fdc85a47a00f9d738a834 (patch) | |
tree | b0924cc65ae676fa559fafda49ee1887d37b84ca /scripts/Makefile.extrawarn | |
parent | e27128db62834c5b906585c2d97f0ddd431fa28f (diff) |
kbuild: allow Clang to find unused static inline functions for W=1 build
GCC and Clang have different policy for -Wunused-function; GCC does not
warn unused static inline functions at all whereas Clang does if they
are defined in source files instead of included headers although it has
been suppressed since commit abb2ea7dfd82 ("compiler, clang: suppress
warning for unused static inline functions").
We often miss to delete unused functions where 'static inline' is used
in *.c files since there is no tool to detect them. Unused code remains
until somebody notices. For example, commit 075ddd75680f ("regulator:
core: remove unused rdev_get_supply()").
Let's remove __maybe_unused from the inline macro to allow Clang to
start finding unused static inline functions. For now, we do this only
for W=1 build since it is not a good idea to sprinkle warnings for the
normal build (e.g. 35 warnings for arch/x86/configs/x86_64_defconfig).
My initial attempt was to add -Wno-unused-function for no W= build
(https://lore.kernel.org/patchwork/patch/1120594/)
Nathan Chancellor pointed out that would weaken Clang's checks since
we would no longer get -Wunused-function without W=1. It is true GCC
would catch unused static non-inline functions, but it would weaken
Clang as a standalone compiler, at least.
Hence, here is a counter implementation. The current problem is, W=...
only controls compiler flags, which are globally effective. There is
no way to address only 'static inline' functions.
This commit defines KBUILD_EXTRA_WARN[123] corresponding to W=[123].
When KBUILD_EXTRA_WARN1 is defined, __maybe_unused is omitted from
the 'inline' macro.
The new macro __inline_maybe_unused makes the code a bit uglier, so I
hope we can remove it entirely after fixing most of the warnings.
If you contribute to code clean-up, please run "make CC=clang W=1"
and check -Wunused-function warnings. You will find lots of unused
functions.
Some of them are false-positives because the call-sites are disabled
by #ifdef. I do not like to abuse the inline keyword for suppressing
unused-function warnings because it is intended to be a hint for the
compiler optimization. I prefer #ifdef around the definition, or
__maybe_unused if #ifdef would make the code too ugly.
Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
Reviewed-by: Nathan Chancellor <natechancellor@gmail.com>
Tested-by: Nathan Chancellor <natechancellor@gmail.com>
Diffstat (limited to 'scripts/Makefile.extrawarn')
-rw-r--r-- | scripts/Makefile.extrawarn | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/scripts/Makefile.extrawarn b/scripts/Makefile.extrawarn index 53eb7e0c6a5a..ecddf83ac142 100644 --- a/scripts/Makefile.extrawarn +++ b/scripts/Makefile.extrawarn @@ -36,6 +36,8 @@ KBUILD_CFLAGS += $(call cc-option, -Wstringop-truncation) KBUILD_CFLAGS += -Wno-missing-field-initializers KBUILD_CFLAGS += -Wno-sign-compare +KBUILD_CPPFLAGS += -DKBUILD_EXTRA_WARN1 + else # Some diagnostics enabled by default are noisy. @@ -65,6 +67,8 @@ KBUILD_CFLAGS += -Wsign-compare KBUILD_CFLAGS += $(call cc-option, -Wmaybe-uninitialized) KBUILD_CFLAGS += $(call cc-option, -Wunused-macros) +KBUILD_CPPFLAGS += -DKBUILD_EXTRA_WARN2 + endif # @@ -82,4 +86,6 @@ KBUILD_CFLAGS += -Wredundant-decls KBUILD_CFLAGS += -Wswitch-default KBUILD_CFLAGS += $(call cc-option, -Wpacked-bitfield-compat) +KBUILD_CPPFLAGS += -DKBUILD_EXTRA_WARN3 + endif |