public inbox for cocci@systeme.lip6.fr
 help / color / mirror / Atom feed
* [cocci] Matching function pointer casts
@ 2025-12-02 14:12 Mathias Krause
  2025-12-10 11:12 ` Markus Elfring
  0 siblings, 1 reply; 3+ messages in thread
From: Mathias Krause @ 2025-12-02 14:12 UTC (permalink / raw)
  To: cocci

Hi,

I have a hard time trying to come up with a semantic patch that would
match function pointer casts, specifically (void (*)(void)) in my case.

I want to get rid of these and replace them with a properly typed
functions that'd do necessary type conversions. (I already have that
part, though.)

Below are two attempts I tried and did not work;

1.
@pfunc_cast@
identifier fn;
fresh identifier fnthunk = "THUNK_" ## fn;
@@
- (void (*)(void)) &fn
+ &fnthunk

Above doesn't parse for me (spatch version 1.1.0).

2.
@pfunc_cast@
identifier fn;
fresh identifier fnthunk = "THUNK_" ## fn;
type T =~ "^void (*)(void)$";
@@
- (T) &fn
+ &fnthunk

as well as 3.
@pfunc_cast@
identifier fn;
fresh identifier fnthunk = "THUNK_" ## fn;
type T =~ "void \\(*\\)\\(void\\)";
@@
- (T) &fn
+ &fnthunk


This basically matches all address taking expressions, even without
casts, and replaces them by &THUNK_... -- not quite what I want. ;)
It looks like to completely ignoring the regular expression for the type
match beside complaining about syntax errors when one does some?

Is there a way to match function pointer casts in spatch at all?

Thanks,
Mathias

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [cocci] Matching function pointer casts
  2025-12-02 14:12 [cocci] Matching function pointer casts Mathias Krause
@ 2025-12-10 11:12 ` Markus Elfring
       [not found]   ` <c1622b03-ada2-4978-92ee-268b0868671c@grsecurity.net>
  0 siblings, 1 reply; 3+ messages in thread
From: Markus Elfring @ 2025-12-10 11:12 UTC (permalink / raw)
  To: Mathias Krause; +Cc: cocci

> Is there a way to match function pointer casts in spatch at all?

How do you think about to construct another test case variant
for the desired software clarification?

Regards,
Markus

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [cocci] Matching function pointer casts
       [not found]   ` <c1622b03-ada2-4978-92ee-268b0868671c@grsecurity.net>
@ 2025-12-10 14:25     ` Markus Elfring
  0 siblings, 0 replies; 3+ messages in thread
From: Markus Elfring @ 2025-12-10 14:25 UTC (permalink / raw)
  To: Mathias Krause; +Cc: cocci

> I meanwhile found a workaround but it's ugly -- not because cocci fails
> to match on function pointer casts (I implemented that by making use of
> its python script capabilities) but because of actual source code
> guards, the function pointer assignments are wrapped in.
> 
> It's an '#if ... #else ... #endif' block that, apparently, doesn't get
> processed correctly. The preprocessor condition is non-trivial as in not
> simply being "0" or "1" but still easy enough to handle (one level of indirection).

Thanks for such background information.

There are some development challenges remaining for better support
of conditional “compilation” (or analysis) also by the means of the Coccinelle software.

Regards,
Markus

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-12-10 14:25 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-12-02 14:12 [cocci] Matching function pointer casts Mathias Krause
2025-12-10 11:12 ` Markus Elfring
     [not found]   ` <c1622b03-ada2-4978-92ee-268b0868671c@grsecurity.net>
2025-12-10 14:25     ` Markus Elfring

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox