public inbox for cocci@systeme.lip6.fr
 help / color / mirror / Atom feed
From: Tobias Deiminger <tobias.deiminger@posteo.de>
To: cocci@inria.fr
Subject: Re: [cocci] Can we match a known macro by macro name instead of expanded function name?
Date: Sat, 29 Nov 2025 20:06:43 +0000	[thread overview]
Message-ID: <ded004b275d73e35c46c3d30c057d58e@posteo.de> (raw)
In-Reply-To: <825ab32a-2544-d2a8-bc48-38f26c62bc@inria.fr>

Hi,

Am 29.11.2025 18:59 schrieb Julia Lawall:
> Sorry, I don't think it is going to work with the attribute in the 
> short
> term.
> 
> I succeeded with the following:
> 
> .cocci
> 
> @r@
> symbol SYSCALL_DEFINE1;
> identifier fn;
> type t;
> position p;
> @@
> fn(int SYSCALL_DEFINE1, ...) {@p ... }
> 
> // or put the corresponding python code
> @script:ocaml@
> p << r.p;
> @@
> 
> Printf.printf "line: %d\n" (List.hd p).line
> 
> ----------------------------------------------
> 
> standard.h
> 
> #define SYSCALL_DEFINE1(func, t1, a1) \
>     int func(int SYSCALL_DEFINE1, t1 a1)
> 
> ----------------------------------------------
> 
> .c
> 
> SYSCALL_DEFINE1(foo,int,x) { return 0; }
> 
> ----------------------------------------------

yep, that worked. Thanks a lot. What also works is to fake the return 
type to syscall_define_t in standard.h, and then do 'type t =~ 
"syscall_define_t";' in the rule.

This is good enough for my experiments *). Sure it would be nice if 
coccinelle could match on "known macros" somehow, maybe during the 
preprocessing run. But as said, I'm not in a position to make such 
suggestions and believe I understand how it's not well suited if the 
engine is designed to match on the AST.

Tobias

*) There's an ongoing effort to add testable code expectations / 
requirements to important functions in the Linux kernel [1]. I'm 
involved, and one thing that IMO would help is if we could quantify what 
"important" exactly means, i.e. how many functions are to be documented 
(100? 10000? 1000000?), and where exactly are they. So I'm looking for 
something that can find all syscalls, all exported symbols, all sysfs 
functions, subset of internal APIs, and so on. Raw grep is obviously not 
well suited. Coccinelle is already used for similar tasks, so it's an 
obvious candidate. tree-sitter queries could also work.

[1] https://lpc.events/event/19/contributions/2085/contribution.pdf

  parent reply	other threads:[~2025-11-29 20:06 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-29 10:38 [cocci] Can we match a known macro by macro name instead of expanded function name? Tobias Deiminger
2025-11-29 10:56 ` Julia Lawall
2025-11-29 13:15   ` Tobias Deiminger
2025-11-29 13:32     ` Markus Elfring
2025-11-29 13:51     ` Julia Lawall
2025-11-29 14:51       ` Markus Elfring
2025-11-29 15:00         ` Julia Lawall
2025-11-29 15:10           ` [cocci] Questionable macro expansions Markus Elfring
2025-11-29 15:55       ` [cocci] Can we match a known macro by macro name instead of expanded function name? Tobias Deiminger
2025-11-29 15:59         ` Julia Lawall
     [not found]           ` <67d1e00d2e22a4655cb10ec55d1a99db@posteo.de>
     [not found]             ` <83c8a7aa-9b98-8ac1-d563-e8fe2588f9a@inria.fr>
     [not found]               ` <fd7307f8024706d4bd128d0b7f43bb96@posteo.de>
2025-11-29 17:33                 ` Tobias Deiminger
2025-11-29 17:38                   ` Markus Elfring
2025-11-29 17:59                   ` Julia Lawall
2025-11-29 18:28                     ` Markus Elfring
2025-11-29 18:41                       ` Julia Lawall
2025-11-29 19:00                         ` Markus Elfring
2025-11-29 20:06                     ` Tobias Deiminger [this message]
2025-11-29 20:10                       ` Julia Lawall
2025-11-30  8:44                         ` [cocci] Clarification for parsing capabilities? Markus Elfring
2025-11-30  8:05                       ` [cocci] Can we match a known macro by macro name instead of expanded function name? Markus Elfring
2025-11-30 19:02                         ` Tobias Deiminger
2025-12-01  8:32                           ` Tobias Deiminger
2025-12-01 14:00                             ` Markus Elfring
2025-12-01  9:42                           ` Markus Elfring
2025-12-04  8:50                           ` [cocci] Searching for system call implementations? Markus Elfring
2025-11-29 16:28         ` [cocci] Can we match a known macro by macro name instead of expanded function name? Markus Elfring
2025-12-02  9:45 ` [cocci] Searching for system call implementations with SmPL? Markus Elfring

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ded004b275d73e35c46c3d30c057d58e@posteo.de \
    --to=tobias.deiminger@posteo.de \
    --cc=cocci@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox