You may be invalidating the BasicBlock::iterator by removing
instructions while iterating through the instructions in the
BasicBlock. One way to fix this would be to iterate through the
BasicBlock and record in a std::vector<> all the instructions that
should be removed. Then you can write a loop that removes the last
element of the std::vector, erases it, and then repeats until the
std::vector is empty.
Also, just to note, it looks like your code is not checking whether the
LoadInst is volatile before deleting it. Your transform should not
remove volatile LoadInst or StoreInst instructions, even if they appear
dead.
-- John T.
_______________________________________________
LLVM Developers mailing list
LLV...@cs.uiuc.edu http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
The problem is in how you use it:
for (BasicBlock::iterator I = BB->begin(), E = BB->end(); I != E;
I++) {
if (I->use_empty() && dyn_cast<LoadInst>(I)) {
errs() << "*****Instruction unused*****" << "\n";
errs() << *I << "\n";
EraseInst(*I);
}
}
Once you call EraseInst, you can't use it again in the I++ part of your
for loop. You'll have to restructure your loop so that you increment
before erasing your instruction, and erase the one you haven't
incremented yet.
Nick
>
> So please, if anyone could help me on this, i would be very grateful!
>
> PS: It's also following my pass and the bytecode used for tests.
>
> Thanks for the attention,
> Alysson
>
>
>