Skip to content

Commit 05452da

Browse files
committed
Fix store_borrow generation in AddressLowering
1 parent ab47788 commit 05452da

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

lib/SILOptimizer/Mandatory/AddressLowering.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1774,25 +1774,32 @@ void CallArgRewriter::rewriteIndirectArgument(Operand *operand) {
17741774
// Allocate temporary storage for a loadable operand.
17751775
AllocStackInst *allocInst =
17761776
argBuilder.createAllocStack(callLoc, argValue->getType());
1777-
1778-
operand->set(allocInst);
1779-
17801777
if (apply.getArgumentConvention(*operand).isOwnedConvention()) {
17811778
argBuilder.createTrivialStoreOr(apply.getLoc(), argValue, allocInst,
17821779
StoreOwnershipQualifier::Init);
17831780
apply.insertAfterFullEvaluation([&](SILBuilder &callBuilder) {
17841781
callBuilder.createDeallocStack(callLoc, allocInst);
17851782
});
1783+
operand->set(allocInst);
17861784
} else {
17871785
auto borrow = argBuilder.emitBeginBorrowOperation(callLoc, argValue);
1788-
argBuilder.emitStoreBorrowOperation(callLoc, borrow, allocInst);
1789-
1786+
auto *store =
1787+
argBuilder.emitStoreBorrowOperation(callLoc, borrow, allocInst);
1788+
auto *storeBorrow = dyn_cast<StoreBorrowInst>(store);
17901789
apply.insertAfterFullEvaluation([&](SILBuilder &callBuilder) {
1790+
if (storeBorrow) {
1791+
callBuilder.emitEndBorrowOperation(callLoc, storeBorrow);
1792+
}
17911793
if (borrow != argValue) {
17921794
callBuilder.emitEndBorrowOperation(callLoc, borrow);
17931795
}
17941796
callBuilder.createDeallocStack(callLoc, allocInst);
17951797
});
1798+
if (storeBorrow) {
1799+
operand->set(storeBorrow);
1800+
} else {
1801+
operand->set(allocInst);
1802+
}
17961803
}
17971804
}
17981805

test/SILOptimizer/address_lowering.sil

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,8 @@ bb0(%0 : @owned $T):
262262
// CHECK: [[TMP:%.*]] = alloc_stack $C
263263
// CHECK: [[B:%.*]] = begin_borrow [[LD]] : $C
264264
// CHECK: [[SB:%.*]] = store_borrow [[B]] to [[TMP]] : $*C
265-
// CHECK: apply %{{.*}}([[TMP]]) : $@convention(thin) (@in_guaranteed C) -> ()
265+
// CHECK: apply %{{.*}}([[SB]]) : $@convention(thin) (@in_guaranteed C) -> ()
266+
// CHECK: end_borrow [[SB]] : $*C
266267
// CHECK: end_borrow [[B]] : $C
267268
// CHECK: dealloc_stack [[TMP]] : $*C
268269
// CHECK: destroy_value [[LD]] : $C

0 commit comments

Comments
 (0)