Skip to content

Commit d98994e

Browse files
committed
[AddressLowering] Fix begin_apply's end_borrows.
When a `load_borrow` is created on behalf of a `begin_apply`, it's possible that it may have escaping users. When it does, `findInnerTransitiveGuaranteedUses` returns `false` and the uses it finds are incomplete. As a result the boundary computed in `emitEndBorrows` will be incomplete.
1 parent d3461e5 commit d98994e

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

lib/SILOptimizer/Mandatory/AddressLowering.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2332,7 +2332,10 @@ void ApplyRewriter::convertBeginApplyWithOpaqueYield() {
23322332
SILValue load =
23332333
resultBuilder.emitLoadBorrowOperation(callLoc, &newResult);
23342334
oldResult.replaceAllUsesWith(load);
2335-
emitEndBorrows(load, pass);
2335+
for (auto *user : origCall->getTokenResult()->getUsers()) {
2336+
pass.getBuilder(user->getIterator())
2337+
.createEndBorrow(pass.genLoc(), load);
2338+
}
23362339
} else {
23372340
auto *load = resultBuilder.createTrivialLoadOr(
23382341
callLoc, &newResult, LoadOwnershipQualifier::Take);

test/SILOptimizer/address_lowering.sil

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1590,8 +1590,8 @@ entry:
15901590
// CHECK: ([[ADDR_1:%[^,]+]], [[ADDR_2:%[^,]+]], {{%[^,]+}}) = begin_apply
15911591
// CHECK: [[BORROW_1:%[^,]+]] = load_borrow [[ADDR_1]] : $*LoadableNontrivial
15921592
// CHECK: struct_extract [[BORROW_1]] : $LoadableNontrivial, #LoadableNontrivial.x
1593-
// CHECK: end_borrow [[BORROW_1]] : $LoadableNontrivial
15941593
// CHECK: copy_addr [[ADDR_2]] to [init] [[OPAQUE_OUT]] : $*T
1594+
// CHECK: end_borrow [[BORROW_1]] : $LoadableNontrivial
15951595
// CHECK-LABEL: } // end sil function 'testBeginApply9Yield1LoadableNontrivialGuaranteed1OpaqueGuaranteed'
15961596
sil [ossa] @testBeginApply9Yield1LoadableNontrivialGuaranteed1OpaqueGuaranteed : $@convention(thin) <T> () -> (@out Klass, @out T) {
15971597
entry:

0 commit comments

Comments
 (0)