Skip to content

Commit 14d3779

Browse files
author
Davide Italiano
committed
[CapturePromotion] Preserve DebugInfo when creating project_box.
The code was assigning an incorrect lexical scope, which was responsible for an hole (and likely, wrong DI at `-Onone` in some cases). Fixes SR-6709.
1 parent fbea78a commit 14d3779

File tree

2 files changed

+37
-2
lines changed

2 files changed

+37
-2
lines changed

lib/SILOptimizer/IPO/CapturePromotion.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1175,7 +1175,7 @@ constructClonedFunction(PartialApplyInst *PAI, FunctionRefInst *FRI,
11751175
static SILValue getOrCreateProjectBoxHelper(SILValue PartialOperand) {
11761176
// If we have a copy_value, just create a project_box on the copy and return.
11771177
if (auto *CVI = dyn_cast<CopyValueInst>(PartialOperand)) {
1178-
SILBuilder B(std::next(CVI->getIterator()));
1178+
SILBuilderWithScope B(std::next(CVI->getIterator()));
11791179
return B.createProjectBox(CVI->getLoc(), CVI, 0);
11801180
}
11811181

@@ -1189,7 +1189,7 @@ static SILValue getOrCreateProjectBoxHelper(SILValue PartialOperand) {
11891189
}
11901190

11911191
// Just return a project_box.
1192-
SILBuilder B(std::next(Box->getIterator()));
1192+
SILBuilderWithScope B(std::next(Box->getIterator()));
11931193
return B.createProjectBox(Box->getLoc(), Box, 0);
11941194
}
11951195

test/SILOptimizer/sr6709.swift

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Make sure project_box gets assigned the correct lexical scope when we create it.
2+
// RUN: %target-swift-frontend -primary-file %s -Onone -emit-sil -Xllvm -sil-print-after=capture-promotion -Xllvm \
3+
// RUN: -sil-print-debuginfo -o /dev/null 2>&1 | %FileCheck %s
4+
5+
// CHECK: sil hidden @_T04null19captureStackPromoteSiycyF : $@convention(thin) () -> @owned @callee_guaranteed () -> Int {
6+
// CHECK: bb0:
7+
// CHECK: %0 = alloc_box ${ var Int }, var, name "x", loc {{.*}}:32:7, scope 3 // users: %19, %7, %1
8+
// CHECK: %1 = project_box %0 : ${ var Int }, 0, loc {{.*}}:32:7, scope 3 // users: %9, %6
9+
// CHECK: %2 = metatype $@thin Int.Type, loc {{.*}}:32:11, scope 3 // user: %5
10+
// CHECK: %3 = integer_literal $Builtin.Int2048, 1, loc {{.*}}:32:11, scope 3 // user: %5
11+
// CHECK: // function_ref Int.init(_builtinIntegerLiteral:)
12+
// CHECK: %4 = function_ref @_T0Si22_builtinIntegerLiteralSiBi2048__tcfC : $@convention(method) (Builtin.Int2048, @thin Int.Type) -> Int, loc {{.*}}:32:11, scope 3 // user: %5
13+
// CHECK: %5 = apply %4(%3, %2) : $@convention(method) (Builtin.Int2048, @thin Int.Type) -> Int, loc {{.*}}:32:11, scope 3 // user: %6
14+
// CHECK: store %5 to [trivial] %1 : $*Int, loc {{.*}}:32:11, scope 3 // id: %6
15+
// CHECK: %7 = copy_value %0 : ${ var Int }, loc {{.*}}:33:11, scope 3 // users: %12, %8
16+
// CHECK: %8 = project_box %7 : ${ var Int }, 0, loc {{.*}}:33:11, scope 3 // user: %11
17+
// CHECK: mark_function_escape %1 : $*Int, loc {{.*}}:33:11, scope 3 // id: %9
18+
// CHECK: %10 = function_ref @_T04null19captureStackPromoteSiycyFSiycfU_Tf2i_n : $@convention(thin) (Int) -> Int, loc {{.*}}:33:11, scope 3 // user: %13
19+
// CHECK: %11 = load [trivial] %8 : $*Int, loc {{.*}}:33:11, scope 3 // user: %13
20+
// CHECK: destroy_value %7 : ${ var Int }, loc {{.*}}:33:11, scope 3 // id: %12
21+
// CHECK: %13 = partial_apply [callee_guaranteed] %10(%11) : $@convention(thin) (Int) -> Int, loc {{.*}}:33:11, scope 3 // users: %14, %15, %17, %18
22+
// CHECK: debug_value %13 : $@callee_guaranteed () -> Int, let, name "f", loc {{.*}}:33:7, scope 3 // id: %14
23+
// CHECK: %15 = begin_borrow %13 : $@callee_guaranteed () -> Int, loc {{.*}}:34:10, scope 3 // users: %17, %16
24+
// CHECK: %16 = copy_value %15 : $@callee_guaranteed () -> Int, loc {{.*}}:34:10, scope 3 // user: %20
25+
// CHECK: end_borrow %15 from %13 : $@callee_guaranteed () -> Int, $@callee_guaranteed () -> Int, loc {{.*}}:34:10, scope 3 // id: %17
26+
// CHECK: destroy_value %13 : $@callee_guaranteed () -> Int, loc {{.*}}:35:1, scope 3 // id: %18
27+
// CHECK: destroy_value %0 : ${ var Int }, loc {{.*}}:35:1, scope 3 // id: %19
28+
// CHECK: return %16 : $@callee_guaranteed () -> Int, loc {{.*}}:34:3, scope 3 // id: %20
29+
// CHECK: }
30+
31+
func captureStackPromote() -> () -> Int {
32+
var x = 1
33+
let f = { x }
34+
return f
35+
}

0 commit comments

Comments
 (0)