cocci.inria.fr archive mirror
 help / color / mirror / Atom feed
From: "Jérémy LEFAURE" <jeremy.lefaure@netatmo.com>
To: Julia Lawall <julia.lawall@inria.fr>,
	Markus Elfring <Markus.Elfring@web.de>
Cc: "cocci@inria.fr" <cocci@inria.fr>,
	"kernel-janitors@vger.kernel.org"
	<kernel-janitors@vger.kernel.org>,
	Nicolas Palix <nicolas.palix@imag.fr>
Subject: Re: [cocci] [PATCH v2] coccinelle: ifaddr: Find address test in more complex conditions
Date: Wed, 8 Jun 2022 12:04:52 +0000	[thread overview]
Message-ID: <AS8PR03MB76038B2D2E451F0A07AEE4D093A49@AS8PR03MB7603.eurprd03.prod.outlook.com> (raw)
In-Reply-To: <alpine.DEB.2.22.394.2206072138160.2960@hadrien>

> I don't really understand the above, but it made me realize that actually
> the following is sufficient:
>
> @@
> expression x;
> @@
>
> *&x || ...
>
> This forces &x to appear as a test expression. There can be 0 or more
> occurrences of ||, so eg &x && y is also matched.

That's indeed better because it allows to catch issues in tests that
are not in if statements (such as loops). Is it ok to rename this file
to test_addr.cocci in the next version of the patch to give it a more
appropriated name?

It also gives a better line indication for conditions split on several
lines.

I also noticed that with this change the semantic patch catches tests of
addresses in if statements when likely/unlikely is used, for example
if (likely(&a)). This was not the case with my previous patch nor with
the current semantic patch version on master even though the isomorphism
unlikely(E) <=> likely(E) => E is in the standard.iso file. I don't get
this behavior change, do you have any idea why it didn't work?


Thank you!
Jérémy

________________________________________
From: Julia Lawall <julia.lawall@inria.fr>
Sent: Tuesday, June 7, 2022 21:39
To: Markus Elfring
Cc: Jérémy LEFAURE; cocci@inria.fr; kernel-janitors@vger.kernel.org; Julia Lawall; Nicolas Palix
Subject: Re: [PATCH v2] coccinelle: ifaddr: Find address test in more complex conditions



On Tue, 7 Jun 2022, Markus Elfring wrote:

>
> > The test of an expression's address does not necessarily represent the
> > whole condition, it may only be a part of it.
> > This change aims at detecting an address test in more complex conditions.
> >
> > Signed-off-by: Jérémy Lefaure <jeremy.lefaure@netatmo.com>
> > ---
> > v1 -> v2: Moved disjunction on the condition itself instead of being on the if statements
> >
> >  scripts/coccinelle/misc/ifaddr.cocci | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/scripts/coccinelle/misc/ifaddr.cocci b/scripts/coccinelle/misc/ifaddr.cocci
> > index fc92e8fcbfcb..14dbf3131a3f 100644
> > --- a/scripts/coccinelle/misc/ifaddr.cocci
> > +++ b/scripts/coccinelle/misc/ifaddr.cocci
> > @@ -18,7 +18,7 @@ statement S1,S2;
> >  position p;
> >  @@
> >
> > -*if@p (&x)
> > +*if@p ( \(&x || ... \| &x && ... \) )
> >   S1 else S2
> >
> >  @script:python depends on org@
>
>
> Would you ever dare to adjust the specification another bit for such
> a source code search approach according to the difference in the selection
> of the operators “||” (disjunction) and “&&” (conjunction)?

I don't really understand the above, but it made me realize that actually
the following is sufficient:

@@
expression x;
@@

*&x || ...

This forces &x to appear as a test expression.  There can be 0 or more
occurrences of ||, so eg &x && y is also matched.

julia

  reply	other threads:[~2022-06-08 14:08 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-07  9:15 [cocci] [PATCH v2] coccinelle: ifaddr: Find address test in more complex conditions Jérémy LEFAURE
2022-06-07  9:44 ` Julia Lawall
2022-06-07 18:33 ` Markus Elfring
2022-06-07 19:39   ` Julia Lawall
2022-06-08 12:04     ` Jérémy LEFAURE [this message]
2022-06-08 14:07       ` Julia Lawall
2022-06-08 17:44     ` [cocci] " Markus Elfring
2022-06-09 15:07     ` Markus Elfring
2022-06-09 15:41       ` Julia Lawall
2022-06-09 16:20         ` Markus Elfring
2022-06-09 16:25           ` Julia Lawall
2022-06-09 17:34             ` Markus Elfring
2022-06-09 19:39               ` Julia Lawall
2022-06-09 20:44                 ` Markus Elfring

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=AS8PR03MB76038B2D2E451F0A07AEE4D093A49@AS8PR03MB7603.eurprd03.prod.outlook.com \
    --to=jeremy.lefaure@netatmo.com \
    --cc=Markus.Elfring@web.de \
    --cc=cocci@inria.fr \
    --cc=julia.lawall@inria.fr \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=nicolas.palix@imag.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;
as well as URLs for NNTP newsgroup(s).