Skip to content

Commit 3ae5389

Browse files
committed
[IRGen][DebugInfo] split method declaration and definition.
1 parent 017d31f commit 3ae5389

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

lib/IRGen/IRGenDebugInfo.cpp

+12
Original file line numberDiff line numberDiff line change
@@ -2468,6 +2468,18 @@ IRGenDebugInfoImpl::emitFunction(const SILDebugScope *DS, llvm::Function *Fn,
24682468
/*IsLocalToUnit=*/Fn ? Fn->hasInternalLinkage() : true,
24692469
/*IsDefinition=*/true, /*IsOptimized=*/Opts.shouldOptimize());
24702470

2471+
// When the function is a method, we only want a DW_AT_declaration there,
2472+
// because LLVM LTO can't unify type definitions when a child DIE is a full
2473+
// subprogram definition.
2474+
if (Rep == SILFunctionTypeRepresentation::Method) {
2475+
llvm::DISubprogram::DISPFlags SPFlags = llvm::DISubprogram::toSPFlags(
2476+
/*IsLocalToUnit=*/Fn ? Fn->hasInternalLinkage() : true,
2477+
/*IsDefinition=*/false, /*IsOptimized=*/Opts.shouldOptimize());
2478+
Decl = DBuilder.createMethod(Scope, Name, LinkageName, File, Line, DIFnTy,
2479+
0, 0, nullptr, Flags, SPFlags,
2480+
TemplateParameters, Error);
2481+
}
2482+
24712483
// Construct the DISubprogram.
24722484
llvm::DISubprogram *SP = DBuilder.createFunction(
24732485
Scope, Name, LinkageName, File, Line, DIFnTy, ScopeLine, Flags, SPFlags,
+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// RUN: %target-swift-frontend -primary-file %s -emit-ir -gdwarf-types -o - | %FileCheck %s
2+
3+
// Verify that we added a declaration for a method.
4+
5+
// CHECK: define{{.*}}foo_static_method{{.*}} !dbg ![[FOO_STATIC_METHOD_DEF_DBG:[0-9]+]]
6+
// CHECK: define{{.*}}foo_method{{.*}} !dbg ![[FOO_METHOD_DEF_DBG:[0-9]+]]
7+
// CHECK: define{{.*}}bar_static_method{{.*}} !dbg ![[BAR_STATIC_METHOD_DEF_DBG:[0-9]+]]
8+
// CHECK: define{{.*}}bar_method{{.*}} !dbg ![[BAR_METHOD_DEF_DBG:[0-9]+]]
9+
// CHECK: define{{.*}}a_function{{.*}} !dbg ![[FUNC_DEF_DBG:[0-9]+]]
10+
11+
// CHECK-DAG: ![[FOO_DBG:[0-9]+]] = !DICompositeType(tag: {{.*}} name: "Foo", {{.*}} identifier:
12+
public struct Foo {
13+
// CHECK-DAG: ![[FOO_STATIC_METHOD_DEF_DBG]] = distinct !DISubprogram(name: "foo_static_method"{{.*}}, scope: ![[FOO_DBG]]{{.*}}DISPFlagDefinition{{.*}}, declaration: ![[FOO_STATIC_METHOD_DECL_DBG:[0-9]+]]
14+
// CHECK-DAG: ![[FOO_STATIC_METHOD_DECL_DBG]] = !DISubprogram(name: "foo_static_method"{{.*}}, scope: ![[FOO_DBG]]
15+
static func foo_static_method() {}
16+
// CHECK-DAG: ![[FOO_METHOD_DEF_DBG]] = distinct !DISubprogram(name: "foo_method"{{.*}}, scope: ![[FOO_DBG]]{{.*}}DISPFlagDefinition{{.*}}, declaration: ![[FOO_METHOD_DECL_DBG:[0-9]+]]
17+
// CHECK-DAG: ![[FOO_METHOD_DECL_DBG]] = !DISubprogram(name: "foo_method"{{.*}}, scope: ![[FOO_DBG]]
18+
func foo_method() {}
19+
}
20+
21+
// CHECK-DAG: ![[BAR_DBG:[0-9]+]] = !DICompositeType(tag: {{.*}} name: "Bar", {{.*}} identifier:
22+
public class Bar {
23+
// CHECK-DAG: ![[BAR_STATIC_METHOD_DEF_DBG]] = distinct !DISubprogram(name: "bar_static_method"{{.*}}, scope: ![[BAR_DBG]]{{.*}}DISPFlagDefinition{{.*}}, declaration: ![[BAR_STATIC_METHOD_DECL_DBG:[0-9]+]]
24+
// CHECK-DAG: ![[BAR_STATIC_METHOD_DECL_DBG]] = !DISubprogram(name: "bar_static_method"{{.*}}, scope: ![[BAR_DBG]]
25+
static func bar_static_method() {}
26+
// CHECK-DAG: ![[BAR_METHOD_DEF_DBG]] = distinct !DISubprogram(name: "bar_method"{{.*}}, scope: ![[BAR_DBG]]{{.*}}DISPFlagDefinition{{.*}}, declaration: ![[BAR_METHOD_DECL_DBG:[0-9]+]]
27+
// CHECK-DAG: ![[BAR_METHOD_DECL_DBG]] = !DISubprogram(name: "bar_method"{{.*}}, scope: ![[BAR_DBG]]
28+
func bar_method() {}
29+
}
30+
31+
// CHECK: ![[FUNC_DEF_DBG]] = distinct !DISubprogram(name: "a_function"
32+
// CHECK-NOT: declaration
33+
// CHECK-SAME: DISPFlagDefinition
34+
// CHECK-NOT: declaration
35+
// CHECK-SAME: )
36+
func a_function() {}
37+

0 commit comments

Comments
 (0)