Skip to contentSkip to conversation

coccinelle: add initial control flow documentation and extend tests

RFC Superseded Luis R. Rodriguez 4 participants 12 messages May 18, 2016 – May 19, 2016

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover coccinelle: add initial control flow documentation and extend tests

This adds some initial control flow documentation, I wanted to add some basic control flow diagrams as well with self generated diagrams from Coccinelle however I had issues figuring out what to use with dot to make it fit within the margins. We can skip that, but I thought adding it would also help document support and example use case for that feature as well.

The tests/remove-code-in-branch1* was more collateral effort as I saw a removal of a statement from a branch that only had one statement left an empty brace. I hope we can discuss here what the expected outcome should be. I figured removing the empty code may be an optional optimization, however it was still unclear how to resolve this if that's desirable. Would it be up to Coccinelle or would that be an optional isomorphism ? I noticed no current isomorphisms seem to remove code like this so it was unclear what to do.

The following rule for instnace can deal with it.

@ remove_empty_branch @
expression E;
@@

-if (E) {}

Luis R. Rodriguez (3):
tests: add test to remove single statement from branch
tests: add basic series of tests for exists and forall
coccinelle: add control flow documentation

 docs/manual/Makefile               |   6 +-
 docs/manual/cocci_syntax.tex       | 249 +++++++++++++++++++++++++++++++++++++
 docs/manual/flow1.c                |  10 ++
 docs/manual/flow2.c                |  11 ++
 tests/exists1.c                    |  20 +++
 tests/exists1.cocci                |   9 ++
 tests/exists1.res                  |  21 ++++
 tests/exists2.c                    |  21 ++++
 tests/exists2.cocci                |  13 ++
 tests/exists2.res                  |  23 ++++
 tests/exists3.c                    |  21 ++++
 tests/exists3.cocci                |  12 ++
 tests/exists3.res                  |  23 ++++
 tests/exists4.c                    |  22 ++++
 tests/exists4.cocci                |  13 ++
 tests/exists4.res                  |  21 ++++
 tests/remove-code-in-branch1.c     |   7 ++
 tests/remove-code-in-branch1.cocci |   4 +
 tests/remove-code-in-branch1.res   |   4 +
 19 files changed, 509 insertions(+), 1 deletion(-)
 create mode 100644 docs/manual/flow1.c
 create mode 100644 docs/manual/flow2.c
 create mode 100644 tests/exists1.c
 create mode 100644 tests/exists1.cocci
 create mode 100644 tests/exists1.res
 create mode 100644 tests/exists2.c
 create mode 100644 tests/exists2.cocci
 create mode 100644 tests/exists2.res
 create mode 100644 tests/exists3.c
 create mode 100644 tests/exists3.cocci
 create mode 100644 tests/exists3.res
 create mode 100644 tests/exists4.c
 create mode 100644 tests/exists4.cocci
 create mode 100644 tests/exists4.res
 create mode 100644 tests/remove-code-in-branch1.c
 create mode 100644 tests/remove-code-in-branch1.cocci
 create mode 100644 tests/remove-code-in-branch1.res
Signature · 1 line
2.7.2
#1 lore raw

RFC 1/3 tests: add test to remove single statement from branch

At leaset with coccinelle 1.0.4 this test fails with two issues, one is the return statement is shifted, another is debatable -- an empty branch statement is left. This is funtional however its debatable if this is desirable by default.

---
 tests/remove-code-in-branch1.c     | 7 +++++++
 tests/remove-code-in-branch1.cocci | 4 ++++
 tests/remove-code-in-branch1.res   | 4 ++++
 3 files changed, 15 insertions(+)
 create mode 100644 tests/remove-code-in-branch1.c
 create mode 100644 tests/remove-code-in-branch1.cocci
 create mode 100644 tests/remove-code-in-branch1.res
tests/remove-code-in-branch1.c new file +7 -0
new file mode 100644
index 000000000000..83840bdd99ac
@@ -0,0 +1,7 @@
+int main(void)
+{
+	if (a > 1)
+		c();
+
+	return 0;
+}
tests/remove-code-in-branch1.cocci new file +4 -0
new file mode 100644
index 000000000000..b3f03523ac92
@@ -0,0 +1,4 @@
+ at r@
+@@
+
+-c();
tests/remove-code-in-branch1.res new file +4 -0
new file mode 100644
index 000000000000..31dbf45bf99c
@@ -0,0 +1,4 @@
+int main(void)
+{
+	return 0;
+}
Signature · 1 line
2.7.2
#2 lore raw

RFC 1/3 tests: add test to remove single statement from branch

Quoted 5 lines · Luis R. Rodriguez

At leaset with coccinelle 1.0.4 this test fails with two issues, one is the return statement is shifted, another is debatable -- an empty branch statement is left. This is funtional however its debatable if this is desirable by default.

The return statement should not move, but the if should not be removed either. Please send a second version.

Note the type mentioned by Markus as well (leaset, funtional)

thanks,
julia

Quoted 52 lines
---
 tests/remove-code-in-branch1.c     | 7 +++++++
 tests/remove-code-in-branch1.cocci | 4 ++++
 tests/remove-code-in-branch1.res   | 4 ++++
 3 files changed, 15 insertions(+)
 create mode 100644 tests/remove-code-in-branch1.c
 create mode 100644 tests/remove-code-in-branch1.cocci
 create mode 100644 tests/remove-code-in-branch1.res
tests/remove-code-in-branch1.c new file +7 -0
new file mode 100644
index 000000000000..83840bdd99ac
@@ -0,0 +1,7 @@
+int main(void)
+{
+	if (a > 1)
+		c();
+
+	return 0;
+}
tests/remove-code-in-branch1.cocci new file +4 -0
new file mode 100644
index 000000000000..b3f03523ac92
@@ -0,0 +1,4 @@
+ at r@
+@@
+
+-c();
tests/remove-code-in-branch1.res new file +4 -1
new file mode 100644
index 000000000000..31dbf45bf99c
@@ -0,0 +1,4 @@
+int main(void)
+{
+	return 0;
+}
--

2.7.2

_______________________________________________
Cocci mailing list
Cocci at systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci

#3 lore raw

RFC 1/3 tests: add test to remove single statement from branch

Quoted 9 lines · Julia Lawall
Quoted 5 lines · Luis R. Rodriguez

At leaset with coccinelle 1.0.4 this test fails with two issues, one is the return statement is shifted, another is debatable -- an empty branch statement is left. This is funtional however its debatable if this is desirable by default.

The return statement should not move,

Great!

Quoted 1 line

but the if should not be removed either.

Agreed now..

Quoted 1 line

Please send a second version.

Will do!

Quoted 1 line

Note the type mentioned by Markus as well (leaset, funtional)

Sure thing.

Luis

#4 lore raw

RFC 2/3 tests: add basic series of tests for exists and forall

In reply to Luis R. Rodriguez

This should not only help test but also demo use of exists and forall.

---
 tests/exists1.c     | 20 ++++++++++++++++++++
 tests/exists1.cocci |  9 +++++++++
 tests/exists1.res   | 21 +++++++++++++++++++++
 tests/exists2.c     | 21 +++++++++++++++++++++
 tests/exists2.cocci | 13 +++++++++++++
 tests/exists2.res   | 23 +++++++++++++++++++++++
 tests/exists3.c     | 21 +++++++++++++++++++++
 tests/exists3.cocci | 12 ++++++++++++
 tests/exists3.res   | 23 +++++++++++++++++++++++
 tests/exists4.c     | 22 ++++++++++++++++++++++
 tests/exists4.cocci | 13 +++++++++++++
 tests/exists4.res   | 21 +++++++++++++++++++++
 12 files changed, 219 insertions(+)
 create mode 100644 tests/exists1.c
 create mode 100644 tests/exists1.cocci
 create mode 100644 tests/exists1.res
 create mode 100644 tests/exists2.c
 create mode 100644 tests/exists2.cocci
 create mode 100644 tests/exists2.res
 create mode 100644 tests/exists3.c
 create mode 100644 tests/exists3.cocci
 create mode 100644 tests/exists3.res
 create mode 100644 tests/exists4.c
 create mode 100644 tests/exists4.cocci
 create mode 100644 tests/exists4.res
