如何从LLVM中的CallInst获取函数名称?

pyt*_*nic 9 c c++ llvm clang

我有一个类型的对象CallInst.如何从中获取被调用的函数名称.假设直接调用该函数.

Use*_*ess 19

StringRef get_function_name(CallInst *call)
{
    Function *fun = call->getCalledFunction();
    if (fun) // thanks @Anton Korobeynikov
        return fun->getName(); // inherited from llvm::Value
    else
        return StringRef("indirect call");
}
Run Code Online (Sandbox Code Playgroud)

无论如何,这就是文档所暗示的:

  • 请注意,在间接调用的情况下,fun可以为NULL. (11认同)