<div dir="ltr"><div><div><div><div><div><div><div><div><div>Hello,<br><br></div>I am trying to create IR block for making a call to function pointer.<br></div><div>For creating the IR for a function call to "foo", with "foo" being defined as "void foo(int)", I can use the "getOrInsertFunction" call from Module class as follows:<br><br>  std::vector<Type*> FooArgs;<br>  FooArgs.push_back(IRB.getInt64Ty());<br>  Value *FooFunction = M.getOrInsertFunction(std::string("foo"),<br>                                         FunctionType::get(IRB.getVoidTy(), ArrayRef<Type*>(FooArgs), false));<br>  IRB.CreateCall(FooFunction, IRB.CreateLoad(LenAlloca));<br><br></div><div>I want to create a similar call, but to the pointer of foo ("foo_ptr" is defined as "(void) *foo_ptr (int)"). In C code, I would just call "foo_ptr(var)", and it would just work. But, replacing the function name with the name of the function pointer, in the IRBlock does not work:<br><br>  std::vector<Type*> FooArgs;<br>  FooArgs.push_back(IRB.getInt64Ty());<br>  Value *FooFunctionPtr = M.getOrInsertFunction(std::string("foo_ptr"),<br>                                         FunctionType::get(IRB.getVoidTy(), ArrayRef<Type*>(FooArgs), false));<br>  IRB.CreateCall(FooFunctionPtr, IRB.CreateLoad(LenAlloca));<br><br></div><div>IRBlocks generated from the above crashes. <br>I see the LLVM blocks generated for a sample call to function pointer. It looks as follows:<br><br>  %4 = load void (i64)** @foo_ptr, align 8, !dbg !26<br>  %call = call i32 %4(i32 %3), !dbg !26<br><br></div><div>What LLVM function calls should be used to generate the above IR blocks?<br><br></div><div>Thanks,<br></div><div>Avi.<br></div></div></div></div></div></div></div></div></div>