Skip to content

Commit 9a24013

Browse files
authored
Merge pull request #27219 from gottesmm/pr-76c8dc8ebfc577d7be7ce15c158337b575823c2a
2 parents 5c01a11 + 7e3608e commit 9a24013

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
lines changed

include/swift/SIL/OwnershipUtils.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,18 @@ class LinearLifetimeChecker {
170170
ArrayRef<BranchPropagatedUser> nonConsumingUses,
171171
ownership::ErrorBehaviorKind errorBehavior,
172172
SmallVectorImpl<SILBasicBlock *> *leakingBlocks = nullptr);
173+
174+
/// Returns true that \p value forms a linear lifetime with consuming uses \p
175+
/// consumingUses, non consuming uses \p nonConsumingUses. Returns false
176+
/// otherwise.
177+
bool validateLifetime(SILValue value,
178+
ArrayRef<BranchPropagatedUser> consumingUses,
179+
ArrayRef<BranchPropagatedUser> nonConsumingUses) {
180+
return !checkValue(value, consumingUses, nonConsumingUses,
181+
ownership::ErrorBehaviorKind::ReturnFalse,
182+
nullptr /*leakingBlocks*/)
183+
.getFoundError();
184+
}
173185
};
174186

175187
/// Returns true if v is an address or trivial.

lib/SIL/OwnershipUtils.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,5 @@ bool BorrowScopeIntroducingValue::areInstructionsWithinScope(
207207
[&scratchSpace](SILInstruction *i) { scratchSpace.emplace_back(i); });
208208

209209
LinearLifetimeChecker checker(visitedBlocks, deadEndBlocks);
210-
auto result = checker.checkValue(value, scratchSpace, instructions,
211-
ownership::ErrorBehaviorKind::ReturnFalse);
212-
return !result.getFoundError();
210+
return checker.validateLifetime(value, scratchSpace, instructions);
213211
}

lib/SILOptimizer/Mandatory/SemanticARCOpts.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -673,9 +673,10 @@ class StorageGuaranteesLoadVisitor
673673
SmallPtrSet<SILBasicBlock *, 4> visitedBlocks;
674674

675675
LinearLifetimeChecker checker(visitedBlocks, ARCOpt.getDeadEndBlocks());
676-
auto result = checker.checkValue(baseObject, baseEndBorrows, valueDestroys,
677-
ownership::ErrorBehaviorKind::ReturnFalse);
678-
return answer(result.getFoundError());
676+
// Returns true on success. So we invert.
677+
bool foundError =
678+
!checker.validateLifetime(baseObject, baseEndBorrows, valueDestroys);
679+
return answer(foundError);
679680
}
680681

681682
// TODO: Handle other access kinds?

0 commit comments

Comments
 (0)