Skip to content

Commit ff83942

Browse files
committed
Emit debug info for storage-less variables as constant 0 instead of undef.
LLVM drops debug intrinsics for undef values in SelectionDAG and FastISel. Until this is fixed, emit a constant 0 to force the variable to be emitted. <rdar://problem/26429250>
1 parent 9e8266a commit ff83942

File tree

4 files changed

+30
-25
lines changed

4 files changed

+30
-25
lines changed

lib/IRGen/IRGenDebugInfo.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -949,8 +949,9 @@ void IRGenDebugInfo::emitVariableDeclaration(
949949

950950
// Emit locationless intrinsic for variables that were optimized away.
951951
if (Storage.size() == 0) {
952-
auto *undef = llvm::UndefValue::get(DbgTy.StorageType);
953-
emitDbgIntrinsic(BB, undef, Var, DBuilder.createExpression(), Line,
952+
auto Zero =
953+
llvm::ConstantInt::get(llvm::Type::getInt64Ty(M.getContext()), 0);
954+
emitDbgIntrinsic(BB, Zero, Var, DBuilder.createExpression(), Line,
954955
Loc.Column, Scope, DS);
955956
}
956957
}

test/DebugInfo/letclause.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ func peek() -> Symbol? { return Symbol() }
66

77
func foo() {
88
// CHECK: define {{.*}}foo
9-
// CHECK: call void @llvm.dbg.declare(metadata %V9letclause6Symbol undef, metadata ![[S:.*]], metadata !{{[0-9]+}})
9+
// CHECK: call void @llvm.dbg.value(metadata i{{.*}} 0,
10+
// CHECK-SAME: metadata ![[S:.*]], metadata !{{[0-9]+}})
1011
// CHECK: ![[S]] = !DILocalVariable(name: "s"
1112
// CHECK-SAME: line: [[@LINE+1]],
1213
while let s = peek() {

test/DebugInfo/nostorage.swift

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,31 @@
1-
// RUN: %target-swift-frontend %s -emit-ir -g -o - | FileCheck %s
1+
// RUN: %target-swift-frontend %s -emit-ir -g -o %t
2+
// RUN: cat %t | FileCheck %s --check-prefix=CHECK1
3+
// RUN: cat %t | FileCheck %s --check-prefix=CHECK2
24

3-
func markUsed<T>(_ t: T) {}
5+
func used<T>(_ t: T) {}
46

5-
class AClass {
6-
func f () -> Int64 { return 1 }
7+
public class Foo {
8+
func foo() {
9+
{ [weak self] in
10+
// CHECK1: call void @llvm.dbg.value(metadata i{{.*}} 0,
11+
// CHECK1-SAME: metadata ![[TYPE:.*]], metadata
12+
// CHECK1: ![[TYPE]] = !DILocalVariable(name: "type",
13+
// CHECK1-SAME: line: [[@LINE+1]],
14+
let type = self.dynamicType
15+
used(type)
16+
}()
17+
}
718
}
819

9-
class AnotherClass : AClass {
10-
override func f() -> Int64 { return 2 }
11-
}
12-
13-
struct AStruct {
14-
func f() -> Int64 { return 3 }
15-
}
20+
struct AStruct {}
1621

17-
// CHECK: define hidden void @_TF9nostorage3appFT_T_()
18-
func app() {
19-
var ac: AClass = AnotherClass()
22+
// CHECK2: define{{.*}}app
23+
public func app() {
2024
// No members? No storage! Emitted as a constant 0, because.
21-
// CHECK: call void @llvm.dbg.value(metadata {{.*}}, i64 0, metadata ![[AT:.*]], metadata !{{[0-9]+}}), !dbg
22-
// CHECK: ![[AT]] = !DILocalVariable(name: "at",
23-
// CHECK-SAME: line: [[@LINE+1]]
25+
// CHECK2: call void @llvm.dbg.value(metadata i{{.*}} 0,
26+
// CHECK2-SAME: metadata ![[AT:.*]], metadata
27+
// CHECK2: ![[AT]] = !DILocalVariable(name: "at",{{.*}}line: [[@LINE+1]]
2428
var at = AStruct()
25-
markUsed("\(ac.f()) \(at.f())")
29+
30+
used(at)
2631
}
27-
28-
app()

test/DebugInfo/self-nostorage.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
public struct S {
44
func f() {
55
// CHECK: define {{.*}}_TFV4main1S1ffT_T_
6-
// CHECK: call void @llvm.dbg.declare(metadata %V4main1S undef,
7-
// CHECK-SAME: metadata ![[SELF:[0-9]+]]
6+
// CHECK: call void @llvm.dbg.value(metadata i{{.*}} 0,
7+
// CHECK-SAME: metadata ![[SELF:[0-9]+]]
88
// CHECK: ![[SELF]] = !DILocalVariable(name: "self", arg: 1,
99
}
1010
}

0 commit comments

Comments
 (0)