Skip to content

Commit 4ef9465

Browse files
authored
Merge pull request #8668 from atrick/fix
2 parents cfee4d9 + 2eb6d48 commit 4ef9465

File tree

3 files changed

+9
-8
lines changed

3 files changed

+9
-8
lines changed

include/swift/SIL/SILBasicBlock.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public llvm::ilist_node<SILBasicBlock>, public SILAllocated<SILBasicBlock> {
9494
void push_back(SILInstruction *I);
9595
void push_front(SILInstruction *I);
9696
void remove(SILInstruction *I);
97-
void erase(SILInstruction *I);
97+
iterator erase(SILInstruction *I);
9898

9999
SILInstruction &back() { return InstList.back(); }
100100
const SILInstruction &back() const {

lib/SIL/SILBasicBlock.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,13 @@ void SILBasicBlock::remove(SILInstruction *I) {
9090
InstList.remove(I);
9191
}
9292

93-
void SILBasicBlock::erase(SILInstruction *I) {
93+
SILBasicBlock::iterator SILBasicBlock::erase(SILInstruction *I) {
9494
// Notify the delete handlers that this instruction is going away.
9595
getModule().notifyDeleteHandlers(&*I);
9696
auto *F = getParent();
97-
InstList.erase(I);
97+
auto II = InstList.erase(I);
9898
F->getModule().deallocateInst(I);
99+
return II;
99100
}
100101

101102
/// This method unlinks 'self' from the containing SILFunction and deletes it.

lib/SILOptimizer/Mandatory/AccessMarkerElimination.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,17 +45,17 @@ struct AccessMarkerElimination : SILModuleTransform {
4545
// iterating in reverse eliminates more begin_access users before they
4646
// need to be replaced.
4747
for (auto &BB : reversed(F)) {
48-
for (auto II = BB.rbegin(), IE = BB.rend(); II != IE;) {
49-
SILInstruction *inst = &*II;
50-
++II;
48+
// Don't cache the begin iterator since we're reverse iterating.
49+
for (auto II = BB.end(); II != BB.begin();) {
50+
SILInstruction *inst = &*(--II);
5151

5252
if (auto beginAccess = dyn_cast<BeginAccessInst>(inst)) {
5353
beginAccess->replaceAllUsesWith(beginAccess->getSource());
54-
beginAccess->eraseFromParent();
54+
II = BB.erase(beginAccess);
5555
}
5656
if (auto endAccess = dyn_cast<EndAccessInst>(inst)) {
5757
assert(endAccess->use_empty());
58-
endAccess->eraseFromParent();
58+
II = BB.erase(endAccess);
5959
}
6060
}
6161
}

0 commit comments

Comments
 (0)