Discussion:
[Cocci] warning: line 202: should __func__ be a metavariable?
Timur Tabi
2018-12-04 22:56:41 UTC
Permalink
I have some rules and Python code that removes __FUNCTION__ as a
parameter in a call to a function. That all works great. I now want
it to remove __func__ in exactly the same way. So I copy/pasted my
rules and just changed __FUNCTION__ to __func__, but spatch complains:

warning: line 202: should __func__ be a metavariable?
warning: line 218: should __func__ be a metavariable?
warning: line 229: should __func__ be a metavariable?

I don't even know what this means. Here is one rule that fails:

// Look for NV_PRINTF2 calls that have __func__ as the first parameter
@r2b depends on rules@
constant char[] c;
expression x;
@@
NV_PRINTF2(x, c, __func__, ...)

// Get rid of __func__ at the beginning of the string
@script:python s2b@
c << r2b.c;
c2;
@@
import re
coccinelle.c2 = re.sub('%s[: ]*', '', c, 1)

@depends on rules@
expression x;
constant char[] r2b.c;
identifier s2b.c2;
@@
NV_PRINTF2(x,
-c, __func__
+c2
,...);
Julia Lawall
2018-12-05 06:56:15 UTC
Permalink
Post by Timur Tabi
I have some rules and Python code that removes __FUNCTION__ as a
parameter in a call to a function. That all works great. I now want
it to remove __func__ in exactly the same way. So I copy/pasted my
warning: line 202: should __func__ be a metavariable?
warning: line 218: should __func__ be a metavariable?
warning: line 229: should __func__ be a metavariable?
// Look for NV_PRINTF2 calls that have __func__ as the first parameter
@r2b depends on rules@
constant char[] c;
expression x;
@@
NV_PRINTF2(x, c, __func__, ...)
Typically function names and field names might be metavariables or might
be specific desired names, so there is no check for them. On the other
hand, other kinds of expressions are often represented as metavariables,
and a common mistake is to forget to declare one of them. So Coccinelle
gives a warning if such a thing is not declared as a metavariable. You
can silence the warning by adding the metavariable declaration

symbol __func__;

which means to match that thing explicitly. Once you do that in one rule,
it applies thereafter.

julia
Post by Timur Tabi
// Get rid of __func__ at the beginning of the string
@script:python s2b@
c << r2b.c;
c2;
@@
import re
coccinelle.c2 = re.sub('%s[: ]*', '', c, 1)
@depends on rules@
expression x;
constant char[] r2b.c;
identifier s2b.c2;
@@
NV_PRINTF2(x,
-c, __func__
+c2
,...);
_______________________________________________
Cocci mailing list
https://systeme.lip6.fr/mailman/listinfo/cocci
Loading...