[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAK7LNARDQPixBfWp8od1=13w+hcycYbyTX9+G-gqEHHwXxDCvA@mail.gmail.com>
Date: Tue, 20 Aug 2019 01:58:26 +0900
From: Masahiro Yamada <yamada.masahiro@...ionext.com>
To: Nathan Chancellor <natechancellor@...il.com>
Cc: Linux Kbuild mailing list <linux-kbuild@...r.kernel.org>,
Nick Desaulniers <ndesaulniers@...gle.com>,
Miguel Ojeda <miguel.ojeda.sandonis@...il.com>,
Borislav Petkov <bp@...e.de>,
Kees Cook <keescook@...omium.org>,
Luc Van Oostenryck <luc.vanoostenryck@...il.com>,
Michal Marek <michal.lkml@...kovi.net>,
Paul Burton <paul.burton@...s.com>,
Xiaozhou Liu <liuxiaozhou@...edance.com>,
clang-built-linux <clang-built-linux@...glegroups.com>,
Linux Kernel Mailing List <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH] kbuild: enable unused-function warnings for W= build with Clang
Hi Nathan,
On Tue, Aug 20, 2019 at 1:09 AM Nathan Chancellor
<natechancellor@...il.com> wrote:
>
> On Mon, Aug 19, 2019 at 07:51:38PM +0900, Masahiro Yamada wrote:
> > GCC and Clang have different policy for -Wunused-function; GCC does
> > not report unused-function warnings at all for the functions marked
> > as 'static inline'. Clang does report unused-function warnings if they
> > are defined in source files instead of headers.
> >
> > We could use Clang for detecting unused functions, but it has been
> > suppressed since commit abb2ea7dfd82 ("compiler, clang: suppress
> > warning for unused static inline functions").
> >
> > So, we never notice left-over code if functions in .c files are
> > marked as inline.
> >
> > Let's remove __maybe_unused from the inline macro. As always, it is
> > not a good idea to sprinkle warnings for the normal build. So, these
> > warnings will be shown for the W= build.
> >
> > 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 might affect the compiler's
> > optimization. When I need to fix unused-functions warnings, I prefer
> > adding #ifdef or __maybe_unused to function definitions.
> >
> > Signed-off-by: Masahiro Yamada <yamada.masahiro@...ionext.com>
>
> So if I understand everything correctly, this change allows us to start
> finding unused static inline functions with clang at W=1 but disables
> -Wunused-function by default... I am not sure that is a good tradeoff
> as I am pretty sure that W=1 is fairly noisy for clang although I
> haven't checked lately. I'd argue most regular developers do not build
> with W=1 meaning -Wunused-function generally will not be run with clang
> at all, missing stuff like this:
Try "git log --grep=W=1"
Some people are making efforts to fix W=1 warnings.
I believe somebody will start to remove unused static inline functions.
>
> https://lore.kernel.org/lkml/20190523010235.GA105588@archlinux-epyc/
>
> https://lore.kernel.org/lkml/1558574945-19275-1-git-send-email-skomatineni@nvidia.com/
>
> Furthermore, per the documemtation [1], -Wno-unused-function will also
> disable -Wunneeded-internal-declaration, which can help find bugs like
> commit 8289c4b6f2e5 ("platform/x86: mlx-platform: Properly use
> mlxplat_mlxcpld_msn201x_items").
>
> [1]: https://clang.llvm.org/docs/DiagnosticsReference.html#wunused-function
How about this?
KBUILD_CFLAGS += -Wno-unused-function
KBUILD_CFLAGS += -Wunneeded-internal-declaration
> Is there a way to conditionally remove __maybe_unused from the inline
> defintion so that we keep the current behavior but we can still
> selectively find potentially unused functions?
It would be possible by tweaking include/linux/compiler_types.h
but I am not a big fan of uglifying the 'inline' replacement any more.
--
Best Regards
Masahiro Yamada
Powered by blists - more mailing lists