Skip to content

Commit 867143d

Browse files
committed
[AddressLowering] Soften assertion for end_borrows
When finding the PrunedLiveness on whose boundary end_borrows are to be inserted, allow lifetime ending uses if they are end_borrows. Such end_borrows appear validly when an inner use is a nested begin_borrow.
1 parent e527d8b commit 867143d

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

lib/SILOptimizer/Mandatory/AddressLowering.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3306,7 +3306,7 @@ static void emitEndBorrows(SILValue value, AddressLoweringState &pass) {
33063306
SSAPrunedLiveness liveness(&discoveredBlocks);
33073307
liveness.initializeDef(value);
33083308
for (auto *use : usePoints) {
3309-
assert(!use->isLifetimeEnding());
3309+
assert(!use->isLifetimeEnding() || isa<EndBorrowInst>(use->getUser()));
33103310
liveness.updateForUse(use->getUser(), /*lifetimeEnding*/ false);
33113311
}
33123312
PrunedLivenessBoundary guaranteedBoundary;

test/SILOptimizer/address_lowering.sil

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1753,6 +1753,33 @@ entry:
17531753
return %retval : $()
17541754
}
17551755

1756+
// Verify that a copy_value that is a "copy-store" whose source is a borrow of an
1757+
// @in_guaranteed yield generates storage.
1758+
// testBeginApplyH2CopyStoreBorrowedInGuaranteedValue
1759+
// CHECK-LABEL: sil [ossa] @testBeginApplyH2CopyStoreBorrowedInGuaranteedValue : {{.*}} {
1760+
// CHECK: [[COPY_STORAGE:%[^,]+]] = alloc_stack $T
1761+
// CHECK: ([[YIELD_STORAGE:%[^,]+]], [[TOKEN:%[^,]+]]) = begin_apply undef
1762+
// CHECK: copy_addr [[YIELD_STORAGE]] to [init] [[COPY_STORAGE]] : $*T
1763+
// CHECK: end_apply [[TOKEN]]
1764+
// CHECK: [[PTR:%[^,]+]] = apply undef
1765+
// CHECK: [[ADDR:%[^,]+]] = pointer_to_address [[PTR]]
1766+
// CHECK: copy_addr [take] [[COPY_STORAGE]] to [[ADDR]]
1767+
// CHECK-LABEL: } // end sil function 'testBeginApplyH2CopyStoreBorrowedInGuaranteedValue'
1768+
sil [ossa] @testBeginApplyH2CopyStoreBorrowedInGuaranteedValue : $@convention(thin) <T> () -> () {
1769+
entry:
1770+
(%yield, %token) = begin_apply undef<T>() : $@yield_once @convention(thin) <τ_0_0> () -> @yields @in_guaranteed τ_0_0
1771+
%borrow = begin_borrow %yield : $T
1772+
apply undef<T>(%borrow) : $@convention(thin) <τ> (@in_guaranteed τ) -> ()
1773+
%copy = copy_value %borrow : $T
1774+
end_borrow %borrow : $T
1775+
end_apply %token
1776+
%ptr = apply undef<T>() : $@convention(method) <τ_0_0> () -> Builtin.RawPointer
1777+
%addr = pointer_to_address %ptr : $Builtin.RawPointer to [strict] $*T
1778+
store %copy to [assign] %addr : $*T
1779+
%retval = tuple ()
1780+
return %retval : $()
1781+
}
1782+
17561783
// sil [ossa] @testBeginApplyIConsumeInValue : {{.*}} {
17571784
// bb0:
17581785
// [[IN_STORAGE:%[^,]+]] = alloc_stack $T

0 commit comments

Comments
 (0)