Coccinelle Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: lars@metafoo.de (Lars-Peter Clausen)
To: cocci@systeme.lip6.fr
Subject: [Cocci] isomorphism with unlikely
Date: Mon, 20 May 2013 21:13:34 +0200	[thread overview]
Message-ID: <519A75DE.1040604@metafoo.de> (raw)
In-Reply-To: <alpine.DEB.2.02.1305202051210.2036@localhost6.localdomain6>

On 05/20/2013 08:51 PM, Julia Lawall wrote:
> On Mon, 20 May 2013, Lars-Peter Clausen wrote:
> 
>> On 05/20/2013 08:24 PM, Wolfram Sang wrote:
>>>
>>>> There is already an isomorphism for unlikely. But it is in one direction
>>>> only, so 'unlikely(E)' in your cocci script will also match 'E', but 'E'
>>>> wont match 'unlikely(E)'.
>>>
>>> Okay, but I would then still need 'unlikely(!r)' and 'unlikely(r ==
>>> NULL)' because the !r isomorphisms won't apply. I'd like to have both :)
>>
>> No, just unlikley(r == NULL) also matches !r (and unlikely(!r)). This should
>> also work for unlikely(!r) matching unlikely(r == NULL) but for some reason
>> it doesn't. I just did a quick test and it looks as if even 'if(!r) ..."
>> doesn't match 'if(r == NULL) ...' either.
> 
> It should work if r has pointer type.  Otherwise, if r is not a pointer, 
> then !r should become r == 0.

But for some reason it does not. With --verbose-match I can see that it
generates the correct isomorphisms (both for the case that r is a pointer or
that r is an integer), but for some reason they don't seem to match.

The testcase is simple:

cocci file:

@@
expression *r;
statement S;
@@
*if(!r) S

c file:

int foo(struct resource *r)
{
	if (r == NULL)
		return 0;
	return 1;
}

- Lars

  reply	other threads:[~2013-05-20 19:13 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-05-20 17:34 [Cocci] isomorphism with unlikely Wolfram Sang
2013-05-20 17:47 ` Lars-Peter Clausen
2013-05-20 18:24   ` Wolfram Sang
2013-05-20 18:26     ` Lars-Peter Clausen
2013-05-20 18:51       ` Julia Lawall
2013-05-20 19:13         ` Lars-Peter Clausen [this message]
2013-05-22 17:36           ` Julia Lawall
2013-05-26 20:01           ` Julia Lawall

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=519A75DE.1040604@metafoo.de \
    --to=lars@metafoo.de \
    --cc=cocci@systeme.lip6.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox