[LLVMdev] Opt error

Duncan Sands baldrick at free.fr
Thu Jan 3 07:45:40 PST 2013


Hi Ahmad,

On 03/01/13 16:26, Hassan, Ahmad wrote:
> Hi Team,
>
> I am migrating one of the Pass that was written for llvm2.2 or older to llvm3.1.
>   The code snippet looks like the following:
>
> Constant *func;
>
> void add( Module *M) {
>
> func = M->getOrInsertFunction("func",  Type::getVoidTy(M->getContext()), NULL);

this function has no parameters and doesn't return a result.

>
> }
>
> virtual bool runOnModule(Module &M) {
>
>                 add (&M);
>
> for(Module::iterator F = M.begin(), E = M.end(); F != E; ++F) {
>
>          Function *fun = dyn_cast<Function>(F);
>
>           Value *Opts[1];
>
>          BasicBlock &bb = F->getEntryBlock(), *newBB;
>
>            newBB = BasicBlock::Create(M.getContext(), "initfunc", F, &bb);
>
> *CallInst::Create(func, makeArrayRef(Opts, 1) , "", newBB);*

But here you pass it an argument.  Note you don't need makeArrayRef, you can
just pass Opts.  It will be magically turned into an ArrayRef.

Ciao, Duncan.

PS: Opts[1] is not initialized, this will cause problems!

>
>            BranchInst::Create(&bb, newBB);
>
> }
>
> }
>
> The pass compiles fine but when I use ‘opt’ to instrument a simple C program
> then I get the following exception:
>
> $ opt -o a.bc -load /data/llvm3.1/Release+Asserts/lib/Dat.so  -MyPass < malloc.bc
>
> opt: Instructions.cpp:269: void llvm::CallInst::init(llvm::Value*,
> llvm::ArrayRef<llvm::Value*>, const llvm::Twine&): Assertion `(Args.size() ==
> FTy->getNumParams() || (FTy->isVarArg() && Args.size() > FTy->getNumParams()))
> && "Calling a function with bad signature!"' failed.
>
> In older llvm, I had the following line:
>
> *CallInst::Create(func, Opts, Opts , "", newBB);*
>
> Which I have now modified for llvm3.1 to:
>
> *CallInst::Create(func, makeArrayRef(Opts, 1) , "", newBB);*
>
> **
>
> Please can anyone tell the reason of this opt error?
>
> Thanks.
>
> --Ahmad
>
>
>
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
>




More information about the llvm-dev mailing list