mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
LLVM seems to determine a variable instance as a combination of DILocalVariable and DILocation. Therefore if multiple llvm.dbg.declare have the same variable/location parameters, they are considered to be referencing the same instance of variable. Swift IRGen emits a set of llvm.dbg.declare calls for every variable instance (with unique SILDebugScope), so it is important that these calls have distinct variable/location parameters. Otherwise their DIExpression may be incorrect when treated as referencing the same variable. For example, if they have a DIExpression with fragments, we will see this as multiple declarations of the same fragment. LLVM detects this and crashes with assertion failure: DwarfExpression.cpp:679: void llvm::DwarfExpression::addFragmentOffset(const llvm::DIExpression *): Assertion `FragmentOffset >= OffsetInBits && "overlapping or duplicate fragments"' failed. The patch resolves #55703. The LIT test (debug_scope_distinct.swift) is the reproducer from that issue.
38 lines
1.5 KiB
Swift
38 lines
1.5 KiB
Swift
// RUN: %empty-directory(%t)
|
|
// RUN: echo "public var x = Int64()" \
|
|
// RUN: | %target-swift-frontend -module-name FooBar -emit-module -o %t -
|
|
// RUN: %target-swift-frontend %s -O -I %t -emit-ir -g -o %t.ll
|
|
// RUN: %FileCheck %s < %t.ll
|
|
// RUN: %FileCheck %s -check-prefix=TRANSPARENT-CHECK < %t.ll
|
|
|
|
// CHECK: define{{( dllexport)?}}{{( protected)?( signext)?}} i32 @main{{.*}}
|
|
// CHECK: call swiftcc i64 @"$s4main8noinlineys5Int64VADF"(i64 %{{.*}})
|
|
// CHECK-SAME: !dbg ![[CALL:.*]]
|
|
// CHECK-DAG: ![[TOPLEVEL:.*]] = !DIFile(filename: "{{.*}}inlinescopes.swift"
|
|
|
|
import FooBar
|
|
|
|
@inline(never)
|
|
func use(_ x: Int64) -> Int64 { return x }
|
|
|
|
@inline(never)
|
|
func noinline(_ x: Int64) -> Int64 { return use(x) }
|
|
|
|
@_transparent
|
|
func transparent(_ x: Int64) -> Int64 { return noinline(x) }
|
|
|
|
|
|
@inline(__always)
|
|
func inlined(_ x: Int64) -> Int64 {
|
|
let result = transparent(x)
|
|
// CHECK-DAG: ![[CALL]] = !DILocation(line: [[@LINE-1]], column: {{.*}}, scope: ![[INLINED1:.*]], inlinedAt: ![[INLINEDAT:.*]])
|
|
// 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"
|
|
// TRANSPARENT-CHECK-NOT: !DISubprogram(name: "transparent"
|
|
return result
|
|
}
|
|
// CHECK-DAG: !DIGlobalVariable(name: "y",{{.*}} file: ![[TOPLEVEL]],{{.*}} line: [[@LINE+1]]
|
|
public let y = inlined(x)
|