Skip to content

[DebugInfo] Emit distinct DILocation for different inline instances #66744

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/IRGen/IRGenDebugInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
// Pretend transparent functions don't exist.
if (!Scope)
return createInlinedAt(CS);
auto InlinedAt = llvm::DILocation::get(
auto InlinedAt = llvm::DILocation::getDistinct(
IGM.getLLVMContext(), L.line, L.column, Scope, createInlinedAt(CS));
InlinedAtCache.insert({CS, llvm::TrackingMDNodeRef(InlinedAt)});
return InlinedAt;
Expand Down
8 changes: 4 additions & 4 deletions test/DebugInfo/inlinedAt.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ public func f(_ i : Int) -> Int { // 301
// CHECK: ![[F:.*]] = distinct !DISubprogram(name: "f",
// CHECK: ![[G:.*]] = distinct !DISubprogram(name: "g",

// CHECK: ![[L3:.*]] = !DILocation(line: 302, column: 10,
// CHECK-SAME: scope: ![[F:.*]])
// CHECK: ![[L3:.*]] = distinct !DILocation(line: 302, column: 10,
// CHECK-SAME: scope: ![[F:.*]])
// CHECK: ![[H:.*]] = distinct !DISubprogram(name: "h",
// CHECK: ![[L1]] = !DILocation(line: 101, column: 8, scope: ![[H]],
// CHECK-SAME: inlinedAt: ![[L2:.*]])
// CHECK: ![[L2]] = !DILocation(line: 203, column: 10, scope: ![[G]],
// CHECK-SAME: inlinedAt: ![[L3]])
// CHECK: ![[L2]] = distinct !DILocation(line: 203, column: 10, scope: ![[G]],
// CHECK-SAME: inlinedAt: ![[L3]])

2 changes: 1 addition & 1 deletion test/DebugInfo/inlinescopes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func transparent(_ x: Int64) -> Int64 { return noinline(x) }
func inlined(_ x: Int64) -> Int64 {
let result = transparent(x)
// CHECK-DAG: ![[CALL]] = !DILocation(line: [[@LINE-1]], column: {{.*}}, scope: ![[INLINED1:.*]], inlinedAt: ![[INLINEDAT:.*]])
// CHECK-DAG: ![[INLINEDAT]] = !DILocation({{.*}}scope: ![[INLINEDAT1:[0-9]+]]
// CHECK-DAG: ![[INLINEDAT]] = distinct !DILocation({{.*}}scope: ![[INLINEDAT1:[0-9]+]]
// CHECK-DAG: ![[INLINED1]] = distinct !DILexicalBlock(scope: ![[INLINED:[0-9]+]]
// Check if the inlined and removed function still has the correct linkage name.
// CHECK-DAG: ![[INLINED]] = distinct !DISubprogram(name: "inlined", linkageName: "$s4main7inlinedys5Int64VADF"
Expand Down
72 changes: 72 additions & 0 deletions test/IRGen/debug_scope_distinct.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// RUN: %empty-directory(%t)
// RUN: %target-swiftc_driver -DM -emit-module -emit-module-path %t/M.swiftmodule %s -module-name M
// RUN: %target-swiftc_driver -O -g -I %t -c %s -emit-ir -o - | %FileCheck %s
// RUN: %target-swiftc_driver -O -g -I %t -c %s -o /dev/null

// CHECK: define {{.*}} void @"$s4main1TV4move2byyAC13TangentVectorV_tF"
// CHECK-SAME: ptr {{.*}} %[[ARG_PTR:.*]],
//
// CHECK: %[[ARG0:.*]] = load {{.*}} %[[ARG_PTR]]
// CHECK: call void @llvm.dbg.value(metadata {{.*}} %[[ARG0]], metadata ![[VAR1:[0-9]+]], metadata !DIExpression(DW_OP_LLVM_fragment, 0, 64)), !dbg ![[LOC1:[0-9]+]]
// CHECK: %[[ARG1_GEP:.*]] = getelementptr inbounds i8, ptr %[[ARG_PTR]], i64 8
// CHECK: %[[ARG1:.*]] = load {{.*}} %[[ARG1_GEP]]
// CHECK: call void @llvm.dbg.value(metadata {{.*}} %[[ARG1]], metadata ![[VAR1]], metadata !DIExpression(DW_OP_LLVM_fragment, 64, 8)), !dbg ![[LOC1]]
//
// CHECK: %[[ARG2_GEP:.*]] = getelementptr inbounds %T4main1TV13TangentVectorV, ptr %[[ARG_PTR]], i64 0, i32 2
// CHECK: %[[ARG2:.*]] = load {{.*}} %[[ARG2_GEP]]
// CHECK: call void @llvm.dbg.value(metadata {{.*}} %[[ARG2]], metadata ![[VAR1]], metadata !DIExpression(DW_OP_LLVM_fragment, 0, 64)), !dbg ![[LOC2:[0-9]+]]
// CHECK: %[[ARG3_GEP:.*]] = getelementptr inbounds %T4main1TV13TangentVectorV, ptr %[[ARG_PTR]], i64 0, i32 2, i32 0, i32 1
// CHECK: %[[ARG3:.*]] = load {{.*}} %[[ARG3_GEP]]
// CHECK: call void @llvm.dbg.value(metadata {{.*}} %[[ARG3]], metadata ![[VAR1]], metadata !DIExpression(DW_OP_LLVM_fragment, 64, 8)), !dbg ![[LOC2]]

// CHECK-DAG: ![[VAR1]] = !DILocalVariable(name: "offset", arg: 1, scope: ![[SCOPE:[0-9]+]]

// CHECK-DAG: ![[LOC1]] = !DILocation(line: 0, scope: ![[SCOPE]], inlinedAt: ![[LOCINL1:[0-9]+]])
// CHECK-DAG: ![[LOCINL1]] = distinct !DILocation(line: 0, scope: ![[SUBPROG:[0-9]+]])
// CHECK-DAG: ![[SUBPROG]] = distinct !DISubprogram(name: "move", linkageName: "$s4main1TV4move2byyAC13TangentVectorV_tF"

// CHECK-DAG: ![[LOC2]] = !DILocation(line: 0, scope: ![[SCOPE]], inlinedAt: ![[LOCINL2:[0-9]+]])
// CHECK-DAG: ![[LOCINL2]] = distinct !DILocation(line: 0, scope: ![[SUBPROG]])

#if M
import _Differentiation

public struct S<T> {
class C {}
let c: C
internal var b: Int8
init(_ initb: Int8) {
b = initb;
c = C();
}
}

extension S: AdditiveArithmetic {
public static var zero: S { let ret = S(0); return ret; }
public static func == (_ lhs: S, _ rhs: S) -> Bool { return lhs.b == rhs.b; }
public static func + (_ lhs: S, _ rhs: S) -> S { var ret = lhs; ret.b += rhs.b; return ret; }
public static func - (_ lhs: S, _ rhs: S) -> S { var ret = lhs; ret.b -= rhs.b; return ret; }
}

extension S: Differentiable {
public typealias TangentVector = S
}

#else
import _Differentiation
import M

struct T: Differentiable {
var u1: U
var u2: U
}

struct U: Differentiable {
var s: S<Float>
var v: V
}

struct V: Differentiable {
var s: S<Float>
}
#endif
4 changes: 2 additions & 2 deletions test/Macros/macro_expand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,9 @@ func testFileID(a: Int, b: Int) {
// CHECK-AST: macro_expansion_expr type='String'{{.*}}name=line
print("Builtin result is \(#fileID)")
print(
/// CHECK-IR-DAG: ![[L1:[0-9]+]] = !DILocation(line: [[@LINE+1]], column: 5
/// CHECK-IR-DAG: ![[L1:[0-9]+]] = distinct !DILocation(line: [[@LINE+1]], column: 5
#addBlocker(
/// CHECK-IR-DAG: ![[L2:[0-9]+]] = !DILocation({{.*}}inlinedAt: ![[L1]])
/// CHECK-IR-DAG: ![[L2:[0-9]+]] = distinct !DILocation({{.*}}inlinedAt: ![[L1]])
/// CHECK-IR-DAG: ![[L3:[0-9]+]] = !DILocation({{.*}}inlinedAt: ![[L2]])
#stringify(a - b)
)
Expand Down