[LLVMdev] How to use the return value of a CallInst

Óscar Fuentes ofv at wanadoo.es
Mon Jul 26 20:38:12 PDT 2010

Guowei Xu <myesis at gmail.com> writes:

>    I am trying to compare the return value of a call instruction with 0. The
> called function's return type is uint32. The return value is 1 or 0. But the
> icmp instruction cannot be created.
>   CallInst *ret = CallInst::Create(ptr_func, params.begin(), params.end(),
> "", bb);
>   Value *cmp = new ICmpInst(*bb, ICmpInst::ICMP_EQ, ret,
> ,ConstantInt::get(getIntegerType(32), 0) "")
> The runtime error is:
> /usr/local/include/llvm/Instructions.h:690:
> llvm::ICmpInst::ICmpInst(llvm::BasicBlock&, llvm::CmpInst::Predicate,
> llvm::Value*, llvm::Value*, const llvm::Twine&): Assertion
> `getOperand(0)->getType() == getOperand(1)->getType() && "Both operands to
> ICmp instruction are not of the same type!"' failed.
> Aborted
> I don't know how to use the return value of function .

It is possible that you are wrong assuming that the return value of the
function has type int32. Put

errs() << *ret << '\n';

just after the CallInst to see what `ret' really is.

More information about the llvm-dev mailing list