Skip to content

Commit dab44e3

Browse files
committed
Fix LexicalDestroyHoisting: avoid optimizing when ownership escapes
Fix the utilities used by LexicalDestroyHoisting that finds all uses to report a "PointerEscape". We can't rely on lifetime analysis when such a use is present.
1 parent 17e3cf0 commit dab44e3

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

lib/SIL/Utils/OwnershipUtils.cpp

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -377,19 +377,26 @@ bool swift::findExtendedUsesOfSimpleBorrowedValue(
377377
return true;
378378
}
379379

380+
// TODO: refactor this with SSAPrunedLiveness::computeLiveness.
380381
bool swift::findUsesOfSimpleValue(SILValue value,
381382
SmallVectorImpl<Operand *> *usePoints) {
382383
for (auto *use : value->getUses()) {
383-
if (use->getOperandOwnership() == OperandOwnership::Borrow) {
384+
switch (use->getOperandOwnership()) {
385+
case OperandOwnership::PointerEscape:
386+
return false;
387+
case OperandOwnership::Borrow:
384388
if (!BorrowingOperand(use).visitScopeEndingUses([&](Operand *end) {
385-
if (end->getOperandOwnership() == OperandOwnership::Reborrow) {
386-
return false;
387-
}
388-
usePoints->push_back(end);
389-
return true;
390-
})) {
389+
if (end->getOperandOwnership() == OperandOwnership::Reborrow) {
390+
return false;
391+
}
392+
usePoints->push_back(end);
393+
return true;
394+
})) {
391395
return false;
392396
}
397+
break;
398+
default:
399+
break;
393400
}
394401
usePoints->push_back(use);
395402
}

0 commit comments

Comments
 (0)