FunctionType as a function argument

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(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.

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.

That would be TypeBuilder<char ()(void), false>…

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.