How to get type of a call instruction

I need to get the type of a call instruction to typecast a (void*) pointer to the type of the function which is called. How can I achieve that?

Blind Faith <person.of.book@gmail.com> writes:

I need to get the type of a call instruction to typecast a (void*) pointer
to the type of the function which is called. How can I achieve that?

CallInst::getType ?

CallInst is derived from Value, Value's have a type, which you obtain
with getType method.

Then you use BitCastInst for the typecast.

But maybe you are not talking about the type of the value returned by
the call, but the type of the called function (you want to typecast a
void* to a function pointer.) Then you use CallInst::getCalledFunction
and Function::getFunctionType. Finally, you need BitCastInst for the
typecast.

The Doxygen documentation is handy for that. Using clang & opt for
looking at the llvm assembly and/or LLVM C++ API representation helps a
lot too.

[please keep the discussion on-list, thanks]

Blind Faith <person.of.book@gmail.com> writes:

CallInst::getCalledFunction followed by Function::getFunctionType does not
work for indirect calls, because getCalledFunction returns NULL for
indirect calls, and my focus is indirect calls. Any idea how to get the
Function Type from indirect calls?

Maybe CallInst::getCalledValue ?

getCalledValue - Get a pointer to the function that is invoked by this instruction

Note that it returns a Value*, not a Function*.

Then you can use Value::getType.