Skip to content

Commit f3eacc6

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 (cherry picked from commit f7f869c)
1 parent da6a33a commit f3eacc6

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
@@ -2628,8 +2628,8 @@ IRGenDebugInfoImpl::computeLLVMLocCodeView(const SILDebugScope *DS,
26282628
SILLocation Loc) {
26292629
// If the scope has not changed and the line number is either zero or
26302630
// artificial, we want to keep the most recent debug location.
2631-
if (DS == LastScope &&
2632-
(Loc.is<ArtificialUnreachableLocation>() || Loc.isLineZero(SM)))
2631+
if (DS == LastScope && (Loc.is<ArtificialUnreachableLocation>() ||
2632+
Loc.isLineZero(SM) || Loc.isHiddenFromDebugInfo()))
26332633
return LastFileAndLocation;
26342634

26352635
// Decode the location.
@@ -2642,11 +2642,6 @@ IRGenDebugInfoImpl::computeLLVMLoc(const SILDebugScope *DS, SILLocation Loc) {
26422642
if (Fn && (Fn->isThunk() || Fn->isTransparent()))
26432643
return {0, 0, CompilerGeneratedFile};
26442644

2645-
// Reuse the last source location if we are still in the same scope to get a
2646-
// more contiguous line table.
2647-
if (DS == LastScope && Loc.isHiddenFromDebugInfo())
2648-
return LastFileAndLocation;
2649-
26502645
if (Opts.DebugInfoFormat == IRGenDebugInfoFormat::CodeView)
26512646
return computeLLVMLocCodeView(DS, Loc);
26522647

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

0 commit comments

Comments
 (0)