@@ -1774,25 +1774,32 @@ void CallArgRewriter::rewriteIndirectArgument(Operand *operand) {
1774
1774
// Allocate temporary storage for a loadable operand.
1775
1775
AllocStackInst *allocInst =
1776
1776
argBuilder.createAllocStack (callLoc, argValue->getType ());
1777
-
1778
- operand->set (allocInst);
1779
-
1780
1777
if (apply.getArgumentConvention (*operand).isOwnedConvention ()) {
1781
1778
argBuilder.createTrivialStoreOr (apply.getLoc (), argValue, allocInst,
1782
1779
StoreOwnershipQualifier::Init);
1783
1780
apply.insertAfterFullEvaluation ([&](SILBuilder &callBuilder) {
1784
1781
callBuilder.createDeallocStack (callLoc, allocInst);
1785
1782
});
1783
+ operand->set (allocInst);
1786
1784
} else {
1787
1785
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);
1790
1789
apply.insertAfterFullEvaluation ([&](SILBuilder &callBuilder) {
1790
+ if (storeBorrow) {
1791
+ callBuilder.emitEndBorrowOperation (callLoc, storeBorrow);
1792
+ }
1791
1793
if (borrow != argValue) {
1792
1794
callBuilder.emitEndBorrowOperation (callLoc, borrow);
1793
1795
}
1794
1796
callBuilder.createDeallocStack (callLoc, allocInst);
1795
1797
});
1798
+ if (storeBorrow) {
1799
+ operand->set (storeBorrow);
1800
+ } else {
1801
+ operand->set (allocInst);
1802
+ }
1796
1803
}
1797
1804
}
1798
1805
0 commit comments