如果是直接调用函数,可以通过以下代码获取Function类型。
Function * fun = callInst->getCalledFunction();
Function * funType = fun->getFunctionType();
但是,如果调用是间接的,即通过函数指针,则
getCalledFunction
返回 NULL。所以我的问题是当通过函数指针调用函数时如何获取 Function 类型。
要从间接调用获取类型,请使用
getCalledValue
而不是 getCalledFunction
,如下所示:
Type* t = callInst->getCalledValue()->getType();
这将为您提供传递给调用指令的指针的类型;要获取实际的函数类型,请继续:
FunctionType* ft = cast<FunctionType>(cast<PointerType>(t)->getElementType());