backports.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Luca Coelho <luca@coelho.fi>
To: Julia Lawall <julia.lawall@lip6.fr>
Cc: cocci@systeme.lip6.fr, backports@vger.kernel.org,
	johannes.berg@intel.com, felipe.balbi@intel.com
Subject: Re: Weird problem trying to match code inside a function
Date: Tue, 11 Sep 2018 14:22:44 +0300	[thread overview]
Message-ID: <9ff5075ecd90926d1e47060f0309cd2c0e531ba2.camel@coelho.fi> (raw)
In-Reply-To: <alpine.DEB.2.20.1809111059590.3671@hadrien>

On Tue, 2018-09-11 at 11:05 +0200, Julia Lawall wrote:
> 
> On Tue, 11 Sep 2018, Luca Coelho wrote:
> 
> > Hi Julia,
> > 
> > I bumped in to another weird problem.  I'm trying to match some
> > code
> > inside a function that has a specific struct as a parameter, but I
> > can't get it to work.
> > 
> > This is cocci code I tried first:
> > 
> > http://pastebin.coelho.fi/6f8f346822a7c99e.txt
> > 
> > And this is the file I'm trying to match:
> > 
> > http://pastebin.coelho.fi/f73f542932add1c6.txt
> > 
> > The led activate op changed from being a function that returns void
> > to
> > one that returns int and I had to backport that.
> > 
> > The strange thing is that if I have only the first rule, it works
> > fine,
> > but when I add the second rule it fails.
> 
> I didn't look at the code in detail, but there is a restriction on
> metavariables that are not position variables that are inherited from
> one
> rule to another.  Such metavariables have to have only one value.  If
> there is more than one possible value, the original match fails
> completely.
> 
> For example, if you do:
> 
> @r@
> expression E;
> @@
> 
> f();
> ...
> -g(E);
> 
> This will do the right thing for:
> 
> f();
> if (x)
>   g(3);
> else g(4);
> 
> But if you do:
> 
> @r@
> expression E;
> @@
> 
> f();
> ...
> -g(E);
> 
> @@
> expression r.E;
> @@
> 
> - xxx(E);
> 
> Then nothing will happen at all.  Because in the first rule, it is
> not
> able to find a unique binding for E.
> 
> A solution can be:
> 
> @r@
> expression E;
> position p;
> @@
> 
> f();
> ...
> g(E@p);
> 
> @s@
> position r.p;
> expression E;
> @@
> 
> - g(E@p);
> 
> @@
> expression s.E;
> @@
> 
> - xxx(E);
> 
> Position metavariable can take on many values, even if they are
> inherited.

Ah, I think this explains the problem.

I tried to add the position thing in my rules, but I didn't succeed. 
I'll have to try again at some other time.  My rules without matching
inside a function work fine, so I'll leave with that for now.

Thanks!

--
Luca.

--
To unsubscribe from this list: send the line "unsubscribe backports" in

      reply	other threads:[~2018-09-11 16:21 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-09-11  8:08 Weird problem trying to match code inside a function Luca Coelho
2018-09-11  9:05 ` Julia Lawall
2018-09-11 11:22   ` Luca Coelho [this message]

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=9ff5075ecd90926d1e47060f0309cd2c0e531ba2.camel@coelho.fi \
    --to=luca@coelho.fi \
    --cc=backports@vger.kernel.org \
    --cc=cocci@systeme.lip6.fr \
    --cc=felipe.balbi@intel.com \
    --cc=johannes.berg@intel.com \
    --cc=julia.lawall@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;
as well as URLs for NNTP newsgroup(s).