* [Cocci] [Coccinellery] drop_continue/cont.cocci broken ?
@ 2013-02-19 20:44 Cyril Roelandt
2013-02-19 21:54 ` Julia Lawall
2013-02-19 22:05 ` Julia Lawall
0 siblings, 2 replies; 3+ messages in thread
From: Cyril Roelandt @ 2013-02-19 20:44 UTC (permalink / raw)
To: cocci
Hi!
I think the drop_continue/cont.cocci script is broken. Here is a simple
semantic patch extracted from it:
$ cat foo.cocci
@@
statement S;
@@
for (...;...;...) {
...
if (...)
- {
S
- continue;
- }
}
A simple C file:
$ cat continue.c
static void
foo(int max)
{
int i;
for (i = 0; i < max; i++) {
do_stuff();
if (i == 42) {
do_stg_else();
continue;
}
}
}
$ spatch -sp_file foo.cocci continue.c --debug --verbose-parsing
init_defs_builtins: /home/cyril/opt/spatch/share/coccinelle/standard.h
-----------------------------------------------------------------------
processing semantic patch file: foo.cocci
with isos from: /home/cyril/opt/spatch/share/coccinelle/standard.iso
-----------------------------------------------------------------------
@@
statement S;
@@
for (...;...;...) {
...
if (...)
- {
S
- continue;
- }
}
warning: iso braces1 does not match the code below on line 4
{
...
if (...) {
S
continue;
}
}
braces must be all minus (plus code allowed) or all
context (plus code not allowed in the body) to match:
{
...
if (...) {
S
continue;
}
}
HANDLING: continue.c
-----------------------------------------------------------------------
let's go
-----------------------------------------------------------------------
-----------------------------------------------------------------------
-----------------------------------------------------------------------
rule starting on line 1 =
-----------------------------------------------------------------------
dependencies for rule rule starting on line 1 satisfied:
binding in = []
binding relevant in = []
transformation info returned:
transform state: 18
with rule_elem: -{
with binding: []
transform state: 20
with rule_elem: -continue-;
with binding: []
binding out = []
transform one node: 20
transform one node: 18
PB: found closing brace alone in fuzzy parsing
ERROR-RECOV: end of file while in recovery mode
parsing pass2: try again
ERROR-RECOV: end of file while in recovery mode
parse error
= File "/tmp/cocci_small_output-5101-1385aa.c", line 11, column 0,
charpos = 118
around = '}', whole content = }
badcount: 1
bad: }
BAD:!!!!! }
ALREADY AT END
-----------------------------------------------------------------------
Finished
-----------------------------------------------------------------------
PB: found closing brace alone in fuzzy parsing
ERROR-RECOV: end of file while in recovery mode
parsing pass2: try again
ERROR-RECOV: end of file while in recovery mode
parse error
= File "/tmp/cocci-output-5101-f0bc97-continue.c", line 11, column 0,
charpos = 118
around = '}', whole content = }
badcount: 1
bad: }
BAD:!!!!! }
ALREADY AT END
diff =
--- continue.c
+++ /tmp/cocci-output-5101-f0bc97-continue.c
@@ -4,9 +4,8 @@ foo(int max)
int i;
for (i = 0; i < max; i++) {
do_stuff();
- if (i == 42) {
+ if (i == 42)
do_stg_else();
- continue;
}
}
}
Check duplication for 1 files
There is a missing closing brace in the resulting code. I can reproduce
this with both 1.0-rc12 (packaged in Debian) and 1.0-rc16. The same
thing happens when using "*" instead of "-", and when using the "break"
keyword instead of the "continue" keyword.
WBR,
Cyril Roelandt.
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Cocci] [Coccinellery] drop_continue/cont.cocci broken ?
2013-02-19 20:44 [Cocci] [Coccinellery] drop_continue/cont.cocci broken ? Cyril Roelandt
@ 2013-02-19 21:54 ` Julia Lawall
2013-02-19 22:05 ` Julia Lawall
1 sibling, 0 replies; 3+ messages in thread
From: Julia Lawall @ 2013-02-19 21:54 UTC (permalink / raw)
To: cocci
My recollecton is indeed that this rule does not work properly. There is
no control flow from the continue to the following brace, so it doesn't
get removed.
I will change the rule so that it doesn't make any changes, just prints
out a warning message.
Thanks for the report.
julia
On Tue, 19 Feb 2013, Cyril Roelandt wrote:
> Hi!
>
> I think the drop_continue/cont.cocci script is broken. Here is a simple
> semantic patch extracted from it:
>
>
> $ cat foo.cocci
> @@
> statement S;
> @@
> for (...;...;...) {
> ...
> if (...)
> - {
> S
> - continue;
> - }
> }
>
>
> A simple C file:
>
> $ cat continue.c
> static void
> foo(int max)
> {
> int i;
> for (i = 0; i < max; i++) {
> do_stuff();
> if (i == 42) {
> do_stg_else();
> continue;
> }
> }
> }
>
> $ spatch -sp_file foo.cocci continue.c --debug --verbose-parsing
> init_defs_builtins: /home/cyril/opt/spatch/share/coccinelle/standard.h
> -----------------------------------------------------------------------
> processing semantic patch file: foo.cocci
> with isos from: /home/cyril/opt/spatch/share/coccinelle/standard.iso
> -----------------------------------------------------------------------
> @@
> statement S;
> @@
> for (...;...;...) {
> ...
> if (...)
> - {
> S
> - continue;
> - }
> }
>
> warning: iso braces1 does not match the code below on line 4
> {
> ...
> if (...) {
> S
> continue;
> }
> }
> braces must be all minus (plus code allowed) or all
> context (plus code not allowed in the body) to match:
> {
> ...
> if (...) {
> S
> continue;
> }
> }
> HANDLING: continue.c
> -----------------------------------------------------------------------
> let's go
> -----------------------------------------------------------------------
> -----------------------------------------------------------------------
> -----------------------------------------------------------------------
> rule starting on line 1 =
> -----------------------------------------------------------------------
> dependencies for rule rule starting on line 1 satisfied:
> binding in = []
> binding relevant in = []
> transformation info returned:
> transform state: 18
> with rule_elem: -{
>
> with binding: []
> transform state: 20
> with rule_elem: -continue-;
> with binding: []
> binding out = []
> transform one node: 20
> transform one node: 18
> PB: found closing brace alone in fuzzy parsing
> ERROR-RECOV: end of file while in recovery mode
> parsing pass2: try again
> ERROR-RECOV: end of file while in recovery mode
> parse error
> = File "/tmp/cocci_small_output-5101-1385aa.c", line 11, column 0, charpos =
> 118
> around = '}', whole content = }
> badcount: 1
> bad: }
> BAD:!!!!! }
> ALREADY AT END
> -----------------------------------------------------------------------
> Finished
> -----------------------------------------------------------------------
> PB: found closing brace alone in fuzzy parsing
> ERROR-RECOV: end of file while in recovery mode
> parsing pass2: try again
> ERROR-RECOV: end of file while in recovery mode
> parse error
> = File "/tmp/cocci-output-5101-f0bc97-continue.c", line 11, column 0,
> charpos = 118
> around = '}', whole content = }
> badcount: 1
> bad: }
> BAD:!!!!! }
> ALREADY AT END
> diff =
> --- continue.c
> +++ /tmp/cocci-output-5101-f0bc97-continue.c
> @@ -4,9 +4,8 @@ foo(int max)
> int i;
> for (i = 0; i < max; i++) {
> do_stuff();
> - if (i == 42) {
> + if (i == 42)
> do_stg_else();
> - continue;
> }
> }
> }
> Check duplication for 1 files
>
>
>
>
> There is a missing closing brace in the resulting code. I can reproduce this
> with both 1.0-rc12 (packaged in Debian) and 1.0-rc16. The same thing happens
> when using "*" instead of "-", and when using the "break" keyword instead of
> the "continue" keyword.
>
>
> WBR,
> Cyril Roelandt.
> _______________________________________________
> Cocci mailing list
> Cocci at systeme.lip6.fr
> https://systeme.lip6.fr/mailman/listinfo/cocci
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Cocci] [Coccinellery] drop_continue/cont.cocci broken ?
2013-02-19 20:44 [Cocci] [Coccinellery] drop_continue/cont.cocci broken ? Cyril Roelandt
2013-02-19 21:54 ` Julia Lawall
@ 2013-02-19 22:05 ` Julia Lawall
1 sibling, 0 replies; 3+ messages in thread
From: Julia Lawall @ 2013-02-19 22:05 UTC (permalink / raw)
To: cocci
Actually, I changed it as follows, for the for loop case:
@@
statement S;
@@
for (...;...;...) {
...
if (...)
{
+ DROP_ME();
S
- continue;
}
}
@@
statement S;
@@
if (...)
- {
- DROP_ME();
S
- }
I just hope that no one puts a call to DROP_ME at the top of an if...
It's not foolproof, but it does allow the rule to do the transformation.
julia
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2013-02-19 22:05 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-02-19 20:44 [Cocci] [Coccinellery] drop_continue/cont.cocci broken ? Cyril Roelandt
2013-02-19 21:54 ` Julia Lawall
2013-02-19 22:05 ` 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.