Hi,

I noticed that coccinelle will that identifiers, which have the same name,
but live in different scopes, as the same identifier. For example two local
variables in two different functions with the same name will be seen as the
same identifier.

E.g. in this simple synthetic example

@r1@
identifier i;
@@
i = 1;

@r2@
identifier r1.i;
@@
-i = 2;
+i = 3;

void f1(void)
{
    int i;

    i = 1;
}

void f2(void)
{
    int i;

    i = 2;
}

it will match r1 on the i in f1, but will replace the assignment to i in f2,
although it is different i.

Is this a bug or a feature?

In this example I could work around it by e.g. doing something like:
@r1@
identifier i;
identifier fn;
@@
fn(...)
{
<+...
i = 1;
...+>
}

@@
identifier r1.i;
identifier r1.fn;
@@
fn(...)
{
<+...
-i = 2;
+i = 3;
...+>
}

But this would still leave the issue open for nested scopes inside a
function. And requires a extra set of rules to match identifiers outside of
functions.

Thanks,
- Lars
_______________________________________________
Cocci mailing list
[email protected]
http://lists.diku.dk/mailman/listinfo/cocci
(Web access from inside DIKUs LAN only)

Reply via email to