assertion in LeakDetector

I am seeing the following assertion in leak detector.

void<unnamed>::LeakDetectorImpl<T>::addGarbage(const T*) [with T =
void]: Assertion `Ts.count(Cache) == 0 && "Object already in set!"'

I am creating a list of instructions using BuildMI() and adding them
to a basic block using BB->insert(). I am seeing this assertion after
some number of insertions. Am I doing something wrong?


Hi Manjunath,

If you are using BuildMI(), you shouldn't have to re-insert the
instruction into the machine basic block.


Hi Bill,

I am using the following version of BuildMI :

MachineInstrBuilder BuildMI(MachineFunction &MF,
                                    const TargetInstrDesc &TID,
                                    unsigned DestReg)

I do the following :

void createInstrs(std::vector<MachineInstr *>& ilist)
  Machine Instr *mi;

  mi = BuildMI(MF, someTID, somereg);
  mi = BuildMI(MF, someotherTID, someotherreg);

viud insertInto(MachineBasicBlock *BB, MachineBasicBlock::iterator II)
   std::vector<MachineInstr *> temp;

   for(unsigned i=0, e=temp.size(); i!=e; ++i)
     BB->insert(II, temp[i]);

I am getting the assertion during BB->insert()


Hi Manjunath,

Yep! It's putting them into the basic block for you. Though perhaps
not exactly where you want them to be.

You probably want to use this version of BuildMI:

/// BuildMI - This version of the builder inserts the newly-built
/// instruction before the given position in the given
MachineBasicBlock, and
/// sets up the first operand as a destination virtual register.
inline MachineInstrBuilder BuildMI(MachineBasicBlock &BB,
                                   MachineBasicBlock::iterator I,
                                   DebugLoc DL,
                                   const TargetInstrDesc &TID,
                                   unsigned DestReg);

in the 'createInstrs' function and *don't* run the 'for' loop to
re-insert them into the basic block.