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); } 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); 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 -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20130103/0b1b5c1c/attachment.html>
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 >
Thanks Duncan. I have noticed that in the older LLVM, the code is passing double pointer as un-initialized: Value **Opts; CallInst::Create(func, Opts, Opts , "", newBB); Is there any alternative of this in llvm3.1 please? --Ahmad -----Original Message----- From: llvmdev-bounces at cs.uiuc.edu [mailto:llvmdev-bounces at cs.uiuc.edu] On Behalf Of Duncan Sands Sent: 03 January 2013 15:46 To: llvmdev at cs.uiuc.edu Subject: Re: [LLVMdev] Opt error 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 >_______________________________________________ LLVM Developers mailing list LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev