[LLVMdev] How to get the const argument data from Function? (original) (raw)

Sanjoy Das sanjoy at playingwithpointers.com
Tue Jul 28 18:42:00 PDT 2015


llvm::Argument represents the formal parameter passed to its parent function. In other words, if you have

int f(int x) { }

then, within the body of f, x will be represented using an llvm::Argument. This is independent of any specific calls to f.

Now every call / invoke to f will be represented using an llvm::CallInst / llvm::InvokeInst. These structures will contain the call target, and the set of actual parameter values passed to that call target in that call which you can access using getArgumentNo. So

f(42)

will be represented using a llvm::CallInst which has 42 as the 0th argument. At runtime, of course, the actual parameter values will be bound to formal parameter values in the usual sense during the control transfer corresponding to the call.

-- Sanjoy

On Tue, Jul 28, 2015 at 6:21 PM, Zhen Zhang <izgzhen at gmail.com> wrote:

Hi,

I am doing a project involving checking a called specific function’s argument. Suppose that the function is int f(const char* str). When I am analyzing such a snippet: f("hello") , then compiled by Clang, I will have the “hello” as a Constant Array in the IR code. My goal is to call APIs of LLVM to get the “hello” from IR code. Now suppose the I got the llvm::Function* fn from some Module, so I can get the access the ArgumentList by iterator constargiterator it. However, the iterator now I got is of type llvm::ilistiterator::constiterator. When I am trying to cast it into `llvm::ilistiterator::constiterator, it can’t success. But if I get the raw pointer out of it, the program will simply crash. While Argument inherits Value, ConstantArray inherits Value as well. But how should I cast one into another? It is worth nothing that, hen I used getType()->getTypeID(), it is ConstantArrayVal, and that seems to be the right direction. Thanks for any help!

- Zhen


LLVM Developers mailing list LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev



More information about the llvm-dev mailing list