[LLVMdev] FunctionType as a function argument

Jeffrey Yasskin jyasskin at google.com
Mon Nov 29 10:44:34 PST 2010


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>


More information about the llvm-dev mailing list