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? -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20130211/6a044cde/attachment.html>
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.
[please keep the discussion on-list, thanks] Blind Faith <person.of.book at 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.
Possibly Parallel Threads
- How to efficiently extract the calledFunction from a complex CallInst?
- [LLVMdev] Patch: MSIL backend global pointers initialization
- [LLVMdev] Patch: MSIL backend global pointers initialization
- [LLVMdev] Return Type of Call Function with nested bitcast
- [LLVMdev] [LLVMDEV]How could I get function name in this situation?