How to get a return type of a function with LLVM-C API

Hi LLVM-ers,

I am trying to get a return type of a function(from bitcode file) with LLVM-C API, but there seems no appropriate API to do that.

I’ve tried to do that with following code,

You’re trying to apply an operation on a Type to a Value; that’s no good, as you say. So you want the return type of the type of the function. But the function value itself is of type %function*, so you have to ‘dereference’ the type first:

LLVMGetReturnType(LLVMGetElementType(LLVMTypeOf(F)))

This may help to clarify: http://llvm.org/docs/ProgrammersManual.html#coreclasses

Hi Syoyo,

I am trying to get a return type of a function(from bitcode file) with
LLVM-C API, but there seems no appropriate API to do that.

the function's type and get the info there.

Looking the the API docs [1], I find that there is a simple method on Function
called getReturnType(). You should thus be able to do:
  Type* rt = F->getReturnType();

Good luck,

Matthijs

[1]: http://llvm.org/doxygen/classllvm_1_1Function.html

Hi Gordon and Matthjis,

I got the return type of the function in success with the way Gordon explained.

RetTy = LLVMGetReturnType(LLVMGetElementType(LLVMTypeOf(F)))

Thanks a lot!