tests/exists1.c new file +20 -0
new file mode 100644
index 000000000000..5cc37415bfef
@@ -0,0 +1,20 @@
+void bar(void)
+{
+	int a;
+
+	a = 300;
+	b();
+}
+
+int main(void)
+{
+	int a;
+
+	a = 10;
+	b();
+
+	c = 400;
+	c();
+
+	return 0;
+}
tests/exists1.cocci new file +9 -0
new file mode 100644
index 000000000000..af95363de18f
@@ -0,0 +1,9 @@
+// this rule lacks exists, without exists, all control flows possible
+// must match the rule when + or - is used. In the case of exists1.c only
+// one possible control flow exists, the flow is completely linear.
+ at r@
+@@
+
+b();
+...
+-c();
tests/exists1.res new file +21 -0
new file mode 100644
index 000000000000..cd83e4b2b6b1
@@ -0,0 +1,21 @@
+#include <stdio.h>
+
+int bar(void)
+{
+	int a;
+
+	a = 300;
+	b();
+}
+
+int main(void)
+{
+	int a;
+
+	a = 10;
+	b();
+
+	c = 400;
+
+	return 0;
+}
tests/exists2.c new file +21 -0
new file mode 100644
index 000000000000..486a8f5633d9
@@ -0,0 +1,21 @@
+void bar(void)
+{
+	int a;
+
+	a = 300;
+	b();
+}
+
+int main(void)
+{
+	int a;
+
+	a = 10;
+	b();
+
+	c = 400;
+	if (a > 5)
+		c();
+
+	return 0;
+}
tests/exists2.cocci new file +13 -0
new file mode 100644
index 000000000000..576b3cd3af24
@@ -0,0 +1,13 @@
+// this rule lacks exists, without exists, all control flows possible
+// must match the rule. In the case of exists2.c two possible control
+// flows exists on main():
+// 1. b() --> a > 5 --> c();
+// 2. b() --> a <= 5 ---> no c();
+// Not all control flows match, so no changes are made.
+// To visualize the control graph use: spatch --control-flow exists2.c
+ at r@
+@@
+
+b();
+...
+-c();
tests/exists2.res new file +23 -0
new file mode 100644
index 000000000000..9d6401eb7d05
@@ -0,0 +1,23 @@
+#include <stdio.h>
+
+int bar(void)
+{
+	int a;
+
+	a = 300;
+	b();
+}
+
+int main(void)
+{
+	int a;
+
+	a = 10;
+	b();
+
+	c = 400;
+	if (a > 5)
+		c();
+
+	return 0;
+}
tests/exists3.c new file +21 -0
new file mode 100644
index 000000000000..486a8f5633d9
@@ -0,0 +1,21 @@
+void bar(void)
+{
+	int a;
+
+	a = 300;
+	b();
+}
+
+int main(void)
+{
+	int a;
+
+	a = 10;
+	b();
+
+	c = 400;
+	if (a > 5)
+		c();
+
+	return 0;
+}
tests/exists3.cocci new file +12 -0
new file mode 100644
index 000000000000..64cb43aa8ec4
@@ -0,0 +1,12 @@
+// this rule uses exists, with it, the rule is successful if at least
+// one of the possible control flows possible match.
+// exists3.c has two possible control flows on main():
+// 1. b() --> a > 5 --> c();
+// 2. b() --> a <= 5 ---> no c();
+// The match on 1. enables the changes to take place.
+ at r exists @
+@@
+
+b();
+...
+-c();
tests/exists3.res new file +23 -0
new file mode 100644
index 000000000000..f6b53c361fa5
@@ -0,0 +1,23 @@
+#include <stdio.h>
+
+int bar(void)
+{
+	int a;
+
+	a = 300;
+	b();
+}
+
+int main(void)
+{
+	int a;
+
+	a = 10;
+	b();
+
+	c = 400;
+	if (a > 5)
+		{}
+
+	return 0;
+}
tests/exists4.c new file +22 -0
new file mode 100644
index 000000000000..0b3dab08e6e1
@@ -0,0 +1,22 @@
+void bar(void)
+{
+	int a;
+
+	a = 300;
+	b();
+	c();
+}
+
+int main(void)
+{
+	int a;
+
+	a = 10;
+	b();
+
+	c = 400;
+	if (a > 5)
+		c();
+
+	return 0;
+}
tests/exists4.cocci new file +13 -0
new file mode 100644
index 000000000000..d80c71a9d3f3
@@ -0,0 +1,13 @@
+// this rule uses forall, with it, all control flows must match.
+//
+// The exists4.c was extended to add a c() in comparison to exists2.c
+// this is done to show that using forall will still have an effect
+// on bar() even though it does not match on main()
+//
+// This is the default behaviour when + or - is used as well.
+ at r forall@
+@@
+
+b();
+...
+-c();
tests/exists4.res new file +21 -0
new file mode 100644
index 000000000000..486a8f5633d9
@@ -0,0 +1,21 @@
+void bar(void)
+{
+	int a;
+
+	a = 300;
+	b();
+}
+
+int main(void)
+{
+	int a;
+
+	a = 10;
+	b();
+
+	c = 400;
+	if (a > 5)
+		c();
+
+	return 0;
+}
Signature · 1 line
2.7.2
#5 lore raw

RFC 2/3 tests: add basic series of tests for exists and forall

Quoted 2 lines · Luis R. Rodriguez

This should not only help test but also demo use of exists and forall.

Thanks for the examples. But should it go in tests or in demos? Demos could be better if the main purpose is to help the user understand exists and forall.

julia

Quoted 328 lines
---
 tests/exists1.c     | 20 ++++++++++++++++++++
 tests/exists1.cocci |  9 +++++++++
 tests/exists1.res   | 21 +++++++++++++++++++++
 tests/exists2.c     | 21 +++++++++++++++++++++
 tests/exists2.cocci | 13 +++++++++++++
 tests/exists2.res   | 23 +++++++++++++++++++++++
 tests/exists3.c     | 21 +++++++++++++++++++++
 tests/exists3.cocci | 12 ++++++++++++
 tests/exists3.res   | 23 +++++++++++++++++++++++
 tests/exists4.c     | 22 ++++++++++++++++++++++
 tests/exists4.cocci | 13 +++++++++++++
 tests/exists4.res   | 21 +++++++++++++++++++++
 12 files changed, 219 insertions(+)
 create mode 100644 tests/exists1.c
 create mode 100644 tests/exists1.cocci
 create mode 100644 tests/exists1.res
 create mode 100644 tests/exists2.c
 create mode 100644 tests/exists2.cocci
 create mode 100644 tests/exists2.res
 create mode 100644 tests/exists3.c
 create mode 100644 tests/exists3.cocci
 create mode 100644 tests/exists3.res
 create mode 100644 tests/exists4.c
 create mode 100644 tests/exists4.cocci
 create mode 100644 tests/exists4.res
tests/exists1.c new file +20 -0
new file mode 100644
index 000000000000..5cc37415bfef
@@ -0,0 +1,20 @@
+void bar(void)
+{
+	int a;
+
+	a = 300;
+	b();
+}
+
+int main(void)
+{
+	int a;
+
+	a = 10;
+	b();
+
+	c = 400;
+	c();
+
+	return 0;
+}
tests/exists1.cocci new file +9 -0
new file mode 100644
index 000000000000..af95363de18f
@@ -0,0 +1,9 @@
+// this rule lacks exists, without exists, all control flows possible
+// must match the rule when + or - is used. In the case of exists1.c only
+// one possible control flow exists, the flow is completely linear.
+ at r@
+@@
+
+b();
+...
+-c();
tests/exists1.res new file +21 -0
new file mode 100644
index 000000000000..cd83e4b2b6b1
@@ -0,0 +1,21 @@
+#include <stdio.h>
+
+int bar(void)
+{
+	int a;
+
+	a = 300;
+	b();
+}
+
+int main(void)
+{
+	int a;
+
+	a = 10;
+	b();
+
+	c = 400;
+
+	return 0;
+}
tests/exists2.c new file +21 -0
new file mode 100644
index 000000000000..486a8f5633d9
@@ -0,0 +1,21 @@
+void bar(void)
+{
+	int a;
+
+	a = 300;
+	b();
+}
+
+int main(void)
+{
+	int a;
+
+	a = 10;
+	b();
+
+	c = 400;
+	if (a > 5)
+		c();
+
+	return 0;
+}
tests/exists2.cocci new file +13 -0
new file mode 100644
index 000000000000..576b3cd3af24
@@ -0,0 +1,13 @@
+// this rule lacks exists, without exists, all control flows possible
+// must match the rule. In the case of exists2.c two possible control
+// flows exists on main():
+// 1. b() --> a > 5 --> c();
+// 2. b() --> a <= 5 ---> no c();
+// Not all control flows match, so no changes are made.
+// To visualize the control graph use: spatch --control-flow exists2.c
+ at r@
+@@
+
+b();
+...
+-c();
tests/exists2.res new file +23 -0
new file mode 100644
index 000000000000..9d6401eb7d05
@@ -0,0 +1,23 @@
+#include <stdio.h>
+
+int bar(void)
+{
+	int a;
+
+	a = 300;
+	b();
+}
+
+int main(void)
+{
+	int a;
+
+	a = 10;
+	b();
+
+	c = 400;
+	if (a > 5)
+		c();
+
+	return 0;
+}
tests/exists3.c new file +21 -0
new file mode 100644
index 000000000000..486a8f5633d9
@@ -0,0 +1,21 @@
+void bar(void)
+{
+	int a;
+
+	a = 300;
+	b();
+}
+
+int main(void)
+{
+	int a;
+
+	a = 10;
+	b();
+
+	c = 400;
+	if (a > 5)
+		c();
+
+	return 0;
+}
tests/exists3.cocci new file +12 -0
new file mode 100644
index 000000000000..64cb43aa8ec4
@@ -0,0 +1,12 @@
+// this rule uses exists, with it, the rule is successful if at least
+// one of the possible control flows possible match.
+// exists3.c has two possible control flows on main():
+// 1. b() --> a > 5 --> c();
+// 2. b() --> a <= 5 ---> no c();
+// The match on 1. enables the changes to take place.
+ at r exists @
+@@
+
+b();
+...
+-c();
tests/exists3.res new file +23 -0
new file mode 100644
index 000000000000..f6b53c361fa5
@@ -0,0 +1,23 @@
+#include <stdio.h>
+
+int bar(void)
+{
+	int a;
+
+	a = 300;
+	b();
+}
+
+int main(void)
+{
+	int a;
+
+	a = 10;
+	b();
+
+	c = 400;
+	if (a > 5)
+		{}
+
+	return 0;
+}
tests/exists4.c new file +22 -0
new file mode 100644
index 000000000000..0b3dab08e6e1
@@ -0,0 +1,22 @@
+void bar(void)
+{
+	int a;
+
+	a = 300;
+	b();
+	c();
+}
+
+int main(void)
+{
+	int a;
+
+	a = 10;
+	b();
+
+	c = 400;
+	if (a > 5)
+		c();
+
+	return 0;
+}
tests/exists4.cocci new file +13 -0
new file mode 100644
index 000000000000..d80c71a9d3f3
@@ -0,0 +1,13 @@
+// this rule uses forall, with it, all control flows must match.
+//
+// The exists4.c was extended to add a c() in comparison to exists2.c
+// this is done to show that using forall will still have an effect
+// on bar() even though it does not match on main()
+//
+// This is the default behaviour when + or - is used as well.
+ at r forall@
+@@
+
+b();
+...
+-c();
tests/exists4.res new file +21 -1
new file mode 100644
index 000000000000..486a8f5633d9
@@ -0,0 +1,21 @@
+void bar(void)
+{
+	int a;
+
+	a = 300;
+	b();
+}
+
+int main(void)
+{
+	int a;
+
+	a = 10;
+	b();
+
+	c = 400;
+	if (a > 5)
+		c();
+
+	return 0;
+}
--

