From: Julia Lawall <julia.lawall@inria.fr>
To: Chuhong Yuan <hslester96@gmail.com>
Cc: cocci@systeme.lip6.fr
Subject: Re: [Cocci] How to match function calls in macros?
Date: Sat, 16 May 2020 14:45:29 +0200 (CEST) [thread overview]
Message-ID: <alpine.DEB.2.21.2005161441500.2573@hadrien> (raw)
In-Reply-To: <CANhBUQ3YaJnVZwy2+Fo42Naa04wQiBnEO6cm-rGE05=rZp0XKw@mail.gmail.com>
On Sat, 16 May 2020, Chuhong Yuan wrote:
> On Sat, May 16, 2020 at 4:49 PM Julia Lawall <julia.lawall@inria.fr> wrote:
> >
> >
> >
> > On Sat, 16 May 2020, Chuhong Yuan wrote:
> >
> > > Hi all,
> > > I want to write a script to match function calls in macros
> > > but I don't know how to do that.
> > > Here is an example:
> > >
> > > #define __INIT_WORK(_work, _func, _onstack) \
> > > do { \
> > > static struct lock_class_key __key; \
> > > \
> > > __init_work((_work), _onstack); \
> > > (_work)->data = (atomic_long_t) WORK_DATA_INIT(); \
> > > lockdep_init_map(&(_work)->lockdep_map,
> > > "(work_completion)"#_work, &__key, 0); \
> > > INIT_LIST_HEAD(&(_work)->entry); \
> > > (_work)->func = (_func); \
> > > } while (0)
> > >
> > > In this example, I want to match function calls
> > > like __init_work() and lockdep_init_map() in this macro.
> > > So how to implement this by Coccinelle?
> >
> > I would suggest to take your file and run spatch --parse-c on the file.
> > If you find BAD or bad in front of the lines of this code then the problem
> > is that the code is not being parsed. I suspect that the # is the
> > problem.
> >
>
> I have run parse-c and it says the example file is perfect.
>
> > Normally, Coccinelle will match code inside of macro definitions, but only
> > if it is able to parse the macro definition, and the ability to parse
> > macro definitions is somewhat limited.
> >
>
> My expression is not very clear.
> I want to know which macros have function calls and what functions do they call.
> So I wrote a script like this:
>
> - #define mac(...) ... f(...) ...
>
> But it does not work on the example.
Try:
@@
identifier mac,f;
@@
*#define mac(...) <+... f(...) ...+>
... means that the code before and after the ... cannot be matched by the
... when considering control-flow paths. Your macro is a loop, so there
is one call to f(...) after another. Coccinelle doesn't evaluate values,
so it doesn't realize that a while(0) won't loop.
julia
_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci
next prev parent reply other threads:[~2020-05-16 12:45 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-05-16 8:16 [Cocci] How to match function calls in macros? Chuhong Yuan
2020-05-16 8:49 ` Julia Lawall
2020-05-16 12:26 ` Chuhong Yuan
2020-05-16 12:45 ` Julia Lawall [this message]
2020-05-16 14:17 ` Chuhong Yuan
-- strict thread matches above, loose matches on Subject: below --
2020-05-16 11:42 Markus Elfring
2020-05-18 8:26 Markus Elfring
2020-05-18 9:19 ` Julia Lawall
2020-05-18 10:13 ` Markus Elfring
2020-05-18 10:18 ` Julia Lawall
2020-05-18 10:30 ` Markus Elfring
2020-05-18 10:34 ` Julia Lawall
2020-05-18 10:46 ` Markus Elfring
2020-05-18 10:50 ` Julia Lawall
2020-05-18 11:07 ` Markus Elfring
2020-05-19 11:15 ` Markus Elfring
2020-05-19 11:23 ` Julia Lawall
2020-05-19 11:43 ` Markus Elfring
2020-05-19 11:55 ` Julia Lawall
2020-05-19 12:04 ` Markus Elfring
2020-05-18 12:07 ` 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=alpine.DEB.2.21.2005161441500.2573@hadrien \
--to=julia.lawall@inria.fr \
--cc=cocci@systeme.lip6.fr \
--cc=hslester96@gmail.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.