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

<br><div class="gmail_quote">On Mon, Nov 29, 2010 at 10:37 AM, Salomon Brys <span dir="ltr"><<a href="mailto:salomon.brys@gmail.com">salomon.brys@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">

<font face="arial,helvetica,sans-serif">Hi all.</font><div><font face="arial,helvetica,sans-serif">I would like to declare a function that takes a function pointer as an argument.</font></div><div><font face="arial, helvetica, sans-serif">In C, it would be :</font></div>



<div><font face="arial, helvetica, sans-serif"><br></font></div><div><font face="arial, helvetica, sans-serif">void execute(char (*func)(void*), void *param)</font></div>
<div>
<font face="arial, helvetica, sans-serif"><br></font></div><div><font face="arial, helvetica, sans-serif">So, in my compiler, I have :</font></div><div><div><font face="'courier new', monospace"><span style="white-space:pre-wrap">  </span>std::vector<const Type *> cbFPtrArgs(1, Type::getInt8PtrTy(C));</font></div>



<div><font face="'courier new', monospace"><span style="white-space:pre-wrap">    </span>FunctionType * cbFPtrTy = FunctionType::get(Type::getInt8Ty(C), cbFPtrArgs, false);</font></div>

<div><font face="'courier new', monospace"><span style="white-space:pre-wrap">    </span>Function * func = cast<Function>(M->getOrInsertFunction(fName, Type::getInt32Ty(C), cbFPtrTy, Type::getInt8PtrTy(C), (Type *)0));</font></div>



<div style="font-family:arial, helvetica, sans-serif"><br></div><div style="font-family:arial, helvetica, sans-serif">But then I get an error form LLVM :</div><div><font face="'courier new', monospace">/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.</font></div>



<div style="font-family:arial, helvetica, sans-serif"><br></div><div style="font-family:arial, helvetica, sans-serif">It seems that a FunctionType is not a valide function argument type.</div><div style="font-family:arial, helvetica, sans-serif">



Does someone know what am I missing ?</div><div style="font-family:arial, helvetica, sans-serif"><br></div><div style="font-family:arial, helvetica, sans-serif">Thank you very much for your help.</div></div>

<div><br>-- <br><font face="'courier new', monospace" color="#666666"><div><br></div><div> <img><br></div></font><br>
</div>
<br>_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:LLVMdev@cs.uiuc.edu">LLVMdev@cs.uiuc.edu</a>         <a href="http://llvm.cs.uiuc.edu" target="_blank">http://llvm.cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br>
<br></blockquote></div><br>