Hi, I'm trying to follow the advice from this message: http://lists.cs.uiuc.edu/pipermail/llvmdev/2008-October/017574.html, to create a call instruction from a function pointer. But I'm getting... Assertion failed: (isa<X>(Val) && "cast<Ty>() argument of incompatible type!"), function cast, file /usr/local/include/llvm/Support/Casting.h, line 202. Code snippets... id testfunc(id a, id b) { ... } ... FunctionType *fn_type = FunctionType::get(id_type, argtypes, false); Value *fn = ConstantExpr::getIntToPtr(ConstantInt::get(int64_type, reinterpret_cast<int64_t>(testfunc)), fn_type); return builder.CreateCall2(fn, arg0val, arg1val); // <-- assertion fails here What am I doing wrong? I can paste more code if needed. thanks, Rob
On Jan 17, 2011, at 5:01 PM, Rob Nikander wrote:> Hi, > > I'm trying to follow the advice from this message: > http://lists.cs.uiuc.edu/pipermail/llvmdev/2008-October/017574.html, > to create a call instruction from a function pointer. But I'm > getting... > > Assertion failed: (isa<X>(Val) && "cast<Ty>() argument of > incompatible type!"), > function cast, file /usr/local/include/llvm/Support/Casting.h, line 202. > > Code snippets... > > id testfunc(id a, id b) { ... } > ... > FunctionType *fn_type = FunctionType::get(id_type, argtypes, false); > Value *fn = ConstantExpr::getIntToPtr(ConstantInt::get(int64_type, > reinterpret_cast<int64_t>(testfunc)), fn_type); > return builder.CreateCall2(fn, arg0val, arg1val); // <-- > assertion fails here > > What am I doing wrong? I can paste more code if needed.One of the types doesn't match the types of what you are trying to pass. You should debug which one it is and why the types aren't matching what you think they should be. -eric -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20110117/aefb7e2e/attachment.html>
On Mon, Jan 17, 2011 at 8:36 PM, Eric Christopher <echristo at apple.com> wrote:> > id testfunc(id a, id b) { ... } > ... > FunctionType *fn_type = FunctionType::get(id_type, argtypes, false); > Value *fn = ConstantExpr::getIntToPtr(ConstantInt::get(int64_type, > reinterpret_cast<int64_t>(testfunc)), fn_type); > return builder.CreateCall2(fn, arg0val, arg1val); // <-- > assertion fails here > > What am I doing wrong? I can paste more code if needed. > > One of the types doesn't match the types of what you are trying to pass. > You should debug which one it is and why the types aren't matching what > you think they should be.Okay, found it. My function was of type: "i8* (i8*, i8*)". I thought that was okay, but now I see it needed to be "i8* (i8*, i8*)*" -- ie, a pointer to the former type. Rob