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

Julia Lawall <[email protected]> Thu, 28 May 2026 14:35:01 +0200 (CEST)
Newsgroups fr.inria.cocci
Message-ID <[email protected]>
  This message is in MIME format.  The first part should be readable text,
  while the remaining parts are likely unreadable without MIME-aware tools.

--8323329-1934856873-1779971701=:10822
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8BIT



On Thu, 28 May 2026, Markus Elfring wrote:

> >>> You have declared content as an identifer and added it into a position
> >>> where an identifier is not allowed.  My suggestion was something like:
> >>>
> >>> coccinelle.content = "\"" + x + "\""
> >>>
> >>> Or whatever is appropriate in pything for putting the value of x in string
> >>> quotes.  Then in the replacement rule you can put the whole
> >>> __attribute((...)) construction.
> >> The following data processing approach is not accepted by the Coccinelle software
> >> so far.
> > Didn't I already explain why it didn't work and send an alternative?
>
> Another data processing approach might look promising.
>
> @searching@
> expression E1, E2;
> identifier F, X;
> initialiser I;
> type T;
> @@
>  T F = I;
>  ...
>  memcmp(&F.X, E1, E2)
>
> @script:python generation@
> x << searching.X;
> my_string;
> @@
> coccinelle.my_string = "\"" + x + "\""
>
> @replacement@
> expression searching.E1, searching.E2;
> identifier searching.F, searching.X, generation.my_string;
> initialiser searching.I;
> type searching.T;
> @@
>  T
> +__attribute__((myattr(
> +my_string
> +)))
>  F = I;
>  ...
>  memcmp(&F.X, E1, E2)
>
>
> Markus_Elfring@Sonne:…/elfring/Projekte/Coccinelle/Probe> /usr/bin/spatch --parse-cocci suggestion4_for_Pierrick_Philippe-20260528.cocci
> …
> @replacement@
> @@
>
> T
>   >>> __attribute__ ((myattr(my_string)))
>         F = I ;
>       ...
>
>       memcmp(&F.X, E1, E2)
>
>
> warning: replacement: inherited metavariable my_string not used in the -, +, or context code
> …
>
> Grep query
> memcmp
>
>
>
> How does the shown message fit to the presented SmPL script?

What message?  The question is whether it makes the change that is wanted?

Maybe the check for whether variables are used doesn't look in arrtibute
arguments.

julia
--8323329-1934856873-1779971701=:10822--