If a function call is direct, you can get the Function type through the following code.
Function * fun = callInst->getCalledFunction();
Function * funType = fun->getFunctionType();
However, if the call is indirect, that is, through a function pointer, the getCalledFunction
returns NULL. So my question is how to get the Function type when a function is called through a function pointer.
To get the type from an indirect call, use getCalledValue
instead of getCalledFunction
, like so:
Type* t = callInst->getCalledValue()->getType();
That would get you the type of the pointer passed to the call instruction; to get the actual function type, continue with:
FunctionType* ft = cast<FunctionType>(cast<PointerType>(t)->getElementType());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With