From: Joe Perches <joe@perches.com>
To: intel-wired-lan@osuosl.org
Subject: [Intel-wired-lan] [Cocci] [RFC] treewide: cleanup unreachable breaks
Date: Sat, 17 Oct 2020 12:00:01 -0700 [thread overview]
Message-ID: <503af4a57ca6daeb3e42a9be136dcd21e6d6e23d.camel@perches.com> (raw)
In-Reply-To: <alpine.DEB.2.22.394.2010172016370.9440@hadrien>
On Sat, 2020-10-17 at 20:21 +0200, Julia Lawall wrote:
> On Sat, 17 Oct 2020, Joe Perches wrote:
> > On Sat, 2020-10-17 at 09:09 -0700, trix at redhat.com wrote:
> > > From: Tom Rix <trix@redhat.com>
> > >
> > > This is a upcoming change to clean up a new warning treewide.
> > > I am wondering if the change could be one mega patch (see below) or
> > > normal patch per file about 100 patches or somewhere half way by collecting
> > > early acks.
> > >
> > > clang has a number of useful, new warnings see
> > > https://clang.llvm.org/docs/DiagnosticsReference.html
> > >
> > > This change cleans up -Wunreachable-code-break
> > > https://clang.llvm.org/docs/DiagnosticsReference.html#wunreachable-code-break
> > > for 266 of 485 warnings in this week's linux-next, allyesconfig on x86_64.
> >
> > Early acks/individual patches by subsystem would be good.
> > Better still would be an automated cocci script.
>
> Coccinelle is not especially good at this, because it is based on control
> flow, and a return or goto diverts the control flow away from the break.
> A hack to solve the problem is to put an if around the return or goto, but
> that gives the break a meaningless file name and line number. I collected
> the following list, but it only has 439 results, so fewer than clang. But
> maybe there are some files that are not considered by clang in the x86
> allyesconfig configuration.
>
> Probably checkpatch is the best solution here, since it is not
> configuration sensitive and doesn't care about control flow.
Likely the clang compiler is the best option here.
It might be useful to add -Wunreachable-code-break to W=1
or just always enable it if it isn't already enabled.
diff --git a/scripts/Makefile.extrawarn b/scripts/Makefile.extrawarn
index 95e4cdb94fe9..3819787579d5 100644
--- a/scripts/Makefile.extrawarn
+++ b/scripts/Makefile.extrawarn
@@ -32,6 +32,7 @@ KBUILD_CFLAGS += $(call cc-option, -Wunused-but-set-variable)
KBUILD_CFLAGS += $(call cc-option, -Wunused-const-variable)
KBUILD_CFLAGS += $(call cc-option, -Wpacked-not-aligned)
KBUILD_CFLAGS += $(call cc-option, -Wstringop-truncation)
+KBUILD_CFLAGS += $(call cc-option, -Wunreachable-code-break)
# The following turn off the warnings enabled by -Wextra
KBUILD_CFLAGS += -Wno-missing-field-initializers
KBUILD_CFLAGS += -Wno-sign-compare
(and thank you Tom for pushing this forward)
checkpatch can't find instances like:
case FOO:
if (foo)
return 1;
else
return 2;
break;
As it doesn't track flow and relies on the number
of tabs to be the same for any goto/return and break;
checkpatch will warn on:
case FOO:
...
goto bar;
break;
next prev parent reply other threads:[~2020-10-17 19:00 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-10-17 16:09 [Intel-wired-lan] [RFC] treewide: cleanup unreachable breaks trix
2020-10-17 16:24 ` Joe Perches
2020-10-17 18:21 ` [Intel-wired-lan] [Cocci] " Julia Lawall
2020-10-17 19:00 ` Joe Perches [this message]
2020-10-17 21:01 ` [Intel-wired-lan] " Dan Williams
2020-10-18 5:43 ` Greg KH
2020-10-18 14:04 ` Tom Rix
2020-10-19 19:42 ` Nick Desaulniers
2020-10-19 23:05 ` Jason Gunthorpe
2020-10-20 14:09 ` Tom Rix
2020-10-20 8:47 ` [Intel-wired-lan] [Ocfs2-devel] " John Haxby
2020-10-20 13:55 ` [Intel-wired-lan] " Tom Rix
2020-10-20 18:42 ` Joe Perches
2020-10-18 9:29 ` Hans de Goede
2020-10-18 18:59 ` [Intel-wired-lan] [Ocfs2-devel] " Matthew Wilcox
2020-10-18 19:06 ` Joe Perches
2020-10-18 19:13 ` James Bottomley
2020-10-18 19:16 ` Matthew Wilcox
2020-10-18 19:17 ` James Bottomley
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=503af4a57ca6daeb3e42a9be136dcd21e6d6e23d.camel@perches.com \
--to=joe@perches.com \
--cc=intel-wired-lan@osuosl.org \
/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