[LLVMdev] How to get type of a call instruction

Óscar Fuentes ofv at wanadoo.es
Mon Feb 11 03:54:16 PST 2013


Blind Faith <person.of.book at 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.




More information about the llvm-dev mailing list