Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c++

llvm

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.

like image 321
MetallicPriest Avatar asked Feb 11 '13 12:02

MetallicPriest


1 Answers

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());
like image 58
Oak Avatar answered Nov 17 '22 09:11

Oak