linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Nathan Chancellor <natechancellor@gmail.com>
To: Masahiro Yamada <yamada.masahiro@socionext.com>
Cc: linux-kbuild@vger.kernel.org,
	Nick Desaulniers <ndesaulniers@google.com>,
	Arnd Bergmann <arnd@arndb.de>,
	Michal Marek <michal.lkml@markovi.net>,
	clang-built-linux@googlegroups.com, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] kbuild: enable unused-function warnings for W= build with Clang
Date: Tue, 27 Aug 2019 12:28:11 -0700	[thread overview]
Message-ID: <20190827192811.GA24626@archlinux-threadripper> (raw)
In-Reply-To: <20190827103621.1073-1-yamada.masahiro@socionext.com>

On Tue, Aug 27, 2019 at 07:36:21PM +0900, Masahiro Yamada wrote:
> GCC and Clang have different policy for -Wunused-function; GCC never
> reports unused-function warnings for 'static inline' functions whereas
> Clang reports them 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 remove 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. As always, it is not a
> good idea to sprinkle warnings for the normal build, so I added
> -Wno-unsued-function for no W= build.
> 
> Per the documentation [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"). (pointed out by Nathan Chancellor)
> I added -Wunneeded-internal-declaration to address it.
> 
> 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's optimization. I prefer __maybe_unused or #ifdef around the
> definition.
> 
> [1]: https://clang.llvm.org/docs/DiagnosticsReference.html#wunused-function
> 
> Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
> Reviewed-by: Kees Cook <keescook@chromium.org>

I am still not a big fan of this as I think it weakens clang as a
standalone compiler but the change itself looks good so if it is going
in anyways:

Reviewed-by: Nathan Chancellor <natechancellor@gmail.com>

I'm sure Nick would like to weigh in as well before this gets merged.

  reply	other threads:[~2019-08-27 19:28 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-27 10:36 [PATCH v2] kbuild: enable unused-function warnings for W= build with Clang Masahiro Yamada
2019-08-27 19:28 ` Nathan Chancellor [this message]
2019-08-27 20:58   ` Nick Desaulniers
2019-08-27 21:34     ` Nathan Chancellor
2019-08-27 21:56       ` Nick Desaulniers
2019-08-28  2:57         ` Masahiro Yamada
2019-08-28 23:10           ` Nick Desaulniers

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190827192811.GA24626@archlinux-threadripper \
    --to=natechancellor@gmail.com \
    --cc=arnd@arndb.de \
    --cc=clang-built-linux@googlegroups.com \
    --cc=linux-kbuild@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=michal.lkml@markovi.net \
    --cc=ndesaulniers@google.com \
    --cc=yamada.masahiro@socionext.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).