When you introduce a wrapper function then you would like that the original function call isn't replaced inside the implementation of the wrapper function itself.
Example C-code:
#include <stdio.h>
int buh(void) {
printf("wrapper");
return baz();
}
int main(void) {
printf("baz");
baz();
return 1;
}
The following simple semantic patch will also replace “return baz();” with “return buh();” in the wrapper function.
@@ @@ - baz + buh
A better solution is to write a rule that matches the wrapper, records the positions of baz in the wrapper function and then only modify references to the function variable that are not in those positions.
@r@
position p;
@@
buh(...) {
<... baz@p ...>
}
@@
position p!=r.p;
@@
- baz@p
+ buh