Skip to content

Commit 1f6091a

Browse files
Merge pull request #66744 from asavonic/debuginfo-fragment-distinct-inline-loc
[DebugInfo] Emit distinct DILocation for different inline instances
2 parents 8af81a3 + ca6e742 commit 1f6091a

File tree

5 files changed

+80
-8
lines changed

5 files changed

+80
-8
lines changed

lib/IRGen/IRGenDebugInfo.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
415415
// Pretend transparent functions don't exist.
416416
if (!Scope)
417417
return createInlinedAt(CS);
418-
auto InlinedAt = llvm::DILocation::get(
418+
auto InlinedAt = llvm::DILocation::getDistinct(
419419
IGM.getLLVMContext(), L.line, L.column, Scope, createInlinedAt(CS));
420420
InlinedAtCache.insert({CS, llvm::TrackingMDNodeRef(InlinedAt)});
421421
return InlinedAt;

test/DebugInfo/inlinedAt.swift

+4-4
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@ public func f(_ i : Int) -> Int { // 301
4040
// CHECK: ![[F:.*]] = distinct !DISubprogram(name: "f",
4141
// CHECK: ![[G:.*]] = distinct !DISubprogram(name: "g",
4242

43-
// CHECK: ![[L3:.*]] = !DILocation(line: 302, column: 10,
44-
// CHECK-SAME: scope: ![[F:.*]])
43+
// CHECK: ![[L3:.*]] = distinct !DILocation(line: 302, column: 10,
44+
// CHECK-SAME: scope: ![[F:.*]])
4545
// CHECK: ![[H:.*]] = distinct !DISubprogram(name: "h",
4646
// CHECK: ![[L1]] = !DILocation(line: 101, column: 8, scope: ![[H]],
4747
// CHECK-SAME: inlinedAt: ![[L2:.*]])
48-
// CHECK: ![[L2]] = !DILocation(line: 203, column: 10, scope: ![[G]],
49-
// CHECK-SAME: inlinedAt: ![[L3]])
48+
// CHECK: ![[L2]] = distinct !DILocation(line: 203, column: 10, scope: ![[G]],
49+
// CHECK-SAME: inlinedAt: ![[L3]])
5050

test/DebugInfo/inlinescopes.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ func transparent(_ x: Int64) -> Int64 { return noinline(x) }
2626
func inlined(_ x: Int64) -> Int64 {
2727
let result = transparent(x)
2828
// CHECK-DAG: ![[CALL]] = !DILocation(line: [[@LINE-1]], column: {{.*}}, scope: ![[INLINED1:.*]], inlinedAt: ![[INLINEDAT:.*]])
29-
// CHECK-DAG: ![[INLINEDAT]] = !DILocation({{.*}}scope: ![[INLINEDAT1:[0-9]+]]
29+
// CHECK-DAG: ![[INLINEDAT]] = distinct !DILocation({{.*}}scope: ![[INLINEDAT1:[0-9]+]]
3030
// CHECK-DAG: ![[INLINED1]] = distinct !DILexicalBlock(scope: ![[INLINED:[0-9]+]]
3131
// Check if the inlined and removed function still has the correct linkage name.
3232
// CHECK-DAG: ![[INLINED]] = distinct !DISubprogram(name: "inlined", linkageName: "$s4main7inlinedys5Int64VADF"

test/IRGen/debug_scope_distinct.swift

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-swiftc_driver -DM -emit-module -emit-module-path %t/M.swiftmodule %s -module-name M
3+
// RUN: %target-swiftc_driver -O -g -I %t -c %s -emit-ir -o - | %FileCheck %s
4+
// RUN: %target-swiftc_driver -O -g -I %t -c %s -o /dev/null
5+
6+
// CHECK: define {{.*}} void @"$s4main1TV4move2byyAC13TangentVectorV_tF"
7+
// CHECK-SAME: ptr {{.*}} %[[ARG_PTR:.*]],
8+
//
9+
// CHECK: %[[ARG0:.*]] = load {{.*}} %[[ARG_PTR]]
10+
// CHECK: call void @llvm.dbg.value(metadata {{.*}} %[[ARG0]], metadata ![[VAR1:[0-9]+]], metadata !DIExpression(DW_OP_LLVM_fragment, 0, 64)), !dbg ![[LOC1:[0-9]+]]
11+
// CHECK: %[[ARG1_GEP:.*]] = getelementptr inbounds i8, ptr %[[ARG_PTR]], i64 8
12+
// CHECK: %[[ARG1:.*]] = load {{.*}} %[[ARG1_GEP]]
13+
// CHECK: call void @llvm.dbg.value(metadata {{.*}} %[[ARG1]], metadata ![[VAR1]], metadata !DIExpression(DW_OP_LLVM_fragment, 64, 8)), !dbg ![[LOC1]]
14+
//
15+
// CHECK: %[[ARG2_GEP:.*]] = getelementptr inbounds %T4main1TV13TangentVectorV, ptr %[[ARG_PTR]], i64 0, i32 2
16+
// CHECK: %[[ARG2:.*]] = load {{.*}} %[[ARG2_GEP]]
17+
// CHECK: call void @llvm.dbg.value(metadata {{.*}} %[[ARG2]], metadata ![[VAR1]], metadata !DIExpression(DW_OP_LLVM_fragment, 0, 64)), !dbg ![[LOC2:[0-9]+]]
18+
// CHECK: %[[ARG3_GEP:.*]] = getelementptr inbounds %T4main1TV13TangentVectorV, ptr %[[ARG_PTR]], i64 0, i32 2, i32 0, i32 1
19+
// CHECK: %[[ARG3:.*]] = load {{.*}} %[[ARG3_GEP]]
20+
// CHECK: call void @llvm.dbg.value(metadata {{.*}} %[[ARG3]], metadata ![[VAR1]], metadata !DIExpression(DW_OP_LLVM_fragment, 64, 8)), !dbg ![[LOC2]]
21+
22+
// CHECK-DAG: ![[VAR1]] = !DILocalVariable(name: "offset", arg: 1, scope: ![[SCOPE:[0-9]+]]
23+
24+
// CHECK-DAG: ![[LOC1]] = !DILocation(line: 0, scope: ![[SCOPE]], inlinedAt: ![[LOCINL1:[0-9]+]])
25+
// CHECK-DAG: ![[LOCINL1]] = distinct !DILocation(line: 0, scope: ![[SUBPROG:[0-9]+]])
26+
// CHECK-DAG: ![[SUBPROG]] = distinct !DISubprogram(name: "move", linkageName: "$s4main1TV4move2byyAC13TangentVectorV_tF"
27+
28+
// CHECK-DAG: ![[LOC2]] = !DILocation(line: 0, scope: ![[SCOPE]], inlinedAt: ![[LOCINL2:[0-9]+]])
29+
// CHECK-DAG: ![[LOCINL2]] = distinct !DILocation(line: 0, scope: ![[SUBPROG]])
30+
31+
#if M
32+
import _Differentiation
33+
34+
public struct S<T> {
35+
class C {}
36+
let c: C
37+
internal var b: Int8
38+
init(_ initb: Int8) {
39+
b = initb;
40+
c = C();
41+
}
42+
}
43+
44+
extension S: AdditiveArithmetic {
45+
public static var zero: S { let ret = S(0); return ret; }
46+
public static func == (_ lhs: S, _ rhs: S) -> Bool { return lhs.b == rhs.b; }
47+
public static func + (_ lhs: S, _ rhs: S) -> S { var ret = lhs; ret.b += rhs.b; return ret; }
48+
public static func - (_ lhs: S, _ rhs: S) -> S { var ret = lhs; ret.b -= rhs.b; return ret; }
49+
}
50+
51+
extension S: Differentiable {
52+
public typealias TangentVector = S
53+
}
54+
55+
#else
56+
import _Differentiation
57+
import M
58+
59+
struct T: Differentiable {
60+
var u1: U
61+
var u2: U
62+
}
63+
64+
struct U: Differentiable {
65+
var s: S<Float>
66+
var v: V
67+
}
68+
69+
struct V: Differentiable {
70+
var s: S<Float>
71+
}
72+
#endif

test/Macros/macro_expand.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,9 @@ func testFileID(a: Int, b: Int) {
140140
// CHECK-AST: macro_expansion_expr type='String'{{.*}}name=line
141141
print("Builtin result is \(#fileID)")
142142
print(
143-
/// CHECK-IR-DAG: ![[L1:[0-9]+]] = !DILocation(line: [[@LINE+1]], column: 5
143+
/// CHECK-IR-DAG: ![[L1:[0-9]+]] = distinct !DILocation(line: [[@LINE+1]], column: 5
144144
#addBlocker(
145-
/// CHECK-IR-DAG: ![[L2:[0-9]+]] = !DILocation({{.*}}inlinedAt: ![[L1]])
145+
/// CHECK-IR-DAG: ![[L2:[0-9]+]] = distinct !DILocation({{.*}}inlinedAt: ![[L1]])
146146
/// CHECK-IR-DAG: ![[L3:[0-9]+]] = !DILocation({{.*}}inlinedAt: ![[L2]])
147147
#stringify(a - b)
148148
)

0 commit comments

Comments
 (0)