Question about function arguments

Hello All,

I was wondering how I could determine the values of function arguments using the iterators defined in Function.cpp.

Any advice or hints would be great…!

Basically, what I am trying out is:

Function foo has the following function body:
int foo(int a, int b) {

}

Function * f = module->getFunction(“foo”);

Function::arg_iterator start = f->arg_begin();
Function::arg_iterator end = f->arg_end();

while(start != end) {
Argument * value = (Argument *)start;
cout << "\n Argument: << value->getNameStr();
start++;
}

This piece of code works if ‘module’ contains the definition of function foo. Otherwise, I just get blanks even though the number returned by arg_size() is two.

If foo is just a function being called from ‘module’, then how do I determine the arguments.

Hi Hemanth,

I was wondering how I could determine the values of function arguments
using the iterators defined in Function.cpp.

are you sure you aren't confusing values and names? In something like
this
   int foo(int a, int b)
there are names "a" and "b". To make it easier for humans to read LLVM
IR, most front-ends will use the same names for the function arguments
in the LLVM IR. But names are entirely optional, and everything works
fine if all function arguments are nameless. So in general you can't hope
to extract "a" and "b" from the LLVM IR.

What do you want the names for? They aren't needed to use and manipulate
arguments.

This piece of code works if 'module' contains the definition of function
foo. Otherwise, I just get blanks even though the number returned by
arg_size() is two.

No names :slight_smile:

Ciao,

Duncan.

Hi Duncan,

Thanks for the clarification. My doubt is to know how I can extract the values contained in the arguments from LLVM IR.

Thanks,
Hemanth

Hi Hemanth,

Thanks for the clarification. My doubt is to know how I can extract the
values contained in the arguments from LLVM IR.

the argument *is* the value, it doesn't need to be extracted: just pass
the argument as an operand when creating your instruction.

Ciao,

Duncan.