Skip to content

Commit f7f869c

Browse files
[DebugInfo] Don't inherit debug location of previous instruction
Prior to this commit, when lowering SIL instructions that should are "hidden" for the purposes of debugging, the compiler just attaches the location of the previous instruction in the name of keeping a simpler line table. However, this is wrong for many reasons. One such reason is this: at the start of a basic block, inheriting the previous debug location will almost certainly cause the instruction to have a random location in the code, as it will depend on whatever BB was visited previously. Other examples can be seen in the tests affect by this commit, which changes lowering to use Line 0 instead of the line number of the previous instruction. CodeView doesn't handle line 0 the same way DWARF does, so this commit preserves the old behavior for the CodeView path. The test changes here are effectively undoing some of the diffs from 158772c. rdar://139826231&110187845
1 parent 9758099 commit f7f869c

12 files changed

+17
-24
lines changed

lib/IRGen/IRGenDebugInfo.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2625,8 +2625,8 @@ IRGenDebugInfoImpl::computeLLVMLocCodeView(const SILDebugScope *DS,
26252625
SILLocation Loc) {
26262626
// If the scope has not changed and the line number is either zero or
26272627
// artificial, we want to keep the most recent debug location.
2628-
if (DS == LastScope &&
2629-
(Loc.is<ArtificialUnreachableLocation>() || Loc.isLineZero(SM)))
2628+
if (DS == LastScope && (Loc.is<ArtificialUnreachableLocation>() ||
2629+
Loc.isLineZero(SM) || Loc.isHiddenFromDebugInfo()))
26302630
return LastFileAndLocation;
26312631

26322632
// Decode the location.
@@ -2639,11 +2639,6 @@ IRGenDebugInfoImpl::computeLLVMLoc(const SILDebugScope *DS, SILLocation Loc) {
26392639
if (Fn && (Fn->isThunk() || Fn->isTransparent()))
26402640
return {0, 0, CompilerGeneratedFile};
26412641

2642-
// Reuse the last source location if we are still in the same scope to get a
2643-
// more contiguous line table.
2644-
if (DS == LastScope && Loc.isHiddenFromDebugInfo())
2645-
return LastFileAndLocation;
2646-
26472642
if (Opts.DebugInfoFormat == IRGenDebugInfoFormat::CodeView)
26482643
return computeLLVMLocCodeView(DS, Loc);
26492644

test/Backtracing/Crash.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ struct Crash {
6060
// CHECK-NEXT: 4 [ra] 0x{{[0-9a-f]+}} level1() + {{[0-9]+}} in Crash at {{.*}}/Crash.swift:24:3
6161
// CHECK-NEXT: 5 [ra] 0x{{[0-9a-f]+}} static Crash.main() + {{[0-9]+}} in Crash at {{.*}}/Crash.swift:48:5
6262
// CHECK-NEXT: 6 [ra] [system] 0x{{[0-9a-f]+}} static Crash.$main() + {{[0-9]+}} in Crash at {{.*}}/<compiler-generated>
63-
// CHECK-NEXT: 7 [ra] 0x{{[0-9a-f]+}} main + {{[0-9]+}} in Crash at {{.*}}/Crash.swift
63+
// CHECK-NEXT: 7 [ra] [system] 0x{{[0-9a-f]+}} main + {{[0-9]+}} in Crash at {{.*}}/Crash.swift
6464

6565
// CHECK: Registers:
6666

test/Backtracing/CrashStatic.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ struct CrashStatic {
5151
// CHECK-NEXT: 4 [ra] 0x{{[0-9a-f]+}} level1() + {{[0-9]+}} in CrashStatic at {{.*}}/CrashStatic.swift:15:3
5252
// CHECK-NEXT: 5 [ra] 0x{{[0-9a-f]+}} static CrashStatic.main() + {{[0-9]+}} in CrashStatic at {{.*}}/CrashStatic.swift:39:5
5353
// CHECK-NEXT: 6 [ra] [system] 0x{{[0-9a-f]+}} static CrashStatic.$main() + {{[0-9]+}} in CrashStatic at {{.*}}/<compiler-generated>
54-
// CHECK-NEXT: 7 [ra] 0x{{[0-9a-f]+}} main + {{[0-9]+}} in CrashStatic at {{.*}}/CrashStatic.swift
54+
// CHECK-NEXT: 7 [ra] [system] 0x{{[0-9a-f]+}} main + {{[0-9]+}} in CrashStatic at {{.*}}/CrashStatic.swift
5555

5656
// CHECK: Registers:
5757

test/Backtracing/CrashWithThunk.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ struct CrashWithThunk {
3838
// CHECK-NEXT: 1 [ra] [thunk] 0x{{[0-9a-f]+}} thunk for @escaping @callee_guaranteed () -> () + {{[0-9]+}} in CrashWithThunk at {{.*}}/<compiler-generated>
3939
// CHECK-NEXT: 2 [ra] 0x{{[0-9a-f]+}} static CrashWithThunk.main() + {{[0-9]+}} in CrashWithThunk at {{.*}}/CrashWithThunk.swift:29:9
4040
// CHECK-NEXT: 3 [ra] [system] 0x{{[0-9a-f]+}} static CrashWithThunk.$main() + {{[0-9]+}} in CrashWithThunk at {{.*}}/<compiler-generated>
41-
// CHECK-NEXT: 4 [ra] 0x{{[0-9a-f]+}} main + {{[0-9]+}} in CrashWithThunk at {{.*}}/CrashWithThunk.swift
41+
// CHECK-NEXT: 4 [ra] [system] 0x{{[0-9a-f]+}} main + {{[0-9]+}} in CrashWithThunk at {{.*}}/CrashWithThunk.swift
4242

4343
// CHECK: Registers:
4444

test/Backtracing/FatalError.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,4 @@ struct FatalError {
5151
// CHECK-NEXT: 5 [ra] 0x{{[0-9a-f]+}} level1() + {{[0-9]+}} in FatalError at {{.*}}/FatalError.swift:14:3
5252
// CHECK-NEXT: 6 [ra] 0x{{[0-9a-f]+}} static FatalError.main() + {{[0-9]+}} in FatalError at {{.*}}/FatalError.swift:36:5
5353
// CHECK-NEXT: 7 [ra] [system] 0x{{[0-9a-f]+}} static FatalError.$main() + {{[0-9]+}} in FatalError at {{.*}}/<compiler-generated>
54-
// CHECK-NEXT: 8 [ra] 0x{{[0-9a-f]+}} main + {{[0-9]+}} in FatalError at {{.*}}/FatalError.swift
54+
// CHECK-NEXT: 8 [ra] [system] 0x{{[0-9a-f]+}} main + {{[0-9]+}} in FatalError at {{.*}}/FatalError.swift

test/Backtracing/Overflow.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ struct Overflow {
5252
// CHECK-NEXT: 5 [ra] 0x{{[0-9a-f]+}} level1() + {{[0-9]+}} in Overflow at {{.*}}/Overflow.swift:15:3
5353
// CHECK-NEXT: 6 [ra] 0x{{[0-9a-f]+}} static Overflow.main() + {{[0-9]+}} in Overflow at {{.*}}/Overflow.swift:39:5
5454
// CHECK-NEXT: 7 [ra] [system] 0x{{[0-9a-f]+}} static Overflow.$main() + {{[0-9]+}} in Overflow at {{.*}}/<compiler-generated>
55-
// CHECK-NEXT: 8 [ra] 0x{{[0-9a-f]+}} main + {{[0-9]+}} in Overflow at {{.*}}/Overflow.swift
55+
// CHECK-NEXT: 8 [ra] [system] 0x{{[0-9a-f]+}} main + {{[0-9]+}} in Overflow at {{.*}}/Overflow.swift
5656

5757
// CHECK: Registers:
5858

test/Backtracing/StackOverflow.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ struct StackOverflow {
100100

101101
// CHECK: {{[0-9]+}} [ra] 0x{{[0-9a-f]+}} static StackOverflow.main() + {{[0-9]+}} in StackOverflow at {{.*}}/StackOverflow.swift:25:5
102102
// CHECK-NEXT: {{[0-9]+}} [ra] [system] 0x{{[0-9a-f]+}} static StackOverflow.$main() + {{[0-9]+}} in StackOverflow at {{.*}}/<compiler-generated>
103-
// CHECK-NEXT: {{[0-9]+}} [ra] 0x{{[0-9a-f]+}} main + {{[0-9]+}} in StackOverflow at {{.*}}/StackOverflow.swift
103+
// CHECK-NEXT: {{[0-9]+}} [ra] [system] 0x{{[0-9a-f]+}} main + {{[0-9]+}} in StackOverflow at {{.*}}/StackOverflow.swift
104104

105105
// CHECK: Registers:
106106

@@ -129,7 +129,7 @@ struct StackOverflow {
129129

130130
// LIMITED: {{[0-9]+}} [ra] 0x{{[0-9a-f]+}} static StackOverflow.main() + {{[0-9]+}} in StackOverflow at {{.*}}/StackOverflow.swift:25:5
131131
// LIMITED-NEXT: {{[0-9]+}} [ra] [system] 0x{{[0-9a-f]+}} static StackOverflow.$main() + {{[0-9]+}} in StackOverflow at {{.*}}/<compiler-generated>
132-
// LIMITED-NEXT: {{[0-9]+}} [ra] 0x{{[0-9a-f]+}} main + {{[0-9]+}} in StackOverflow at {{.*}}/StackOverflow.swift
132+
// LIMITED-NEXT: {{[0-9]+}} [ra] [system] 0x{{[0-9a-f]+}} main + {{[0-9]+}} in StackOverflow at {{.*}}/StackOverflow.swift
133133

134134
// FRIENDLY: *** Program crashed: Bad pointer dereference at 0x{{[0-9a-f]+}} ***
135135

test/Backtracing/StaticBacktracer.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ struct StaticBacktracer {
5252
// CHECK-NEXT: 4 [ra] 0x{{[0-9a-f]+}} level1() + {{[0-9]+}} in StaticBacktracer at {{.*}}/StaticBacktracer.swift:16:3
5353
// CHECK-NEXT: 5 [ra] 0x{{[0-9a-f]+}} static StaticBacktracer.main() + {{[0-9]+}} in StaticBacktracer at {{.*}}/StaticBacktracer.swift:40:5
5454
// CHECK-NEXT: 6 [ra] [system] 0x{{[0-9a-f]+}} static StaticBacktracer.$main() + {{[0-9]+}} in StaticBacktracer at {{.*}}/<compiler-generated>
55-
// CHECK-NEXT: 7 [ra] 0x{{[0-9a-f]+}} main + {{[0-9]+}} in StaticBacktracer at {{.*}}/StaticBacktracer.swift
55+
// CHECK-NEXT: 7 [ra] [system] 0x{{[0-9a-f]+}} main + {{[0-9]+}} in StaticBacktracer at {{.*}}/StaticBacktracer.swift
5656

5757
// CHECK: Registers:
5858

test/DebugInfo/async-let.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public actor Alice {
1717
// CHECK: load ptr, ptr {{.*}} !dbg ![[LET_HOP0:[0-9]+]]
1818

1919
// CHECK: define {{.*}}$s1M5AliceC4callyyYaFSiyYaYbcfu_TY2_{{.*}} !dbg ![[LET_SCOPE1:[0-9]+]]
20-
// CHECK: load ptr, ptr {{.*}} !dbg ![[LET_HOP1:[0-9]+]]
20+
// CHECK: store i64 %{{.*}} !dbg ![[LET_HOP1:[0-9]+]]
2121
public func call() async {
2222
// CHECK: ![[SCOPE0]] = distinct !DISubprogram({{.*}}line: [[@LINE-1]]
2323
// CHECK: ![[HOP0]] = !DILocation(line: [[@LINE+1]], column: 11

test/DebugInfo/autoclosure.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,10 @@ func &&&&&(lhs: Bool, rhs: @autoclosure () -> Bool) -> Bool {
1919
}
2020

2121
func call_me(_ input: Int64) -> Void {
22-
// rdar://problem/14627460
2322
// An autoclosure should have a line number in the debug info and a scope line of 0.
2423
// CHECK-DAG: !DISubprogram({{.*}}linkageName: "$s11autoclosure7call_meyys5Int64VFSbyXEfu_",{{.*}} spFlags: DISPFlagLocalToUnit | DISPFlagDefinition
25-
// But not in the line table.
26-
// CHECK-DAG: ![[DBG]] = !DILocation(line: [[@LINE+1]],
24+
// Instructions setting up the closure should have a line number of 0.
25+
// CHECK-DAG: ![[DBG]] = !DILocation(line: 0,
2726
if input != 0 &&&&& ( get_truth (input * 2 + 1) > 0 ) {
2827
}
2928

test/DebugInfo/callexpr.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,8 @@ markUsed(r)
1919
struct MyType {}
2020
func bar(x: MyType = MyType()) {}
2121

22-
// Room for improvement:
23-
// Because the default argument is implicit it inherits the previous source location.
2422
// CHECK2: call {{.*}}MyType{{.*}}, !dbg ![[DEFAULTARG:.*]]
2523
// CHECK2: call {{.*}}bar{{.*}}, !dbg ![[BARCALL:.*]]
26-
bar() // CHECK2: ![[DEFAULTARG]] = !DILocation(line: [[@LINE-9]]
24+
bar() // CHECK2: ![[DEFAULTARG]] = !DILocation(line: 0
2725
// CHECK2: ![[BARCALL]] = !DILocation(line: [[@LINE-1]], column: 1
2826

test/DebugInfo/returnlocation.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,9 +184,10 @@ public class Class1 {
184184
public required init?() {
185185
print("hello")
186186
// CHECK_INIT: call {{.*}}@"$ss5print_9separator10terminatoryypd_S2StF"{{.*}}, !dbg ![[PRINTLOC:[0-9]+]]
187-
// FIXME: Why doesn't ret have the correct line number?
188-
// CHECK_INIT: ret i{{32|64}} 0, !dbg ![[PRINTLOC]]
187+
// FIXME: ret has an incorrect line number because it is generated with "isHiddenFromDebugInfo"
188+
// CHECK_INIT: ret i{{32|64}} 0, !dbg ![[LINE_0:[0-9]+]]
189189
// CHECK_INIT-DAG: [[PRINTLOC]] = !DILocation(line: [[@LINE-4]]
190+
// CHECK_INIT-DAG: [[LINE_0]] = !DILocation(line: 0
190191
return nil
191192
}
192193
}

0 commit comments

Comments
 (0)