All of lore.kernel.org
 help / color / mirror / Atom feed
* [Cocci] [RFC] coccinelle: add style check for assignment in if
@ 2015-08-12 13:51 ` Kris Borer
  0 siblings, 0 replies; 12+ messages in thread
From: Kris Borer @ 2015-08-12 13:51 UTC (permalink / raw)
  To: cocci

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() )
+ at 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 )
+ at 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

^ permalink raw reply related	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2015-08-12 15:16 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-08-12 13:51 [Cocci] [RFC] coccinelle: add style check for assignment in if Kris Borer
2015-08-12 13:51 ` Kris Borer
2015-08-12 14:00 ` [Cocci] " Julia Lawall
2015-08-12 14:00   ` Julia Lawall
2015-08-12 14:49   ` [Cocci] " Kris Borer
2015-08-12 14:12 ` Michal Marek
2015-08-12 14:12   ` Michal Marek
2015-08-12 14:53   ` [Cocci] " Kris Borer
2015-08-12 15:05     ` Michal Marek
2015-08-12 15:05       ` Michal Marek
2015-08-12 15:16       ` [Cocci] " Julia Lawall
2015-08-12 15:16         ` Julia Lawall

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.