How to get FunctionType from CallInst when a call is indirect in LLVM

If the function call is direct, you can get the type of the function through the following code.

Function * fun = callInst->getCalledFunction(); Function * funType = fun->getFunctionType(); 

However, if the call is indirect, that is, through a function pointer, getCalledFunction returns NULL. So my question is how to get the type of the function when the function is called using the function pointer.

+7
source share
1 answer

To get a type from an indirect call, use getCalledValue instead of getCalledFunction , for example:

 Type* t = callInst->getCalledValue()->getType(); 

This will give you the type of pointer passed to the call command; to get the actual type of function, continue:

 FunctionType* ft = cast<FunctionType>(cast<PointerType>(t)->getElementType()); 
+9
source

All Articles