[Cocci] Coccinelle errors during parsing of C-macros

Julia Lawall julia at diku.dk
Wed Apr 29 07:23:00 CEST 2009


>     ***Regarding q3***, here is the simple example:
>  c file:
>  int main(){
>      int a, b;
>      long c = a + b;
>      return 0;
>  }
>  cocci file:
>  @test@
>  int E1, E2;
>  long E3;
>  @@
>  -  E3 = E1 + E2;
>  + E3 = E1 - E2;

The problem is that Coccinelle does not make any analysis aboutthe 
relationship between the old and new code.  So it does not know that in 
this case the only difference between them is the operator on the 
right-hand side expression.  If the semantic patch were, for example:

  @test@
  int E1, E2;
  long E3;
  @@
  -  E3 = E1 + E2;
  + foo();

then it would not be possible to apply this semantic patch, because what 
would one do with the "int" type?

If you instead write your semantic patch as follows:

  @test@
  int E1, E2;
  long E3;
  @@
  E3 =
  -  E1 + E2
  +  E1 - E2

that is, with an assignment expression, and not a statement, and with the 
E3 untouched, then everything is fine.  Internally, it considers that the 
expression E3 might also be an identifier that is being declared with int 
type.

Is this an acceptable solution with respect to what you want to do?

julia


More information about the Cocci mailing list