Skip to content

Commit 4201f9c

Browse files
Merge pull request #18312 from sparkasaurusRex/codeview-linetables
Reduce breaks in Codeview linetables
2 parents 36db311 + 1717694 commit 4201f9c

File tree

4 files changed

+24
-4
lines changed

4 files changed

+24
-4
lines changed

include/swift/SIL/SILLocation.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,11 @@ class SILLocation {
295295
/// contain calls, which the debugger could be able to step into.
296296
bool isAutoGenerated() const { return KindData & (1 << AutoGeneratedBit); }
297297

298+
/// Returns true if the line number of this location is zero.
299+
bool isLineZero(const SourceManager &SM) const {
300+
return decodeDebugLoc(SM).Line == 0;
301+
}
302+
298303
/// Changes the default source location position to point to start of
299304
/// the AST node.
300305
void pointToStart() { KindData |= (1 << PointsToStartBit); }

lib/IRGen/IRGenDebugInfo.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1589,6 +1589,9 @@ void IRGenDebugInfoImpl::setCurrentLoc(IRBuilder &Builder,
15891589
if (!Scope)
15901590
return;
15911591

1592+
// NOTE: In CodeView, zero is not an artificial line location. We try to
1593+
// avoid those line locations near user code to reduce the number
1594+
// of breaks in the linetables.
15921595
SILLocation::DebugLoc L;
15931596
SILFunction *Fn = DS->getInlinedFunction();
15941597
if (Fn && (Fn->isThunk() || Fn->isTransparent())) {
@@ -1597,10 +1600,11 @@ void IRGenDebugInfoImpl::setCurrentLoc(IRBuilder &Builder,
15971600
// Reuse the last source location if we are still in the same
15981601
// scope to get a more contiguous line table.
15991602
L = LastDebugLoc;
1600-
} else if (DS == LastScope && Loc.is<ArtificialUnreachableLocation>() &&
1603+
} else if (DS == LastScope &&
1604+
(Loc.is<ArtificialUnreachableLocation>() || Loc.isLineZero(SM)) &&
16011605
Opts.DebugInfoFormat == IRGenDebugInfoFormat::CodeView) {
1602-
// Remove unreachable locations with line zero because line zero does not
1603-
// represent an artificial location in CodeView.
1606+
// If the scope has not changed and the line number is either zero or
1607+
// artificial, we want to keep the most recent debug location.
16041608
L = LastDebugLoc;
16051609
} else {
16061610
// Decode the location.

test/DebugInfo/columns.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ public func foo(_ a: Int64, _ b: Int64) -> Int64 { // line 5
2424

2525
// CV-CHECK-DAG: !DILexicalBlock({{.*}}, line: 5)
2626
// CV-CHECK-DAG: ![[DIV]] = !DILocation(line: 8, scope:
27-
// CV-CHECK-DAG: ![[ADD]] = !DILocation(line: 8, scope:
2827
// CV-CHECK-DAG: ![[SLT]] = !DILocation(line: 10, scope:
2928
// CV-CHECK-DAG: !DILexicalBlock({{.*}}, line: 10)
3029
// CV-CHECK-DAG: ![[SUB]] = !DILocation(line: 12, scope:

test/DebugInfo/linetable-codeview.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ func mySwitch(_ a: Int64) {
2525
} // line 25
2626
}
2727
}
28+
func foo() {
29+
var myArray: [Int64] = [] // line 29
30+
}
2831

2932
// func arithmetic(_ a: Int64, _ b: Int64)
3033
// CHECK: define {{.*}} @"$S4main10arithmeticyys5Int64V_ADtF"(i64, i64)
@@ -55,13 +58,21 @@ func mySwitch(_ a: Int64) {
5558
// CHECK: ret void
5659

5760
// func mySwitch(_ a: Int64)
61+
// CHECK: define {{.*}} @"$S4main8mySwitchyys5Int64VF"
5862
// CHECK: call { i64, i1 } @llvm.ssub.with.overflow.i64{{.*}}
5963
// CHECK: br label %[[RETLABEL:[0-9]+]], !dbg ![[CASE:[0-9]+]]
6064
// CHECK: call { i64, i1 } @llvm.sadd.with.overflow.i64{{.*}}
6165
// CHECK: br label %[[RETLABEL]], !dbg ![[DEFAULTCLEANUP:[0-9]+]]
6266
// CHECK: ; <label>:[[RETLABEL]]:
6367
// CHECK-NEXT: ret void
6468

69+
// func foo()
70+
// CHECK: define {{.*}} @"$S4main3fooyyF"
71+
// CHECK: call void @llvm.dbg.declare(metadata %TSa* %myArray,
72+
// CHECK-SAME: !dbg ![[ARRAY:[0-9]+]]
73+
// CHECK: call swiftcc { {{.*}} } @"$Ss27_allocateUninitializedArrayySayxG_BptBwlF"
74+
// CHECK-SAME: !dbg ![[ARRAY]]
75+
// CHECK: ret void
6576

6677
// CHECK-DAG: ![[ADD]] = !DILocation(line: 4, scope:
6778
// CHECK-DAG: ![[DIV]] = !DILocation(line: 5, scope:
@@ -78,3 +89,4 @@ func mySwitch(_ a: Int64) {
7889
// CHECK-DAG: ![[FORBODY]] = !DILocation(line: 16, scope:
7990
// CHECK-DAG: ![[CASE]] = !DILocation(line: 22, scope:
8091
// CHECK-DAG: ![[DEFAULTCLEANUP]] = !DILocation(line: 25, scope:
92+
// CHECK-DAG: ![[ARRAY]] = !DILocation(line: 29, scope:

0 commit comments

Comments
 (0)