Re: [cocci] Can we match a known macro by macro name instead of expanded function name?

Tobias Deiminger <[email protected]>
Newsgroups fr.inria.cocci
Message-ID <[email protected]>
Unintentionally removed the list from recipients, thus resending. Sorry 
for the noise.

Am 29.11.2025 18:29 schrieb Tobias Deiminger:
> Am 29.11.2025 17:36 schrieb Julia Lawall:
>> On Sat, 29 Nov 2025, Tobias Deiminger wrote:
>> 
>>> Am 29.11.2025 16:59 schrieb Julia Lawall:
>>> > On Sat, 29 Nov 2025, Tobias Deiminger wrote:
>>> > [...]
>>> > There is no macro expansion in the semantic patch.
>>> 
>>> Sorry, that I don't understand. Here's the complete minimal example 
>>> as I
>>> understood from your earlier advice:
>>> 
>>>   // my.c
>>>   SYSCALL_DEFINE0(foo) { return 0; }
>>> 
>>>   // my.cocci
>>>   @r@
>>>   attribute a;
>>>   identifier fn;
>>>   type t;
>>>   @@
>>>   * t a fn(...) { ... }
>>> 
>>>   // standard.h
>>>   #define  asmlinkage
>>>   #define SYSCALL_DEFINE0(func) \
>>>       asmlinkage unsigned long __SYSCALL_DEFINE0 func(void)
>> 
>> There is no macro expansion in the semantic patch.  You have to write 
>> the
>> semantic patch to match the expanded function.
> 
> Yes, I believe that's exactly what I did:
> 
> 1. The semantic patch is "* t a fn(...) { ... }". It matches the
> expanded function, where return type = unsigned long, attribute =
> __SYSCALL_DEFINE0, fn = foo.
> 
>> Macro expansion only happens in the C code.
> 
> 2. The C code is 'SYSCALL_DEFINE0(foo) { return 0; }'. I assume this C
> code is expanded by spatch to the definition in standard.h to
> "unsigned long __SYSCALL_DEFINE0 foo(void)" before the semantic patch
> gets applied.
> 
> Somewhere either me or coccinelle is wrong. Very likely the former ;-)
> 
> Tobias
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.