Matching function pointer casts
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
Quoted 1 line
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
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 8 lines
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