[LLVMdev] Instruction insertion By Module Pass

John Criswell criswell at illinois.edu
Tue Jul 30 07:01:21 PDT 2013


On 7/30/13 7:44 AM, Rasha Omar wrote:
> Hi,
> I need to insert new instruction into every basic block like x=1
> or while loop
> I tried this code, but it doesn't work
>
> Type * Int32Type = IntegerType::getInt32Ty(getGlobalContext());
>  AllocaInst* newInst = new AllocaInst(Int32Type,"flag", Bb);
>  Bb->getInstList().push_back(newInst);

The problem is that you've inserted the AllocaInst into the basic block 
via the AllocaInst constructor (note the Bb at the end of the line with 
new AllocaInst).  You then attempt to insert the AllocaInst into the 
BasicBlock Bb a second time with the last line. Note that the assertion 
is telling you that you're inserting the alloca instruction twice.

Remove the last line, and it should fix your problem.

-- John T.

>
> the error:
> void llvm::SymbolTableListTraits<llvm::Instruction, 
> llvm::BasicBlock>::addNodeToList(ValueSubClass *) [ValueSubClass = 
> llvm::Instruction, ItemParentClass = llvm::BasicBlock]: Assertion 
> `V->getParent() == 0 && "Value already in a container!!"' failed.
>
>  Is there a class I could use to insert while loop in Module Pass?
>
> Thank you in advance
>
> -- 
> *Rasha Salah Omar
> Msc Student at E-JUST
> Demonestrator  at Faculty of Computers and Informatics
> Benha University*
>
> *e-mail: rasha.omar at ejust.edu.eg <mailto:rasha.omar at ejust.edu.eg>*
>
> P* Please consider the environment before printing this email.*
>
>
>
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20130730/9c01b3b3/attachment.html>


More information about the llvm-dev mailing list