[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20131102151500.GW15704@leaf>
Date: Sat, 2 Nov 2013 08:15:01 -0700
From: Josh Triplett <josh@...htriplett.org>
To: Julia Lawall <julia.lawall@...6.fr>
Cc: Gilles Muller <Gilles.Muller@...6.fr>,
Nicolas Palix <nicolas.palix@...g.fr>,
Michal Marek <mmarek@...e.cz>, linux-kernel@...r.kernel.org,
cocci@...teme.lip6.fr
Subject: [PATCHv2] coccinelle: Add a script to find unnecessary ifs with no
body
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@...htriplett.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) {}
+
+@...ipt: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
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists