Julia Lawall <[email protected]> writes:

> On Sat, 10 Feb 2018, Robert Larice wrote:
>
>> Julia Lawall <[email protected]> writes:
>>
>> > On Sat, 10 Feb 2018, Robert Larice wrote:
>> >
>> >> Dear People,
>> >>
>> >>   I'm completely new here.
>> >>
>> >>   Attached is a small piece of .c and a .cocci file.
>> >>   There is a "return 41;" in both files, commented out.
>> >>   If I uncomment this "return 41;" in both files then
>> >>     spatch will not match the pieces any more.
>> >>
>> >>   Could you please help me to undertand and circumvent this issue ?
>> >
>> > I have not noticed this problem before, but I suspect that it is due to
>> > the fact that Coccinelle is matching the control-flow path and not the
>> > abstract syntax tree. In a control-flow graph, nothing follows a return.
>> >
>> > julia
>>
>> Thank You,
>> I tried to sneak around the problem with a second "rule" which
>>   translates "return 42" to "auxiliary(42)".
>> My intention was to first change the source in such a way
>>   that the "control-flow" graph does not end at the "return",
>> and then hope that the second (accordingly modified) rule would
>>   match.
>> This didn't work, I assume I would have to express the idea of
>>   first applying the first rule
>>     then to rebuild the control-flow graph
>>   then try the second rule.
>>   (and finally undo the changes of the first rule in a third rule)
>> I can not force "rebuild" without invoking spatch myself a second time.
>
> If you change all the returns to something else and then match your
> pattern, and then change them it should work.
>
>>
>> ---
>> I'm a bit of a maintainer for the "ngspice" project, which has a vast
>>   amount of very old files, and lots of semi duplicated stuff often crying
>>   for a thourough hair wash,
>> stumbled over this intresting tool, and am tying it for a certain
>>   rewrite I'm currently busy with.
>
> OK,feel free to ask more questions if you run into further issues.
>
> julia

Hello,

  Thank you for your help. I've four or five .cocci files now which
    do the job at hand for ngspice quite well. The rewrite of return
    to something else with two times invocation of spatch did work.
  Then I found another simpler way. So thats done.

  Playing around, trying to better understand what it means
    to have more than one rule, their interaction etc ..
    I came to the attached example.
  Here I have basically tried to remove the whole body of a function
    iff the function matches two other @rules@
  It seems to work if I use the '*' notation, but doesnt if I use
    '+/-'
  Can you give me a hint which helps me to understand this ?

Regards,
  Robert

// (compile "spatch --sp-file ex4.cocci ex4.c")

@r1@
identifier a, foo, Label;
position p1a;
@@
void foo@p1a (int a)
{
  a++;
  if (a)
      goto Label;
  return 1;
  ...
}

@r2@
identifier a, foo, Label;
position p1b;
@@
void foo@p1b (int a)
{
    ...
 Label:
    return 2;
}

@r3@
identifier foo;
position r1.p1a;
position r2.p1b;
@@
void foo@p1a@p1b (...)
{
// this works thy way I'd expect
// * ...
// this doesn't work the way I'd expect
- ...
+ return 42;
}
void foo(int a) {
    a++;
    if (a)
        goto Label;
    return 1;
 Label:
    return 2;
}


void foo2(int a) {
    a++;
 Label:
    return 2;
}
_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci

Reply via email to