Re: [cocci] Adjusting attributes for variables with SmPL?

Julia Lawall <[email protected]> Thu, 28 May 2026 09:48:30 +0200 (CEST)
Newsgroups fr.inria.cocci
Message-ID <[email protected]>

On Thu, 28 May 2026, Pierrick Philippe wrote:

> On 5/27/26 13:11, Markus Elfring wrote:
> >> I haven't tried this, though.  Another more complex solution involves
> >> passing through python code.  You can get inspiration from
> >> demos/pythontococci.cocci.  You would want to set eg coccinelle.z to a
> >> string that additionally contains the desired string quotes.
> > Would you find a data processing approach (like the following) “appropriate”?
> >
> > @searching@
> > expression E1, E2;
> > identifier F, X;
> > initialiser I;
> > type T;
> > @@
> >  T F = I;
> >  ...
> >  memcmp(&F.X, E1, E2)
> >
> > @script:python generation@
> > f << searching.F;
> > x << searching.X;
> > content;
> > @@
> > coccinelle.content = cocci.make_ident("__attribute__((myattr(\"" + x + "\"))) " + f)

You don't have to put the whole thing in content.  Content could just make
the string, and then the replacement rule could have built the rest.

julia

> >
> > @replacement@
> > expression searching.E1, searching.E2;
> > identifier searching.F, searching.X, generation.content;
> > initialiser searching.I;
> > type searching.T;
> > @@
> >  T
> > -F
> > +content
> >  = I;
> >  ...
> >  memcmp(&F.X, E1, E2)
> This one is clearly working and the output is as expected, thanks.
> I tried writing one on my own but didn't manage to write a working
> semantic patch.
> Thanks a lot :)
>
> Pierrick
>
> > Regards,
> > Markus
>