Skip to content

Commit 4e94109

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 731c0cc commit 4e94109

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

lib/SILOptimizer/Mandatory/AddressLowering.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3418,6 +3418,8 @@ emitEndBorrowsAtEnclosingGuaranteedBoundary(SILValue lifetimeToEnd,
34183418

34193419
// Extract from an opaque struct or tuple.
34203420
void UseRewriter::emitExtract(SingleValueInstruction *extractInst) {
3421+
AddressMaterialization addrMat(pass, extractInst, builder);
3422+
auto source = extractInst->getOperand(0);
34213423
SILValue extractAddr = addrMat.materializeDefProjection(extractInst);
34223424

34233425
if (extractInst->getType().isAddressOnly(*pass.function)) {
@@ -3448,7 +3450,7 @@ void UseRewriter::emitExtract(SingleValueInstruction *extractInst) {
34483450
SILValue loadElement =
34493451
builder.emitLoadBorrowOperation(extractInst->getLoc(), extractAddr);
34503452
replaceUsesWithLoad(extractInst, loadElement);
3451-
emitEndBorrows(loadElement, pass);
3453+
emitEndBorrowsAtEnclosingGuaranteedBoundary(loadElement, source, pass);
34523454
}
34533455

34543456
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)