[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <c45c4435-581b-d137-255c-c21db7ccef78@web.de>
Date: Tue, 1 Oct 2019 16:30:53 +0200
From: Markus Elfring <Markus.Elfring@....de>
To: Julia Lawall <julia.lawall@...6.fr>,
Coccinelle <cocci@...teme.lip6.fr>,
kernel-janitors@...r.kernel.org,
Gilles Muller <Gilles.Muller@...6.fr>,
Masahiro Yamada <yamada.masahiro@...ionext.com>,
Michal Marek <michal.lkml@...kovi.net>,
Nicolas Palix <nicolas.palix@...g.fr>
Cc: LKML <linux-kernel@...r.kernel.org>,
Allison Randal <allison@...utok.net>,
Enrico Weigelt <lkml@...ux.net>,
Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
Kate Stewart <kstewart@...uxfoundation.org>
Subject: [PATCH v2] Coccinelle: Add a SmPL script for the reconsideration of
specific combinations of assignment and return statements
From: Markus Elfring <elfring@...rs.sourceforge.net>
Date: Tue, 1 Oct 2019 15:50:10 +0200
Values from expressions were occasionally assigned to local variables
before they will be returned by the subsequent statement.
Such expressions can be directly specified in the return statement instead.
Adjust affected source code by the means of the semantic patch language
(Coccinelle software).
Signed-off-by: Markus Elfring <elfring@...rs.sourceforge.net>
---
v2:
* Application of the SmPL construct “<+... … ...+>”
* Addition of a hint for the supported coccicheck operation modes
.../coccinelle/misc/move_code_to_return.cocci | 73 +++++++++++++++++++
1 file changed, 73 insertions(+)
create mode 100644 scripts/coccinelle/misc/move_code_to_return.cocci
diff --git a/scripts/coccinelle/misc/move_code_to_return.cocci b/scripts/coccinelle/misc/move_code_to_return.cocci
new file mode 100644
index 000000000000..22ce7c9d0fd2
--- /dev/null
+++ b/scripts/coccinelle/misc/move_code_to_return.cocci
@@ -0,0 +1,73 @@
+// SPDX-License-Identifier: GPL-2.0
+/// Return expressions directly instead of assigning them to
+/// local variables immediately before affected statements.
+//
+// Keywords: return statements variable assignments coding style
+// Confidence: Medium
+
+virtual patch
+virtual report
+
+@...lacement1 depends on patch@
+expression x;
+identifier f, rc;
+local idexpression lrc;
+type rt;
+@@
+ rt f(...)
+ {
+ <+...
+ if (...)
+-{
+-lrc@rc = x;
+ return
+- rc
++ x
+ ;
+-}
+ ...+>
+ }
+
+@...lacement2 depends on patch@
+expression x;
+identifier f, rc;
+local idexpression lrc;
+type rt;
+@@
+ rt f(...)
+ {
+ <+...
+-lrc@rc = x;
+ return
+- rc
++ x
+ ;
+ ...+>
+ }
+
+@...etion2 depends on patch@
+identifier replacement2.f, replacement2.rc;
+type replacement2.rt, t;
+@@
+ rt f(...)
+ {
+ ... when any
+-t rc;
+ ... when != rc
+ }
+
+@...etion1 depends on patch@
+identifier replacement1.f, replacement1.rc;
+type replacement1.rt, t;
+@@
+ rt f(...)
+ {
+ ... when any
+-t rc;
+ ... when != rc
+ }
+
+@...ipt:python info depends on report@
+@@
+import sys
+sys.stderr.write("INFO: Unfortunately, specific software limitations have got the consequence that only the operation mode “patch” can be supported by this SmPL script so far as expected.\n")
--
2.23.0
Powered by blists - more mailing lists