Skip to content

Commit 5e7c308

Browse files
author
Davide Italiano
committed
[StackNesting] Preserve debug info correctly when solving.
Some of the `dealloc_stack` instructions inserted where getting a wrong scope. This manifests when running AllocBoxToStack because it uses StackNesting as an utility. Yet another improvement in debug informations at `-Onone`. Fixes SR-6738.
1 parent b0d5454 commit 5e7c308

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

lib/SILOptimizer/Utils/StackNesting.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ bool StackNesting::solve() {
153153
static SILInstruction *createDealloc(AllocationInst *Alloc,
154154
SILInstruction *InsertionPoint,
155155
SILLocation Location) {
156-
SILBuilder B(InsertionPoint);
156+
SILBuilderWithScope B(InsertionPoint);
157157
switch (Alloc->getKind()) {
158158
case SILInstructionKind::AllocStackInst:
159159
return B.createDeallocStack(Location, Alloc);
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// RUN: %target-swift-frontend -emit-sil -enable-sil-ownership %s -Onone -Xllvm \
2+
// RUN: -sil-print-after=allocbox-to-stack -Xllvm \
3+
// RUN: -sil-print-only-functions=$S3red19ThrowAddrOnlyStructV016throwsOptionalToG0ACyxGSgSi_tcfC \
4+
// RUN: -Xllvm -sil-print-debuginfo -o /dev/null 2>&1 | %FileCheck %s
5+
6+
// CHECK: bb5(%27 : @owned $Error):
7+
// CHECK: dealloc_stack %6 : $*ThrowAddrOnlyStruct<T>, loc {{.*}}:27:68, scope 2
8+
// CHECK: dealloc_stack %3 : $*ThrowAddrOnlyStruct<T>, loc {{.*}}:27:68, scope 2
9+
// CHECK: br bb4(%27 : $Error), loc {{.*}}:27:15, scope 2
10+
11+
protocol Patatino {
12+
init()
13+
}
14+
struct ThrowAddrOnlyStruct<T : Patatino> {
15+
var x : T
16+
init(fail: ()) throws { x = T() }
17+
init(failDuringDelegation: Int) throws {
18+
try self.init(fail: ())
19+
}
20+
init?(throwsToOptional: Int) {
21+
try? self.init(failDuringDelegation: throwsToOptional)
22+
}
23+
init(throwsOptionalToThrows: Int) throws {
24+
self.init(throwsToOptional: throwsOptionalToThrows)!
25+
}
26+
init?(throwsOptionalToOptional: Int) {
27+
try! self.init(throwsOptionalToThrows: throwsOptionalToOptional)
28+
}
29+
}

0 commit comments

Comments
 (0)