On Mon, 22 Feb 2010, SF Markus Elfring wrote:

> > The attribute given to the two function definitions will make the compiler 
> > (GCC
> > in my case) emit a warning, if the return-value of the given function is 
> > unused
> > in the caller.
> 
> I know the mentioned complier extension.
> http://gcc.gnu.org/onlinedocs/gcc/Function-Attributes.html#index-g_t_0040code_007bwarn_005funused_005fresult_007d-attribute-2391
> 
> I would appreciate support for this use case by the semantic patch language. 
> I imagine that it would enable a concrete bunch of update suggestions for 
> various source files.
> Evolving tools from the area of aspect-oriented software development provide 
> alternative approaches besides static source code analysis.

You can work on the prototype of the file.  The following finds calls 
where there is a non-void return type but the value is ignored:

@r@
identifier f;
@@

f(...);

@ok@
identifier r.f;
@@

void f(...);

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

*f(...);

You would want to run this with the option -all_includes, because often 
the prototype will be in an include file.

This will not do as well as Alexander's solution, though, because it might 
be that the prototype will be in a header file that Coccinelle cannot 
find.  But of course with Coccinelle you can do some transformation on the 
identified function calls.

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

Reply via email to