On Sun, 30 Jan 2011, SF Markus Elfring wrote:

> > It should be possible to declare a metavariable to have any C type.
> 
> I have got the impression that meta-variables get a SmPL data type which
> corresponds to syntax elements in the target language.
> Are all (needed) elements already supported?

You can specify a metavariable as matching an expression of an arbitrary 
type, int, char *, etc.  But parsing of function types in this position 
does not seem to yet be supported.

> > For function types, though it doesn't seem to work in practice.
> 
> I'm sorry that I can not understand your hint so far.
> Would you like to explain it a bit more?
> 
> 
> > I don't think that giving a metavariable a function type is necessary for 
> > doing this.  You can just match the declaration of the function itself.
> 
> How can I specify the desired filter expression if I do not know a concrete
> function name?
> Can a meta-variable provide the name for the affected function(s)?

If you want to do something with functions that have a type other than 
void, you can do:

@r@
identifier f;
@@

f(...) { ... }

@isvoid@
identifier r.f;
@@

void f(...) { ... }

@depends on !isvoid@
identifier r.f;
@@

{here f is a non-void function}

Some functions don't have definitions, only prototypes.  You could repeat 
the above rules for the prototype case.

> > I'm not sure that a generally applicable transformation can be defined in 
> > this case.  One would have to think a bit how the return value should be 
> > used (eg tested, and what the impact of that test should be).
> 
> I would try to insert a function call like "exit(errno)" or "abort()" if the
> target language is "C".

That is good for debugging, but probably more brutal than what is wanted 
in practice.  Usually what is done in Linux code is to clean up the local 
state and return some error code to the caller.

> Otherwise: I would try to throw an exception in programming languages which
> support them.
> 
> 
> > Perhaps if one passes it to another function, that could be considered to 
> > be good enough?
> 
> Not completely. - Can it be expressed in the semantic patch language that a
> return value was assigned to a variable and not used in a conditional 
> expression
> or as a function parameter after that assignment?

Yes, along the lines of the example I sent to Anders.

> How do you think about a concrete SmPL filter pattern application for a 
> source file where I pointed out corresponding open issues in a bug 
> report "Check return codes everywhere"? 
> http://www.cmake.org/Bug/view.php?id=11681 ÿÿ Source code example: 
> http://cmake.org/gitweb?p=cmake.git;a=blob;f=Source/kwsys/ProcessUNIX.c;hb=b9e3c243d476efa04479d253cfc4f76ecbdb6fe3#l2713

I looked at the code, but I don't see the problem in that case, since the 
mentioned line is the header of a void function.

> > But if one wants to consider that case in a special way, it should be 
> > possible to do that. 
> > Eg f(...,x,...) where f is a metavariable will match any passing of x to 
> > some function.
> 
> I see that you suggest the use of commas around the "x" (meta-)variable. Does
> this also work at the beginning or end of the function parameter list?

Yes, for all kinds of lists (parameters, arguments, etc).

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

Reply via email to