The simple solution is just:

@@
@@

* bar();

But maybe you also want to capture cases where the return value is stored 
in a variable and that variable is never used.  Then you could say:

@@
local idexpression x;
@@

(
x = bar()
...
x
|
*x = bar()
)

I put local idexpression to be sure that x is a local variable.  If it 
were an expression such as a->b or a globale variable, then it might be 
used somewhere else.

julia



On Sun, 30 Jan 2011, Anders Wegge Keller wrote:

> 
>  I'm trying to match the cases where the return value from the
> function bar() isn't used in any way. Given that it can be used in
> many more ways than just assignment, I'm afraid that I will end up
> with a very large set of alternatives, before I've covered all
> cases. My first attempt at finding the unused return values isn't very
> good, as it gives 4 false positives in this case. 
> 
>  Is there a simpler way of expressing this poblem in a way so this
> example would only yield the line "bar();"?
> 
> -- foo.c --
> extern int bar(void);
> extern int *barp(void);
> 
> int foo (void) {
> 
>     int baz;
> 
>     baz = (int) bar();
>     baz = 2 + bar();
>     baz = bar() % 4;
>     baz = *((int *) bar());
>     baz = bar();
>     bar();
> 
>     return baz;
> }
> 
> 
> -- barreturn.cocci --
> @@
> identifier RV;
> @@
> 
> (
>  RV = bar()
> |
> * bar()
> )
> 
> -- 
> /Wegge
> 
> 
> _______________________________________________
> Cocci mailing list
> [email protected]
> http://lists.diku.dk/mailman/listinfo/cocci
> (Web access from inside DIKUs LAN only)
> 
_______________________________________________
Cocci mailing list
[email protected]
http://lists.diku.dk/mailman/listinfo/cocci
(Web access from inside DIKUs LAN only)

Reply via email to