2.7.2

_______________________________________________
Cocci mailing list
Cocci at systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci

#6 lore raw

RFC 2/3 tests: add basic series of tests for exists and forall

Quoted 8 lines · Julia Lawall
Quoted 2 lines · Luis R. Rodriguez

This should not only help test but also demo use of exists and forall.

Thanks for the examples. But should it go in tests or in demos? Demos could be better if the main purpose is to help the user understand exists and forall.

Sure thing, will move!

Luis

#7 lore raw

RFC 3/3 coccinelle: add control flow documentation

In reply to Luis R. Rodriguez

From: "Luis R. Rodriguez" <[email protected]>

Add control flow documentation.

---
 docs/manual/Makefile         |   6 +-
 docs/manual/cocci_syntax.tex | 249 +++++++++++++++++++++++++++++++++++++++++++
 docs/manual/flow1.c          |  10 ++
 docs/manual/flow2.c          |  11 ++
 4 files changed, 275 insertions(+), 1 deletion(-)
 create mode 100644 docs/manual/flow1.c
 create mode 100644 docs/manual/flow2.c
docs/manual/Makefile +5 -1
index 98e397ac5b69..c0a28bd9bd4b 100644
@@ -36,7 +36,11 @@ manual.pdf: $(SRC)
 	$(PDFLATEX_CMD) manual.tex
 	$(PDFLATEX_CMD) manual.tex
 
-main_grammar.pdf: main_grammar.tex cocci_syntax.tex  macros_listing_cocci.tex macros_grammar.tex macros_common.tex examples.tex tips.tex
+main_grammar.pdf: main_grammar.tex cocci_syntax.tex flow1.c macros_listing_cocci.tex macros_grammar.tex macros_common.tex examples.tex tips.tex
+	#spatch --control-flow-to-file flow1.c
+	#spatch --control-flow-to-file flow2.c
+	#dot -Gsize="0.5,0.5" -Tpdf flow1:main.dot > flow1.pdf
+	#dot -Gsize="0.5,0.5" -Tpdf flow1:main.dot > flow2.pdf
 	$(PDFLATEX_CMD) main_grammar.tex
 	$(PDFLATEX_CMD) main_grammar.tex
 
docs/manual/cocci_syntax.tex +249 -0

255 lines not on this page · raw message

docs/manual/flow1.c new file +10 -0
new file mode 100644
index 000000000000..43e45ed32843
@@ -0,0 +1,10 @@
+int main(void)
+{
+	int ret, a = 2;
+
+	a = foo(a);
+	ret = bar(a);
+	c();
+
+	return ret;
+}
docs/manual/flow2.c new file +11 -0
new file mode 100644
index 000000000000..bb0d95e4c310
@@ -0,0 +1,11 @@
+int main(void)
+{
+	int ret, a = 2;
+
+	a = foo(a);
+	ret = bar(a);
+	if (a)
+		c();
+
+	return ret;
+}
Signature · 1 line
2.7.2
#8 lore raw

RFC 3/3 coccinelle: add control flow documentation

Quoted 1 line

+this rule by providing additional requirements and usign ellipses in between.

Will the wording "using" be better here?

Quoted 1 line

+or that the statements in between must be present at leaset once (<+... ...+).

Please fix another typo: least.

How do you think about to add any references (or links) for this functionality?

Regards,
Markus

#9 lore raw

RFC 3/3 coccinelle: add control flow documentation

Quoted 3 lines · SF Markus Elfring
Quoted 1 line

+this rule by providing additional requirements and usign ellipses in between.

Will the wording "using" be better here?

Fixed.

Quoted 3 lines
Quoted 1 line

+or that the statements in between must be present at leaset once (<+... ...+).

Please fix another typo: least.

Fixed.

Quoted 1 line

How do you think about to add any references (or links) for this functionality?

Please feel free to follow up with patches, preferably examples.

Luis

#10 lore raw

cover coccinelle: add initial control flow documentation and extend tests

In reply to Luis R. Rodriguez
Quoted 16 lines · Luis R. Rodriguez

