Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get function name from CallInst in LLVM?

Tags:

c++

c

llvm

clang

I have an object of type CallInst. How can I get the name of the called function (aka callee). Assume the function is called directly (i.e., no indirect function calls).

like image 456
pythonic Avatar asked Jul 27 '12 11:07

pythonic


1 Answers

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");
}

anyway, that's what the documentation implies:

  • CallInst
    • CallInst::getCalledFunction
  • returns Function
  • and walk back up the inheritance graph until you see a plausible candidate:
    • Value
    • Value::getName
like image 187
Useless Avatar answered Oct 15 '22 22:10

Useless