Skip to content

Commit 1cb9c24

Browse files
committed
Debug Info: Don't emit shadow stack copies for local variables.
The effect of this tiny change is that local variables will be described by llvm.dbg.values, which will get lowered into an accurate location list instead of a stack slot that is valid for the entire scope of the variable. This means the debugger can now accurately track the liveness of variables knowing exactly when they are initialized and when there values go away. Function arguments are still kept in stack slots because (1) they are already initialized at the function entry and (2) LLDB really needs self to be available at all times for the expression evaluator. This was made possible by recent advancements in LLVM such as the live debug variables pass and various related bugfixes. <rdar://problem/15746520>
1 parent ba2710e commit 1cb9c24

File tree

5 files changed

+15
-17
lines changed

5 files changed

+15
-17
lines changed

lib/IRGen/IRGenSIL.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,7 @@ class IRGenSILFunction :
582582
StringRef Name, unsigned ArgNo,
583583
Alignment Align = Alignment(0)) {
584584
auto Ty = Storage->getType();
585-
if (IGM.Opts.Optimize ||
585+
if (IGM.Opts.Optimize || (ArgNo == 0) ||
586586
isa<llvm::AllocaInst>(Storage) ||
587587
isa<llvm::UndefValue>(Storage) ||
588588
Ty == IGM.RefCountedPtrTy) // No debug info is emitted for refcounts.

test/DebugInfo/WeakCapture.swift

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@ func function() {
1010
let b = B()
1111

1212
// Ensure that the local b and its weak copy are distinct local variables.
13-
// CHECK: %[[B:.*]] = alloca %C11WeakCapture1B*
14-
// CHECK: %[[BWEAK:.*]] = alloca %swift.weak*
15-
// CHECK: call void @llvm.dbg.declare({{.*}}[[B]]
16-
// CHECK: call void @llvm.dbg.declare({{.*}}[[BWEAK]]
13+
// CHECK: call void @llvm.dbg.value(metadata %C11WeakCapture1B*
14+
// CHECK-SAME: metadata [[B:.*]], metadata
15+
// CHECK: call void @llvm.dbg.value(metadata %swift.weak*
16+
// CHECK-NOT: metadata [[B]]
17+
// CHECK: call
1718
A(handler: { [weak b] _ in
1819
if b != nil { }
1920
})

test/DebugInfo/arg-debug_value.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ class Foo {
88
var x: Int64
99
// CHECK: define {{.*}}_TFC4main3FoocfT_S0_
1010
// CHECK: entry:
11-
// CHECK-NEXT: %[[SELF:.*]] = alloca
12-
// CHECK-NEXT: store %C4main3Foo* %0, %C4main3Foo** %[[SELF]]
13-
// CHECK-NEXT: call void @llvm.dbg.declare({{.*}}%[[SELF]]
11+
// CHECK-NEXT: call void @llvm.dbg.value(metadata %C4main3Foo* %0
12+
// CHECK: ret %C4main3Foo* %0
1413
init () { x = g; g += 1 }
1514
}

test/DebugInfo/patternmatching.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ switch p {
2525
// Verify that the branch has a location >= the cleanup.
2626
// SIL-CHECK-NEXT: br{{.*}}line:[[@LINE-3]]:17:cleanup
2727
// CHECK-SCOPES: call {{.*}}markUsed
28-
// CHECK-SCOPES: call void @llvm.dbg.declare({{.*}}metadata ![[X1:[0-9]+]]
28+
// CHECK-SCOPES: call void @llvm.dbg.value({{.*}}metadata ![[X1:[0-9]+]]
2929
// CHECK-SCOPES-SAME: !dbg ![[X1LOC:[0-9]+]]
30-
// CHECK-SCOPES: call void @llvm.dbg.declare
31-
// CHECK-SCOPES: call void @llvm.dbg.declare({{.*}}metadata ![[X2:[0-9]+]]
30+
// CHECK-SCOPES: call void @llvm.dbg.value
31+
// CHECK-SCOPES: call void @llvm.dbg.value({{.*}}metadata ![[X2:[0-9]+]]
3232
// CHECK-SCOPES-SAME: !dbg ![[X2LOC:[0-9]+]]
33-
// CHECK-SCOPES: call void @llvm.dbg.declare
34-
// CHECK-SCOPES: call void @llvm.dbg.declare({{.*}}metadata ![[X3:[0-9]+]]
33+
// CHECK-SCOPES: call void @llvm.dbg.value
34+
// CHECK-SCOPES: call void @llvm.dbg.value({{.*}}metadata ![[X3:[0-9]+]]
3535
// CHECK-SCOPES-SAME: !dbg ![[X3LOC:[0-9]+]]
3636
// CHECK-SCOPES: !DILocalVariable(name: "x",
3737
case (let x, let y) where x == -y:

test/DebugInfo/value-update.sil

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,15 @@ bb0:
1212
%1 = integer_literal $Builtin.Int64, 23
1313
%2 = struct $Int (%1 : $Builtin.Int64)
1414
debug_value %2 : $Int, var, name "v"
15-
// CHECK: store i64 23, i64* %[[ALLOCA:.*]], align 8, !dbg
16-
// CHECK: dbg.declare
15+
// CHECK: call void @llvm.dbg.value(metadata i64 23,
1716
// function_ref StdlibUnittest._blackHole <A> (A) -> ()
1817
%5 = function_ref @_TF14StdlibUnittest10_blackHoleurFxT_ : $@convention(thin) <τ_0_0> (@in τ_0_0) -> () // user: %8
1918
%6 = tuple ()
2019
%7 = alloc_stack $() // users: %8, %9
2120
%8 = apply %5<()>(%7) : $@convention(thin) <τ_0_0> (@in τ_0_0) -> ()
2221
dealloc_stack %7 : $*() // id: %9
2322

24-
// CHECK: store i64 42, i64* %[[ALLOCA]], align 8, !dbg
25-
// CHECK-NOT: dbg.declare
23+
// CHECK: call void @llvm.dbg.value(metadata i64 42,
2624
%9 = integer_literal $Builtin.Int64, 42 // user: %10
2725
%10 = struct $Int (%9 : $Builtin.Int64) // user: %11
2826
debug_value %10 : $Int, var, name "v"

0 commit comments

Comments
 (0)