From: Kris Borer <kborer@gmail.com>
To: Julia.Lawall@lip6.fr
Cc: Gilles.Muller@lip6.fr, nicolas.palix@imag.fr, mmarek@suse.cz,
linux-kernel@vger.kernel.org, cocci@systeme.lip6.fr,
Kris Borer <kborer@gmail.com>
Subject: [RFC] coccinelle: add style check for assignment in if
Date: Wed, 12 Aug 2015 09:51:40 -0400 [thread overview]
Message-ID: <1439387500-11183-1-git-send-email-kborer@gmail.com> (raw)
Add a semantic patch for fixing some cases of checkpatch.pl error:
ERROR: do not use assignment in if condition
Signed-off-by: Kris Borer <kborer@gmail.com>
---
scripts/coccinelle/style/assignment_in_if.cocci | 82 +++++++++++++++++++++++++
1 file changed, 82 insertions(+)
create mode 100644 scripts/coccinelle/style/assignment_in_if.cocci
diff --git a/scripts/coccinelle/style/assignment_in_if.cocci b/scripts/coccinelle/style/assignment_in_if.cocci
new file mode 100644
index 0000000..d9895e7
--- /dev/null
+++ b/scripts/coccinelle/style/assignment_in_if.cocci
@@ -0,0 +1,82 @@
+// find checkpatch.pl errors of the type:
+// ERROR: do not use assignment in if condition
+//
+// Confidence: Moderate
+
+
+// if ( ret = call() )
+@if1@
+identifier i;
+expression E;
+statement S1, S2;
+@@
+
++ i = E;
+ if (
+- (i = E)
++ i
+ ) S1 else S2
+
+
+// if ( (ret = call()) < 0 )
+@if2@
+identifier i;
+expression E;
+statement S1, S2;
+binary operator b;
+@@
+
++ i = E;
+ if (
+- (i = E)
++ i
+ b ... ) S1 else S2
+
+// if ( ptr->fun && (ret = ptr->fun()) < 0 )
+@if3@
+identifier i, i2;
+expression E1, E2;
+constant c;
+binary operator b;
+@@
+
++ if( E1->i ) {
++ i2 = E2;
++ if (i2 < c) {
+- if( E1->i && ((i2 = E2) b c) ) {
+ ...
+- }
++ }
++ }
+
+// if ( (ret = call()) < 0 && ret != 0 )
+@if4@
+identifier i;
+expression E, E2, E3;
+statement S1, S2;
+binary operator b;
+@@
+
++ i = E;
+ if (
+- (i = E)
++ i
+ b
+ ... && E2 && E3 ) S1 else S2
+
+// if ( (ret = call()) < 0 && ret != 0 && ret != 0 )
+@if5@
+identifier i;
+expression E, E2, E3;
+statement S1, S2;
+binary operator b;
+@@
+
++ i = E;
+ if (
+- (i = E)
++ i
+ b
+ ... && E2 && E3 ) S1 else S2
+
+
--
1.9.1
next reply other threads:[~2015-08-12 13:51 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-08-12 13:51 Kris Borer [this message]
2015-08-12 14:00 ` Julia Lawall
2015-08-12 14:12 ` Michal Marek
[not found] ` <CAMy_N63pADkvb4vP=1ReMPpmR7e32TmEE91hELKXTsYnPP+GZA@mail.gmail.com>
2015-08-12 15:05 ` Michal Marek
2015-08-12 15:16 ` Julia Lawall
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=1439387500-11183-1-git-send-email-kborer@gmail.com \
--to=kborer@gmail.com \
--cc=Gilles.Muller@lip6.fr \
--cc=Julia.Lawall@lip6.fr \
--cc=cocci@systeme.lip6.fr \
--cc=linux-kernel@vger.kernel.org \
--cc=mmarek@suse.cz \
--cc=nicolas.palix@imag.fr \
/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
all inboxes | Powered by JetHome®