[LLVMdev] Passing an array to an external function

Rick Mann rmann at latencyzero.com
Sun Jan 27 15:50:55 PST 2013


Hmm.

So, I made a change to my copy of release_32 to show the types involved when you get that assertion. I wish the LLVM philosophy was more in line with that notion, reporting all the little details when there's an issue (not to mention using lots of temporaries so you can step through it in the debugger more easily).

Replace the init() method on line 265 in release_32/lib/VMCore/Instructions.cpp with this:

	http://pastebin.com/QKjtGzvu

You can see how your passed parameter differs from what the function expects. You might be able to use a bitcast instruction instead.

-- 
Rick

On Jan 27, 2013, at 9:05 , SArora <silkyar at umich.edu> wrote:

> Hi,
> 
> I tried passing the array directly using and changing the
> getorInsertFunction accordingly but this didn't work. It fails with
> Assertion `(i >= FTy->getNumParams() || FTy->getParamType(i) ==
> Args[i]->getType()) && "Calling a function with a bad signature!"' failed. 
> 
> hookFunc = M.getOrInsertFunction("hook", Type::getVoidTy(M.getContext()),  
> llvm::ArrayType::get(llvm::Type::getInt32Ty(M.getContext()),2), (Type*)0);
> .....
> Args[0] =
> ConstantArray::get(llvm::ArrayType::get(llvm::Type::getInt32Ty(BI->getContext()),2),
> arr);
> 
> I tried using index 0 in the GEP, but it fails with
> 
> 7  opt             0x00000000006c59f5 bool llvm::isa<llvm::Constant,
> llvm::Value*>(llvm::Value* const&) + 24
> 8  opt             0x00000000006c5a0f llvm::cast_retty<llvm::Constant,
> llvm::Value*>::ret_type llvm::cast<llvm::Constant,
> llvm::Value*>(llvm::Value* const&) + 24
> 9  opt             0x0000000000b2b22f
> 10 opt             0x0000000000b2a4fe
> llvm::ConstantFoldGetElementPtr(llvm::Constant*, bool,
> llvm::ArrayRef<llvm::Value*>) + 55
> 11 opt             0x0000000000b33df2
> llvm::ConstantExpr::getGetElementPtr(llvm::Constant*,
> llvm::ArrayRef<llvm::Value*>, bool) + 82
> 
> Probably the ConstantArray could't be casted to Value*. Any ideas? 
> Thanks!
> 
> 
> 
> 
> --
> View this message in context: http://llvm.1065342.n5.nabble.com/Passing-an-array-to-an-external-function-tp54208p54220.html
> Sent from the LLVM - Dev mailing list archive at Nabble.com.
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev


-- 
Rick







More information about the llvm-dev mailing list