'Return Value of the CallInst

I need help with the llvm code to find the return value of the Call instruction and pass it as a parameter to another function.

I tried iterating the instruction to find the isa and callinst being the value itself i tried mapping it directly as a parameter but i am getting an error.

the following code of mine fails during runtime.

if(isa<CallInst>(I))
{
CallInst *ci = dyn_cast<CallInst>(&I);
IRBuilder<> builder(ci);
builder.SetInsertPoint(&B, builder.GetInsertPoint());
const DebugLoc Debug = I.getDebugLoc();
int x = Debug.getLine();
int y = Debug.getCol();
Value * rhs = ConstantInt::get(Type::getInt32Ty(F.getContext()),x, true);
Value * lhs = ConstantInt::get(Type::getInt32Ty(F.getContext()),y, true);;
Value *args1[3] = {rhs,lhs,ci};
builder.CreateCall(hook1, args1);  //hook1 is the function in a runtime c program which accepts 3 parametes all int.

}

Error Message:

0x135eef8
Stack dump:
0.  Program arguments: opt -load ../build/CBIInstrumentPass.so -CBIInstrument -S fuzz2.instrumented.ll -o fuzz2.cbi.instrumented.ll 
1.  Running pass 'Function Pass Manager' on module 'fuzz2.instrumented.ll'.
2.  Running pass 'Instrumentations for CBI' on function '@xval'
/usr/lib/x86_64-linux-gnu/libLLVM-8.so.1(_ZN4llvm3sys15PrintStackTraceERNS_11raw_ostreamE+0x1f)[0x7f274917c4bf]
/usr/lib/x86_64-linux-gnu/libLLVM-8.so.1(_ZN4llvm3sys17RunSignalHandlersEv+0x50)[0x7f274917a910]
/usr/lib/x86_64-linux-gnu/libLLVM-8.so.1(+0x9728c8)[0x7f274917c8c8]
/lib/x86_64-linux-gnu/libpthread.so.0(+0x128a0)[0x7f274c4698a0]
/usr/lib/x86_64-linux-gnu/libLLVM-8.so.1(_ZNK4llvm8DebugLoc7getLineEv+0x3)[0x7f2749219d43]
../build/CBIInstrumentPass.so(_ZN10instrument13CBIInstrument13runOnFunctionERN4llvm8FunctionE+0x66e)[0x7f2746c3fcaa]
/usr/lib/x86_64-linux-gnu/libLLVM-8.so.1(_ZN4llvm13FPPassManager13runOnFunctionERNS_8FunctionE+0x3f0)[0x7f274926f7f0]
/usr/lib/x86_64-linux-gnu/libLLVM-8.so.1(_ZN4llvm13FPPassManager11runOnModuleERNS_6ModuleE+0x33)[0x7f274926fa63]
/usr/lib/x86_64-linux-gnu/libLLVM-8.so.1(_ZN4llvm6legacy15PassManagerImpl3runERNS_6ModuleE+0x2ee)[0x7f274926fe2e]
opt(main+0x2cf8)[0x4bb7e8]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xe7)[0x7f2747afbb97]
opt(_start+0x2a)[0x4a5efa]
Segmentation fault (core dumped)


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source