Skip to content

Commit ab2a37b

Browse files
committed
Fix DefiniteInitialization to handle access markers in a few more places.
1 parent 00b5a9d commit ab2a37b

File tree

1 file changed

+27
-8
lines changed

1 file changed

+27
-8
lines changed

lib/SILOptimizer/Mandatory/DIMemoryUseCollectorOwnership.cpp

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1112,7 +1112,9 @@ void ElementUseCollector::collectClassSelfUses() {
11121112
// 4) Potential escapes after super.init, if self is closed over.
11131113
//
11141114
// Handle each of these in turn.
1115-
for (auto *Op : MUI->getUses()) {
1115+
SmallVector<Operand *, 8> Uses(MUI->getUses());
1116+
while (!Uses.empty()) {
1117+
Operand *Op = Uses.pop_back_val();
11161118
SILInstruction *User = Op->getUser();
11171119

11181120
// Stores to self.
@@ -1150,6 +1152,14 @@ void ElementUseCollector::collectClassSelfUses() {
11501152
if (isa<EndBorrowInst>(User))
11511153
continue;
11521154

1155+
// Recurse through begin_access.
1156+
if (auto *beginAccess = dyn_cast<BeginAccessInst>(User)) {
1157+
Uses.append(beginAccess->getUses().begin(), beginAccess->getUses().end());
1158+
continue;
1159+
}
1160+
if (isa<EndAccessInst>(User))
1161+
continue;
1162+
11531163
// Loads of the box produce self, so collect uses from them.
11541164
if (isa<LoadInst>(User) || isa<LoadBorrowInst>(User)) {
11551165
auto load = cast<SingleValueInstruction>(User);
@@ -1379,8 +1389,8 @@ void ElementUseCollector::collectClassSelfUses(
13791389
continue;
13801390
}
13811391

1382-
// Skip end_borrow.
1383-
if (isa<EndBorrowInst>(User))
1392+
// Skip end_borrow and end_access.
1393+
if (isa<EndBorrowInst>(User) || isa<EndAccessInst>(User))
13841394
continue;
13851395

13861396
// ref_element_addr P, #field lookups up a field.
@@ -1417,10 +1427,9 @@ void ElementUseCollector::collectClassSelfUses(
14171427

14181428
// Look through begin_borrow, upcast, unchecked_ref_cast
14191429
// and copy_value.
1420-
if (isa<BeginBorrowInst>(User) ||
1421-
isa<UpcastInst>(User) ||
1422-
isa<UncheckedRefCastInst>(User) ||
1423-
isa<CopyValueInst>(User)) {
1430+
if (isa<BeginBorrowInst>(User) || isa<BeginAccessInst>(User)
1431+
|| isa<UpcastInst>(User) || isa<UncheckedRefCastInst>(User)
1432+
|| isa<CopyValueInst>(User)) {
14241433
auto value = cast<SingleValueInstruction>(User);
14251434
std::copy(value->use_begin(), value->use_end(),
14261435
std::back_inserter(Worklist));
@@ -1498,14 +1507,24 @@ void DelegatingInitElementUseCollector::collectClassInitSelfUses() {
14981507
// 4) Potential escapes after super.init, if self is closed over.
14991508
// Handle each of these in turn.
15001509
//
1501-
for (auto *Op : MUI->getUses()) {
1510+
SmallVector<Operand *, 8> Uses(MUI->getUses());
1511+
while (!Uses.empty()) {
1512+
Operand *Op = Uses.pop_back_val();
15021513
SILInstruction *User = Op->getUser();
15031514

15041515
// Ignore end_borrow. If we see an end_borrow it can only come from a
15051516
// load_borrow from ourselves.
15061517
if (isa<EndBorrowInst>(User))
15071518
continue;
15081519

1520+
// Recurse through begin_access.
1521+
if (auto *beginAccess = dyn_cast<BeginAccessInst>(User)) {
1522+
Uses.append(beginAccess->getUses().begin(), beginAccess->getUses().end());
1523+
continue;
1524+
}
1525+
if (isa<EndAccessInst>(User))
1526+
continue;
1527+
15091528
// Stores to self.
15101529
if (auto *SI = dyn_cast<StoreInst>(User)) {
15111530
if (Op->getOperandNumber() == 1) {

0 commit comments

Comments
 (0)