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

Pierrick Philippe <[email protected]> Thu, 28 May 2026 12:09:05 +0200
Newsgroups fr.inria.cocci
Message-ID <[email protected]>
On 5/28/26 10:21, Julia Lawall wrote:
> On Thu, 28 May 2026, Pierrick Philippe wrote:
>> On 5/28/26 09:48, Julia Lawall wrote:
>> I have tried it, and spatch was complaining for some reason.
>> Though it might be to my lack of experience with SmPL.
>> I can provide the output if needed.
> Please provide the semantic patch used and the resulting output.

Sure, here is the output of `spatch --sp-file ./test-python.cocci
./test-struct.c -debug`:

```
init_defs_builtins:
/nix/store/40c99rw6w18kbf89qjqampp7m672a773-coccinelle-1.3.0/lib/coccinelle/standard.h
-----------------------------------------------------------------------
processing semantic patch file: ./test-python.cocci
with isos from:
/nix/store/40c99rw6w18kbf89qjqampp7m672a773-coccinelle-1.3.0/lib/coccinelle/standard.iso
-----------------------------------------------------------------------
@searching_struct_scalar@
expression E1, E2;
identifier F, X;
initialiser I;
type T;
@@
T F = I;
...
(
memcmp(&F.X, E1, E2)
|
memcmp(E1, &F.X, E2)
)

@script:python generation_struct_scalar@
f << searching_struct_scalar.F;
x << searching_struct_scalar.X;
content;
@@
coccinelle.content = cocci.make_ident("__attribute__((myattr(\"" + x +
"\"))) ")

@replacement_struct_scalar@
expression searching_struct_scalar.E1, searching_struct_scalar.E2;
identifier searching_struct_scalar.F, searching_struct_scalar.X,
generation_struct_scalar.content;
initialiser searching_struct_scalar.I;
type searching_struct_scalar.T;
@@
T
+content
 F = I;
...
(
memcmp(&F.X, E1, E2)
|
memcmp(E1, &F.X, E2)
)

plus: parse error: 
  File "./test-python.cocci", line 30, column 1, charpos = 629
  around = 'F',
  whole content =  F = I;
```

Seems like the issue is in the rule `replacement_struct_scalar`.

>
> thanks,
> julia