On Tue, 28 Apr 2020, Paul Chaignon wrote:

> Thanks for the quick answer!
>
> On Tue, Apr 28, 2020 at 07:44:15PM +0200, Julia Lawall wrote:
> >
> >
> > On Tue, 28 Apr 2020, Paul Chaignon wrote:
> >
> > > Hi all,
> > >
> > > I am working on a small semantic patch to annotate specific variables in
> > > our codebase with __attribute__((aligned(8))). The following program works
> > > fine.
> > >
> > >   @r@
> > >   expression e1, e2;
> > >   identifier x;
> > >   @@
> > >   (
> > >     struct \(icmphdr\|icmp6hdr\) x
> > >   + __attribute__((aligned(8)))
> > >     ;
> > >   |
> > >     struct \(icmphdr\|icmp6hdr\) x
> > >   + __attribute__((aligned(8)))
> > >     = ...;
> > >   )
> > >     ... when exists
> > >     ctx_load_bytes(e1, e2, &x, ...)
> > >
> > > However, when I replace __attribute__((aligned(8))) with our internal
> > > macro __align_stack_8, it fails with the following error:
> > >
> > >   plus: parse error:
> > >     File "/home/paul/cilium/contrib/coccinelle/aligned.cocci", line 7, 
> > > column 2, charpos = 77
> > >     around = '__align_stack_8',
> > >     whole content = + __align_stack_8
> > >
> > > I've tried adding '#define __align_stack_8' in a file passed with
> > > --macro-file, without success. Is this a known limitation for macros or
> > > am I missing something?
> >
> > Try adding the "metavariable" declaration:
> >
> > attribute name __align_stack_8;
>
> Awesome, that worked. And I think I understand: undeclared identifiers are by
> default considered symbols, leading to the parse error.
>
> Unfortunately, my semantic patch now leads to the following changes:
>
>   -   struct icmphdr icmphdr __align_stack_8;
>   +   struct icmphdr icmphdr __align_stack_8 __align_stack_8;
>
> I would normally add a first case to my conjunction to match on
> already-present attributes, but Coccinelle can't match on attributes yet.
> Any workaround?

Jaskaran is working on it.

A hackish solution would be to put a position variable on the variable
name and put a position variable on the ; and then use python to see if
they are not adjacent to each other...

Do you get a lot of occurrences of the problem?  In the short term it
could be simpler to just clean it up by hand.  It should be easy to search
for at least.

julia


>
> Paul
>
_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci

Reply via email to