Matching Function Pointers in Clang-Query

477 Views Asked by At

What is the query to match a function pointer, e.g., in the following code:

int foo(struct A *a, int b)
{
    return a->x->y(b);
}

y is the function pointer to match.

1

There are 1 best solutions below

0
On BEST ANSWER

Finally, this is the answer for a call to a function pointer. The main difficulty was to detect the type of function pointers using the query. So I added the ignoringParens(functionType()) traversal matcher to solve the problem. A simple usage of functionType() will not work.

match callExpr(hasDescendant(memberExpr(hasType(pointerType(pointee(ignoringParens(functionType()))))).bind("member")))