[LLVMdev] Instruciton replacement

Juan Nicolas Ruiz juanruiz at students.uiuc.edu
Wed Nov 27 17:33:01 PST 2002


llvm is giving me some assertion errors when trying to replace an
instruction, and I'm not quite sure of what to do. I have the
following snippet of code:

switch((*I)->getOpcode()) {
case Instruction::Malloc:
  {
    AllocaInst *AI;
    AI = new AllocaInst(cast<AllocationInst>(*I)->getAllocatedType(),
			cast<AllocationInst>(*I)->getArraySize());
    (*I)->replaceAllUsesWith(AI);
//  (*I)->dropAllReferences();
//  (*I)->getParent()->getInstList().erase(*I);
//  delete (*I);
//  delete(AI);
  }
  break;

running the code will report:

Leaked objects found: after running pass 'move memory objects from the
heap to the stack'
  LLVM Value subclasses leaked: alloca uint             ; <uint*>:<badref> [#uses=2]

This is probably because you removed an LLVM value (Instruction,
BasicBlock, etc), but didn't delete it.  Please check your code for
memory leaks. Assertion failed: slot != -1 && "Broken bytecode!", file
WriteInst.cpp, line 191
Abort

If I uncomment the (delete(AI)) will report:

While deleting: uint *%
Use still stuck around after Def is destroyed:  %reg112 = load uint*
<badref>  ; <uint> [#uses=1]
Use still stuck around after Def is destroyed:  store uint 37337,
uint* <badref>
Assertion failed: Uses.begin() == Uses.end(), file Value.cpp, line 43
Abort

uncommenting the "dropAllReferences() && delete(*I)" reports:

Assertion failed: Parent == 0 && "Instruction still embedded in basic
block!", file ../../../include/llvm/Instruction.h, line 33
Abort

how can I replace the (*I) instruction with a new AI?

thanks.
nicolas




More information about the llvm-dev mailing list