Skip to content

Commit 15dd4fe

Browse files
author
Davide Italiano
committed
[SILInliner] Set the correct scope for {begin,end}_borrow.
<rdar://problem/51512044>
1 parent 02ba2d3 commit 15dd4fe

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

lib/SILOptimizer/Utils/SILInliner.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -559,15 +559,18 @@ SILValue SILInlineCloner::borrowFunctionArgument(SILValue callArg,
559559
|| callArg.getOwnershipKind() != ValueOwnershipKind::Owned) {
560560
return callArg;
561561
}
562-
auto *borrow = getBuilder().createBeginBorrow(AI.getLoc(), callArg);
562+
563+
SILBuilderWithScope beginBuilder(AI.getInstruction());
564+
auto *borrow = beginBuilder.createBeginBorrow(AI.getLoc(), callArg);
563565
if (auto *tryAI = dyn_cast<TryApplyInst>(AI)) {
564-
SILBuilder returnBuilder(tryAI->getNormalBB()->begin());
566+
SILBuilderWithScope returnBuilder(tryAI->getNormalBB()->begin());
565567
returnBuilder.createEndBorrow(AI.getLoc(), borrow, callArg);
566568

567-
SILBuilder throwBuilder(tryAI->getErrorBB()->begin());
569+
SILBuilderWithScope throwBuilder(tryAI->getErrorBB()->begin());
568570
throwBuilder.createEndBorrow(AI.getLoc(), borrow, callArg);
569571
} else {
570-
SILBuilder returnBuilder(std::next(AI.getInstruction()->getIterator()));
572+
SILBuilderWithScope returnBuilder(
573+
std::next(AI.getInstruction()->getIterator()));
571574
returnBuilder.createEndBorrow(AI.getLoc(), borrow, callArg);
572575
}
573576
return borrow;
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// RUN: %target-swift-frontend -emit-sil %s -Onone -Xllvm \
2+
// RUN: -sil-print-after=mandatory-inlining \
3+
// RUN: -enable-ownership-stripping-after-serialization \
4+
// RUN: -Xllvm -sil-print-debuginfo -o /dev/null 2>&1 | %FileCheck %s
5+
6+
// CHECK: begin_borrow {{.*}} : $OSLog, loc {{.*}}, scope 3
7+
// CHECK: tuple (), loc {{.*}}, scope 3
8+
// CHECK: end_borrow %3 : $OSLog, loc {{.*}}, scope 3
9+
10+
import os
11+
12+
func bar() {
13+
foo(OSLog.default)
14+
}
15+
16+
@_transparent
17+
func foo(_ logObject: OSLog) { }

0 commit comments

Comments
 (0)