Get arguments of a function (bitcast)

Hi All,

I need to get the list of arguments of a function which is bitcasted.

Here is the C code excerpt:

main()
{

/* Get input samples */
input_dsp(input, N, 1);


}

and here is llvm ir for the code section:

%call = call i32 (i32*, i32, i32, …)* bitcast (i32 (…)* @input_dsp to i32 (i32*, i32, i32, …))(i32 getelementptr inbounds ([256 x i32]* @input, i32 0, i32 0), i32 256, i32 1)

When I use the ordinary method for getting arguments,

for (Function::ArgumentListType::iterator it = f->getArgumentList().begin(); it != f->getArgumentList().end(); it++) {…}

i get a segmentation fault which i think i valid. But how can i get arguments of input_dsp which are input, N and 1 in this case.

Best,

Mo

Hi Mo,

Have a look at the Value::stripPointerCasts() method [1] to strip all bitcasts from the function pointer.

-Manuel

[1] http://llvm.org/docs/doxygen/html/classllvm_1_1Value.html#a38ea12c04523d63adda732b9c5d6da0a

Dear Mohammad,

Are you trying to get the formal arguments or the actual arguments?

If you're trying to get the actual arguments, you can use the CallSite class (http://llvm.org/doxygen/classllvm_1_1CallSite.html). Create a local CallSite variable constructed from the Instruction * (in this case, a CallInst). You can then use the getArgument() method to get the various operands to the call site. The CallSite class is nice because it abstracts away details of the CallInst and InvokeInst instructions.

If you want the formal arguments, you need to find the function that the CallInst calls. You can do that as Manual suggests. However, keep in mind that the CallInst may be an indirect call and, therefore, you may not see a Function constant. In that case, you'll need to use a call graph analysis pass (like DSA) to determine which set of functions the CallInst can call.

Regards,

John Criswell