Skip to content

Commit 4c5ce62

Browse files
committed
[AddressLowering] Fix extract's end_borrows.
An extract may have users that have escaping operand ownership. Consequently, we can't rely on findInnerTransitiveGuaranteedUses as used by emitEndBorrows.
1 parent 04978e2 commit 4c5ce62

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

lib/SILOptimizer/Mandatory/AddressLowering.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3450,6 +3450,7 @@ emitEndBorrowsAtEnclosingGuaranteedBoundary(SILValue lifetimeToEnd,
34503450

34513451
// Extract from an opaque struct or tuple.
34523452
void UseRewriter::emitExtract(SingleValueInstruction *extractInst) {
3453+
auto source = extractInst->getOperand(0);
34533454
SILValue extractAddr = addrMat.materializeDefProjection(extractInst);
34543455

34553456
if (extractInst->getType().isAddressOnly(*pass.function)) {
@@ -3480,7 +3481,7 @@ void UseRewriter::emitExtract(SingleValueInstruction *extractInst) {
34803481
SILValue loadElement =
34813482
builder.emitLoadBorrowOperation(extractInst->getLoc(), extractAddr);
34823483
replaceUsesWithLoad(extractInst, loadElement);
3483-
emitEndBorrows(loadElement, pass);
3484+
emitEndBorrowsAtEnclosingGuaranteedBoundary(loadElement, source, pass);
34843485
}
34853486

34863487
void UseRewriter::visitStructExtractInst(StructExtractInst *extractInst) {

test/SILOptimizer/address_lowering.sil

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -761,9 +761,9 @@ bb0(%0 : @owned $SRef<T>):
761761
// CHECK: [[L:%.*]] = load_borrow [[E0]] : $*AnyObject
762762
// CHECK: apply %{{.*}}([[L]]) : $@convention(thin) (@guaranteed AnyObject) -> ()
763763
// CHECK: [[C:%.*]] = copy_value [[L]] : $AnyObject
764-
// CHECK: end_borrow [[L]] : $AnyObject
765764
// CHECK: [[E1:%.*]] = struct_element_addr %2 : $*SRef<T>, #SRef.element
766765
// CHECK: copy_addr [[E1]] to [init] %1 : $*T
766+
// CHECK: end_borrow [[L]] : $AnyObject
767767
// CHECK: destroy_addr %2 : $*SRef<T>
768768
// CHECK: store [[C]] to [init] %0 : $*AnyObject
769769
// CHECK-NOT: dealloc_stack
@@ -813,9 +813,9 @@ bb0(%0 : @owned $(AnyObject, T)):
813813
// CHECK: [[L:%.*]] = load_borrow %3 : $*AnyObject
814814
// CHECK: apply %{{.*}}([[L]]) : $@convention(thin) (@guaranteed AnyObject) -> ()
815815
// CHECK: [[C:%.*]] = copy_value [[L]] : $AnyObject
816-
// CHECK: end_borrow [[L]] : $AnyObject
817816
// CHECK: [[E1:%.*]] = tuple_element_addr %2 : $*(AnyObject, T), 1
818817
// CHECK: copy_addr [[E1]] to [init] %1 : $*T
818+
// CHECK: end_borrow [[L]] : $AnyObject
819819
// CHECK: destroy_addr %2 : $*(AnyObject, T)
820820
// CHECK: store [[C]] to [init] %0 : $*AnyObject
821821
// CHECK-NOT: dealloc_stack

0 commit comments

Comments
 (0)