Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1329000 > unrolled thread
| Started by | Kris Borer <kborer@gmail.com> |
|---|---|
| First post | 2016-02-08 13:50 +0100 |
| Last post | 2016-02-09 10:20 +0100 |
| Articles | 3 — 3 participants |
Back to article view | Back to linux.kernel
[PATCH v2] coccinelle: add style check for assignment in if Kris Borer <kborer@gmail.com> - 2016-02-08 13:50 +0100
Re: [PATCH v2] coccinelle: add style check for assignment in if SF Markus Elfring <elfring@users.sourceforge.net> - 2016-02-09 09:30 +0100
Re: [PATCH v2] coccinelle: add style check for assignment in if Julia Lawall <julia.lawall@lip6.fr> - 2016-02-09 10:20 +0100
| From | Kris Borer <kborer@gmail.com> |
|---|---|
| Date | 2016-02-08 13:50 +0100 |
| Subject | [PATCH v2] coccinelle: add style check for assignment in if |
| Message-ID | <qZTqq-5fX-1@gated-at.bofh.it> |
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 | 128 ++++++++++++++++++++++++
1 file changed, 128 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..b23db8f
--- /dev/null
+++ b/scripts/coccinelle/style/assignment_in_if.cocci
@@ -0,0 +1,128 @@
+/// move assignments out of if conditions
+///
+//# This script is designed to correct code where assignments exist in if
+//# conditions. It is only capable of handling a subset of such problems.
+//# Ideally it would handle all checkpatch errors of the following type:
+//# ERROR: do not use assignment in if condition
+//#
+//# For example:
+//# if(result = myfun())
+//#
+//# would become:
+//# result = myfun();
+//# if(result)
+//
+// Confidence: Moderate
+// Copyright: (C) 2015 Kris Borer. GPLv2.
+// URL: http://coccinelle.lip6.fr/
+// Comments:
+// Options: --no-includes --include-headers
+
+virtual patch
+
+
+// if ( (ret = call()) )
+// if ( (ret = call()) < 0 )
+@if1@
+expression i;
+expression E, E2;
+statement S1, S2;
+binary operator b;
+@@
+
++ i = E;
+ if (
+(
+- (i = E)
++ i
+|
+- (i = E)
++ i
+ b ...
+|
+- (i = E),
+ E2
+)
+ ) S1 else S2
+
+
+// if ( ptr->fun && (ret = ptr->fun()) )
+@if2@
+expression i2;
+expression E1, E2;
+@@
+
++ if( E1 ) {
++ i2 = E2;
++ if (i2) {
+- if( E1 && (i2 = E2) ) {
+ ...
+- }
++ }
++ }
+
+
+// if ( ptr->fun && (ret = ptr->fun()) < 0 )
+@if3@
+expression i2;
+expression E1, E2;
+constant c;
+binary operator b;
+@@
+
++ if( E1 ) {
++ i2 = E2;
++ if (i2 b c) {
+- if( E1 && ((i2 = E2) b c) ) {
+ ...
+- }
++ }
++ }
+
+
+// if ( (ret = call()) && ret != -1 )
+// if ( (ret = call()) < 0 && ret != -1 )
+@if4@
+expression i;
+expression E, E2;
+statement S1, S2;
+binary operator b;
+@@
+
++ i = E;
+ if (
+(
+- (i = E)
++ i
+|
+ (
+- (i = E)
++ i
+ b
+ ...)
+)
+ && E2 ) S1 else S2
+
+
+// if ( (ret = call()) && ret != -1 && ret != -2 )
+// if ( (ret = call()) < 0 && ret != -1 && ret != -2 )
+@if5@
+expression i;
+expression E, E2, E3;
+statement S1, S2;
+binary operator b;
+@@
+
++ i = E;
+ if (
+(
+- (i = E)
++ i
+|
+ (
+- (i = E)
++ i
+ b
+ ...)
+)
+ && E2 && E3 ) S1 else S2
--
1.9.1
[toc] | [next] | [standalone]
| From | SF Markus Elfring <elfring@users.sourceforge.net> |
|---|---|
| Date | 2016-02-09 09:30 +0100 |
| Message-ID | <r0bQl-1sy-1@gated-at.bofh.it> |
| In reply to | #1329000 |
> +virtual patch How do you think about to use this variable in a subsequent SmPL rule? Would you like to consider also the reuse of SmPL variables like "org" and "report"? Regards, Markus
[toc] | [prev] | [next] | [standalone]
| From | Julia Lawall <julia.lawall@lip6.fr> |
|---|---|
| Date | 2016-02-09 10:20 +0100 |
| Message-ID | <r0cCJ-21t-7@gated-at.bofh.it> |
| In reply to | #1329959 |
On Tue, 9 Feb 2016, SF Markus Elfring wrote: > > +virtual patch > > How do you think about to use this variable in a subsequent > SmPL rule? > > Would you like to consider also the reuse of SmPL variables > like "org" and "report"? I think that there is no point for these things, because checkpatch already gives warnings about this issue. It could be nice for the provided rules to actually depend on patch. But in the context of make coccicheck, it doesn't matter, because attempts to run the rule in another mode will just fail, due to the mode not being declared. julia
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web