Hi all. I would like to declare a function that takes a function pointer as an argument. In C, it would be : void execute(char (*func)(void*), void *param) So, in my compiler, I have : std::vector<const Type *> cbFPtrArgs(1, Type::getInt8PtrTy(C)); FunctionType * cbFPtrTy = FunctionType::get(Type::getInt8Ty(C), cbFPtrArgs, false); Function * func = cast<Function>(M->getOrInsertFunction(fName, Type::getInt32Ty(C), cbFPtrTy, Type::getInt8PtrTy(C), (Type *)0)); But then I get an error form LLVM : /home/salomon/AppSRC/LLVM/release_28/lib/VMCore/Type.cpp:456: llvm::FunctionType::FunctionType(llvm::Type const *, std::vector<llvm::Type const *> const &, bool): Assertion `isValidArgumentType(Params[i]) && "Not a valid type for function argument!"' failed. It seems that a FunctionType is not a valide function argument type. Does someone know what am I missing ? Thank you very much for your help. -- -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20101129/dedbf0ce/attachment.html>
You need a pointer-to-function type, but FunctionType just gives you a function type. Use PointerType::getUnqual(FunctionType::get(...)). Or TypeBuilder<char (*func)(void*), false>::get(context) from Support/TypeBuilder.h. On Mon, Nov 29, 2010 at 10:37 AM, Salomon Brys <salomon.brys at gmail.com>wrote:> Hi all. > I would like to declare a function that takes a function pointer as an > argument. > In C, it would be : > > void execute(char (*func)(void*), void *param) > > So, in my compiler, I have : > std::vector<const Type *> cbFPtrArgs(1, Type::getInt8PtrTy(C)); > FunctionType * cbFPtrTy = FunctionType::get(Type::getInt8Ty(C), > cbFPtrArgs, false); > Function * func = cast<Function>(M->getOrInsertFunction(fName, > Type::getInt32Ty(C), cbFPtrTy, Type::getInt8PtrTy(C), (Type *)0)); > > But then I get an error form LLVM : > /home/salomon/AppSRC/LLVM/release_28/lib/VMCore/Type.cpp:456: > llvm::FunctionType::FunctionType(llvm::Type const *, std::vector<llvm::Type > const *> const &, bool): Assertion `isValidArgumentType(Params[i]) && "Not a > valid type for function argument!"' failed. > > It seems that a FunctionType is not a valide function argument type. > Does someone know what am I missing ? > > Thank you very much for your help. > > -- > > > > > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev > >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20101129/19055e90/attachment.html>
That would be TypeBuilder<char (*)(void*), false>... On Mon, Nov 29, 2010 at 10:44 AM, Jeffrey Yasskin <jyasskin at google.com>wrote:> You need a pointer-to-function type, but FunctionType just gives you a > function type. Use PointerType::getUnqual(FunctionType::get(...)). Or > TypeBuilder<char (*func)(void*), false>::get(context) from > Support/TypeBuilder.h. > > On Mon, Nov 29, 2010 at 10:37 AM, Salomon Brys <salomon.brys at gmail.com>wrote: > >> Hi all. >> I would like to declare a function that takes a function pointer as an >> argument. >> In C, it would be : >> >> void execute(char (*func)(void*), void *param) >> >> So, in my compiler, I have : >> std::vector<const Type *> cbFPtrArgs(1, Type::getInt8PtrTy(C)); >> FunctionType * cbFPtrTy = FunctionType::get(Type::getInt8Ty(C), >> cbFPtrArgs, false); >> Function * func = cast<Function>(M->getOrInsertFunction(fName, >> Type::getInt32Ty(C), cbFPtrTy, Type::getInt8PtrTy(C), (Type *)0)); >> >> But then I get an error form LLVM : >> /home/salomon/AppSRC/LLVM/release_28/lib/VMCore/Type.cpp:456: >> llvm::FunctionType::FunctionType(llvm::Type const *, std::vector<llvm::Type >> const *> const &, bool): Assertion `isValidArgumentType(Params[i]) && "Not a >> valid type for function argument!"' failed. >> >> It seems that a FunctionType is not a valide function argument type. >> Does someone know what am I missing ? >> >> Thank you very much for your help. >> >> -- >> >> >> >> >> _______________________________________________ >> LLVM Developers mailing list >> LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu >> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev >> >> >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20101129/c2b309f4/attachment.html>
Hi Salomon,> FunctionType * cbFPtrTy = FunctionType::get(Type::getInt8Ty(C), cbFPtrArgs, false);in spite of the name you gave it, this is not a pointer type.> Function * func = cast<Function>(M->getOrInsertFunction(fName, > Type::getInt32Ty(C), cbFPtrTy, Type::getInt8PtrTy(C), (Type *)0));You need to pass a pointer-to-function type, not a function type. Ciao, Duncan.