This adds some initial control flow documentation, I wanted to add some basic control flow diagrams as well with self generated diagrams from Coccinelle however I had issues figuring out what to use with dot to make it fit within the margins. We can skip that, but I thought adding it would also help document support and example use case for that feature as well.

The tests/remove-code-in-branch1* was more collateral effort as I saw a removal of a statement from a branch that only had one statement left an empty brace. I hope we can discuss here what the expected outcome should be. I figured removing the empty code may be an optional optimization, however it was still unclear how to resolve this if that's desirable. Would it be up to Coccinelle or would that be an optional isomorphism ? I noticed no current isomorphisms seem to remove code like this so it was unclear what to do.

Quoted 7 lines

The following rule for instnace can deal with it.

@ remove_empty_branch @
expression E;
@@

-if (E) {}

I don't think this is desirable as a general rule. E might contain function calls that perform side effects.

julia

Quoted 52 lines

Luis R. Rodriguez (3):
tests: add test to remove single statement from branch
tests: add basic series of tests for exists and forall
coccinelle: add control flow documentation

 docs/manual/Makefile               |   6 +-
 docs/manual/cocci_syntax.tex       | 249 +++++++++++++++++++++++++++++++++++++
 docs/manual/flow1.c                |  10 ++
 docs/manual/flow2.c                |  11 ++
 tests/exists1.c                    |  20 +++
 tests/exists1.cocci                |   9 ++
 tests/exists1.res                  |  21 ++++
 tests/exists2.c                    |  21 ++++
 tests/exists2.cocci                |  13 ++
 tests/exists2.res                  |  23 ++++
 tests/exists3.c                    |  21 ++++
 tests/exists3.cocci                |  12 ++
 tests/exists3.res                  |  23 ++++
 tests/exists4.c                    |  22 ++++
 tests/exists4.cocci                |  13 ++
 tests/exists4.res                  |  21 ++++
 tests/remove-code-in-branch1.c     |   7 ++
 tests/remove-code-in-branch1.cocci |   4 +
 tests/remove-code-in-branch1.res   |   4 +
 19 files changed, 509 insertions(+), 1 deletion(-)
 create mode 100644 docs/manual/flow1.c
 create mode 100644 docs/manual/flow2.c
 create mode 100644 tests/exists1.c
 create mode 100644 tests/exists1.cocci
 create mode 100644 tests/exists1.res
 create mode 100644 tests/exists2.c
 create mode 100644 tests/exists2.cocci
 create mode 100644 tests/exists2.res
 create mode 100644 tests/exists3.c
 create mode 100644 tests/exists3.cocci
 create mode 100644 tests/exists3.res
 create mode 100644 tests/exists4.c
 create mode 100644 tests/exists4.cocci
 create mode 100644 tests/exists4.res
 create mode 100644 tests/remove-code-in-branch1.c
 create mode 100644 tests/remove-code-in-branch1.cocci
 create mode 100644 tests/remove-code-in-branch1.res

--
2.7.2

_______________________________________________
Cocci mailing list
Cocci at systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci

#11 lore raw

cover coccinelle: add initial control flow documentation and extend tests

Quoted 22 lines · Julia Lawall
Quoted 18 lines · Luis R. Rodriguez

This adds some initial control flow documentation, I wanted to add some basic control flow diagrams as well with self generated diagrams from Coccinelle however I had issues figuring out what to use with dot to make it fit within the margins. We can skip that, but I thought adding it would also help document support and example use case for that feature as well.

The tests/remove-code-in-branch1* was more collateral effort as I saw a removal of a statement from a branch that only had one statement left an empty brace. I hope we can discuss here what the expected outcome should be. I figured removing the empty code may be an optional optimization, however it was still unclear how to resolve this if that's desirable. Would it be up to Coccinelle or would that be an optional isomorphism ? I noticed no current isomorphisms seem to remove code like this so it was unclear what to do.

The following rule for instnace can deal with it.

Quoted 8 lines
Quoted 5 lines

@ remove_empty_branch @
expression E;
@@

-if (E) {}

I don't think this is desirable as a general rule. E might contain function calls that perform side effects.

Ah, yes good point.

Luis