All of lore.kernel.org
 help / color / mirror / Atom feed
From: josh@joshtriplett.org (Josh Triplett)
To: cocci@systeme.lip6.fr
Subject: [Cocci] [PATCHv2] coccinelle: Add a script to find unnecessary ifs with no body
Date: Sat, 2 Nov 2013 08:15:01 -0700	[thread overview]
Message-ID: <20131102151500.GW15704@leaf> (raw)
In-Reply-To: <alpine.DEB.2.02.1311021550330.2261@hadrien>

This script finds code like this, with an unnecessary if:

if (foo) {}

Provides report mode only, since patching often eliminates conditionals
that contain TODO comments or similar.

Signed-off-by: Josh Triplett <josh@joshtriplett.org>
---

v2: Drop patch mode.

 scripts/coccinelle/misc/unnecessary-if.cocci | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)
 create mode 100644 scripts/coccinelle/misc/unnecessary-if.cocci

diff --git a/scripts/coccinelle/misc/unnecessary-if.cocci b/scripts/coccinelle/misc/unnecessary-if.cocci
new file mode 100644
index 0000000..28ac895
--- /dev/null
+++ b/scripts/coccinelle/misc/unnecessary-if.cocci
@@ -0,0 +1,23 @@
+/// Find unnecessary ifs with no statements.
+//
+// Report mode only, since patch mode often deletes ifs that contain TODO
+// comments.
+//
+// Confidence: High
+// Options: --no-includes --include-headers
+
+virtual report
+virtual context
+
+ at r depends on report || context@
+expression E;
+position p;
+@@
+if at p (E) {}
+
+ at script:python depends on report@
+p << r.p;
+@@
+
+msg = "WARNING: Unnecessary if with no body."
+coccilib.report.print_report(p[0], msg)
-- 
1.8.4.2

WARNING: multiple messages have this Message-ID (diff)
From: Josh Triplett <josh@joshtriplett.org>
To: Julia Lawall <julia.lawall@lip6.fr>
Cc: Gilles Muller <Gilles.Muller@lip6.fr>,
	Nicolas Palix <nicolas.palix@imag.fr>,
	Michal Marek <mmarek@suse.cz>,
	linux-kernel@vger.kernel.org, cocci@systeme.lip6.fr
Subject: [PATCHv2] coccinelle: Add a script to find unnecessary ifs with no body
Date: Sat, 2 Nov 2013 08:15:01 -0700	[thread overview]
Message-ID: <20131102151500.GW15704@leaf> (raw)
In-Reply-To: <alpine.DEB.2.02.1311021550330.2261@hadrien>

This script finds code like this, with an unnecessary if:

if (foo) {}

Provides report mode only, since patching often eliminates conditionals
that contain TODO comments or similar.

Signed-off-by: Josh Triplett <josh@joshtriplett.org>
---

v2: Drop patch mode.

 scripts/coccinelle/misc/unnecessary-if.cocci | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)
 create mode 100644 scripts/coccinelle/misc/unnecessary-if.cocci

diff --git a/scripts/coccinelle/misc/unnecessary-if.cocci b/scripts/coccinelle/misc/unnecessary-if.cocci
new file mode 100644
index 0000000..28ac895
--- /dev/null
+++ b/scripts/coccinelle/misc/unnecessary-if.cocci
@@ -0,0 +1,23 @@
+/// Find unnecessary ifs with no statements.
+//
+// Report mode only, since patch mode often deletes ifs that contain TODO
+// comments.
+//
+// Confidence: High
+// Options: --no-includes --include-headers
+
+virtual report
+virtual context
+
+@r depends on report || context@
+expression E;
+position p;
+@@
+if@p (E) {}
+
+@script:python depends on report@
+p << r.p;
+@@
+
+msg = "WARNING: Unnecessary if with no body."
+coccilib.report.print_report(p[0], msg)
-- 
1.8.4.2


  parent reply	other threads:[~2013-11-02 15:15 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-11-02 14:32 [Cocci] [PATCH] coccinelle: Add a script to find and remove unnecessary ifs with no body Josh Triplett
2013-11-02 14:32 ` Josh Triplett
2013-11-02 14:51 ` [Cocci] " Julia Lawall
2013-11-02 14:51   ` Julia Lawall
2013-11-02 15:05   ` [Cocci] " Josh Triplett
2013-11-02 15:05     ` Josh Triplett
2013-11-02 15:09     ` [Cocci] " Julia Lawall
2013-11-02 15:09       ` Julia Lawall
2013-11-02 15:15   ` Josh Triplett [this message]
2013-11-02 15:15     ` [PATCHv2] coccinelle: Add a script to find " Josh Triplett
2013-11-02 16:49     ` [Cocci] " Julia Lawall
2013-11-02 16:49       ` Julia Lawall
2013-11-08 13:52       ` [Cocci] " Michal Marek
2013-11-08 13:52         ` Michal Marek

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=20131102151500.GW15704@leaf \
    --to=josh@joshtriplett.org \
    --cc=cocci@systeme.lip6.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.