mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-09-24 23:28:41 +00:00
Fix a bug where RecursivelyDeleteTriviallyDeadInstructions could
delete the instruction pointed to by CGP's current instruction iterator, leading to a crash on the testcase. This fixes PR9578. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@129200 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -889,11 +889,26 @@ bool CodeGenPrepare::OptimizeMemoryInst(Instruction *MemoryInst, Value *Addr,
|
||||
|
||||
MemoryInst->replaceUsesOfWith(Repl, SunkAddr);
|
||||
|
||||
// If we have no uses, recursively delete the value and all dead instructions
|
||||
// using it.
|
||||
if (Repl->use_empty()) {
|
||||
// This can cause recursive deletion, which can invalidate our iterator.
|
||||
// Use a WeakVH to hold onto it in case this happens.
|
||||
WeakVH IterHandle(CurInstIterator);
|
||||
BasicBlock *BB = CurInstIterator->getParent();
|
||||
|
||||
RecursivelyDeleteTriviallyDeadInstructions(Repl);
|
||||
// This address is now available for reassignment, so erase the table entry;
|
||||
// we don't want to match some completely different instruction.
|
||||
SunkAddrs[Addr] = 0;
|
||||
|
||||
if (IterHandle != CurInstIterator) {
|
||||
// If the iterator instruction was recursively deleted, start over at the
|
||||
// start of the block.
|
||||
CurInstIterator = BB->begin();
|
||||
SunkAddrs.clear();
|
||||
} else {
|
||||
// This address is now available for reassignment, so erase the table
|
||||
// entry; we don't want to match some completely different instruction.
|
||||
SunkAddrs[Addr] = 0;
|
||||
}
|
||||
}
|
||||
++NumMemoryInsts;
|
||||
return true;
|
||||
|
Reference in New Issue
Block a user