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

Julia Lawall <[email protected]> Wed, 27 May 2026 11:32:56 +0200 (CEST)
Newsgroups fr.inria.cocci
Message-ID <[email protected]>

On Wed, 27 May 2026, Markus Elfring wrote:

> >> I think that the problem is that { ... } is not actually an expression in
> >> C.  It's a strange thing that can only exist as part of a declaration.
>
> See also:
> https://en.cppreference.com/c/language/initialization
> https://gitlab.inria.fr/coccinelle/coccinelle/-/blob/1bff7651118fc65c269dd8dba7f7d4a30fbc72c7/docs/manual/cocci_syntax.tex#L237-238
>
>
> >> But you don't want to change it, so you don't need a metavariable for it.
> >>
> >> Just write:
> >>
> >> - T F =
> >> + T __attribute__((myattr(("X")))) F =
> >>   { ... };
> >
> > It does work indeed, thanks a lot!
>
> @addition@
> expression E1, E2;
> identifier F, X;
> type T;
> @@
>  T
> +__attribute__((myattr("X")))
>  F = { ... };
>  ...
>  memcmp(&F.X, E1, E2)
>
>
> > Although the metavariable X is not interpreted in the `+` context,
>
> I suggest to reconsider such a view once more.
> Please take another look at implementation details.
>
>
> > could it be due to the attribute or unrelated?
>
> Would you like to adjust a string literal according to a variable access?

The string is supposed to be constructed from the field referenced in the
memcmp call.

julia