cocci.inria.fr archive mirror
 help / color / mirror / Atom feed
* [Cocci] Match variable declaration with init expression
@ 2020-07-31 12:40 Denis Efremov
  2020-07-31 16:55 ` Julia Lawall
  0 siblings, 1 reply; 2+ messages in thread
From: Denis Efremov @ 2020-07-31 12:40 UTC (permalink / raw)
  To: cocci

Hi,

This pattern:
- E = kzalloc(size, flags | __GFP_NOWARN);
- if (\(!E\|E == null\))@p
-   E = vzalloc(size);
+ E = kvzalloc(size, flags);

matches this code:
void *p;
p = kzalloc(size, gfp | __GFP_NOWARN);

if (!p)
	p = vzalloc(size);

But not this:
void *p = kzalloc(size, gfp | __GFP_NOWARN);

if (!p)
	p = vzalloc(size);

What can I do to match them both?

Thanks,
Denis
_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [Cocci] Match variable declaration with init expression
  2020-07-31 12:40 [Cocci] Match variable declaration with init expression Denis Efremov
@ 2020-07-31 16:55 ` Julia Lawall
  0 siblings, 0 replies; 2+ messages in thread
From: Julia Lawall @ 2020-07-31 16:55 UTC (permalink / raw)
  To: Denis Efremov; +Cc: cocci



On Fri, 31 Jul 2020, Denis Efremov wrote:

> Hi,
>
> This pattern:
> - E = kzalloc(size, flags | __GFP_NOWARN);
> - if (\(!E\|E == null\))@p
> -   E = vzalloc(size);
> + E = kvzalloc(size, flags);
>
> matches this code:
> void *p;
> p = kzalloc(size, gfp | __GFP_NOWARN);
>
> if (!p)
> 	p = vzalloc(size);
>
> But not this:
> void *p = kzalloc(size, gfp | __GFP_NOWARN);
>
> if (!p)
> 	p = vzalloc(size);
>
> What can I do to match them both?

For a transformation like that, it's not possible to match both at once.
The problem is that it doesn't know what you want to do with E.  You can't
remove it and just leave void alone.

I don't know if a disjunction is possible either, because one is a
declaration and the other is a statement.

julia
_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-07-31 16:55 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-31 12:40 [Cocci] Match variable declaration with init expression Denis Efremov
2020-07-31 16:55 ` Julia Lawall

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).