[LLVMdev] Changing basic blocks

Chris Lattner sabre at nondot.org
Thu Aug 16 10:01:46 PDT 2007


On Wed, 15 Aug 2007, [ISO-8859-1] Emílio Wuerges wrote:
> --
> int total = BB->size();
> std::vector<MachineInstr*> positionmap(total);
>  for (int i = 0; i< total; ++i)
>    positionmap.push_back(BB->remove(BB->begin()));
>  for(int i = 0; i< total; ++i)
>    BB->push_back(positionmap[i]);
> --

This doesn't do what you think.  This line:

std::vector<MachineInstr*> positionmap(total);

Creates a vector with "total" null elements in it, it doesn't reserve 
space.  This means that this loop:
   for(int i = 0; i< total; ++i)
     BB->push_back(positionmap[i]);

Inserts all these nulls into the BB.  I'm surprised this doesn't explode.

-Chris

-- 
http://nondot.org/sabre/
http://llvm.org/


More information about the llvm-dev mailing list