Skip to content

Commit 72df014

Browse files
authored
Merge pull request swiftlang#18447 from sparkasaurusRex/codeview-linetables
Reduce breaks in CodeView linetables
2 parents 6ade7c1 + 924d51f commit 72df014

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
@@ -1575,6 +1575,9 @@ void IRGenDebugInfoImpl::setCurrentLoc(IRBuilder &Builder,
15751575
if (!Scope)
15761576
return;
15771577

1578+
// NOTE: In CodeView, zero is not an artificial line location. We try to
1579+
// avoid those line locations near user code to reduce the number
1580+
// of breaks in the linetables.
15781581
SILLocation::DebugLoc L;
15791582
SILFunction *Fn = DS->getInlinedFunction();
15801583
if (Fn && (Fn->isThunk() || Fn->isTransparent())) {
@@ -1583,10 +1586,11 @@ void IRGenDebugInfoImpl::setCurrentLoc(IRBuilder &Builder,
15831586
// Reuse the last source location if we are still in the same
15841587
// scope to get a more contiguous line table.
15851588
L = LastDebugLoc;
1586-
} else if (DS == LastScope && Loc.is<ArtificialUnreachableLocation>() &&
1589+
} else if (DS == LastScope &&
1590+
(Loc.is<ArtificialUnreachableLocation>() || Loc.isLineZero(SM)) &&
15871591
Opts.DebugInfoFormat == IRGenDebugInfoFormat::CodeView) {
1588-
// Remove unreachable locations with line zero because line zero does not
1589-
// represent an artificial location in CodeView.
1592+
// If the scope has not changed and the line number is either zero or
1593+
// artificial, we want to keep the most recent debug location.
15901594
L = LastDebugLoc;
15911595
} else {
15921596
// 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)
@@ -62,6 +65,14 @@ func mySwitch(_ a: Int64) {
6265
// CHECK: ; <label>:[[RETLABEL]]:
6366
// CHECK-NEXT: ret void
6467

68+
// func foo()
69+
// CHECK: define {{.*}} @"$S4main3fooyyF"
70+
// CHECK: %[[MYARRAY:.*]] = alloca
71+
// CHECK: call void @llvm.dbg.declare(metadata %TSa* %[[MYARRAY]],
72+
// CHECK-SAME: !dbg ![[ARRAY:[0-9]+]]
73+
// CHECK: call swiftcc { {{.*}} } @"${{.*}}_allocateUninitializedArray{{.*}}"
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)