Skip to content

Commit b308daf

Browse files
committed
[SILOpt] fix the ASAN issue in the new pass completely.
LLVM's ilist::erase is actually correct. It just implements a nonstandard remove method that modifies it's iterator argument. I forgot to add "continue" statements when fixing the iterator-invalidation problem.
1 parent 5659f48 commit b308daf

File tree

4 files changed

+5
-7
lines changed

4 files changed

+5
-7
lines changed

lib/SIL/SILBasicBlock.cpp

+3-5
Original file line numberDiff line numberDiff line change
@@ -90,16 +90,14 @@ void SILBasicBlock::remove(SILInstruction *I) {
9090
InstList.remove(I);
9191
}
9292

93-
/// Returns the iterator following the erased instruction, STL-style.
93+
/// Returns the iterator following the erased instruction.
9494
SILBasicBlock::iterator SILBasicBlock::erase(SILInstruction *I) {
9595
// Notify the delete handlers that this instruction is going away.
9696
getModule().notifyDeleteHandlers(&*I);
9797
auto *F = getParent();
98-
// LLVM does not currently implement ilist::erase correctly. Compensate.
99-
iterator next = std::next(SILBasicBlock::iterator(I));
100-
InstList.erase(I);
98+
auto nextIter = InstList.erase(I);
10199
F->getModule().deallocateInst(I);
102-
return next;
100+
return nextIter;
103101
}
104102

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

lib/SILOptimizer/Mandatory/AccessMarkerElimination.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,12 @@ struct AccessMarkerElimination : SILModuleTransform {
5252
if (auto beginAccess = dyn_cast<BeginAccessInst>(inst)) {
5353
beginAccess->replaceAllUsesWith(beginAccess->getSource());
5454
II = BB.erase(beginAccess);
55+
continue;
5556
}
5657
if (auto endAccess = dyn_cast<EndAccessInst>(inst)) {
5758
assert(endAccess->use_empty());
5859
II = BB.erase(endAccess);
60+
continue;
5961
}
6062
}
6163
}

test/SILOptimizer/access_marker_elim.sil

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
// RUN: %target-sil-opt -enforce-exclusivity=checked -emit-sorted-sil -access-marker-elim %s | %FileCheck %s
2-
// REQUIRES: rdar:31550303 OSS Swift CI ASAN bot fails on AccessMarker tests.
32

43
sil_stage raw
54

test/SILOptimizer/access_marker_mandatory.swift

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
// RUN: %target-swift-frontend -parse-as-library -Xllvm -sil-full-demangle -enforce-exclusivity=checked -emit-sil %s | %FileCheck %s
2-
// REQUIRES: rdar:31550303 OSS Swift CI ASAN bot fails on AccessMarker tests.
32

43
public struct S {
54
var i: Int

0 commit comments

Comments
 (0)