Skip to content

Commit dc70d2f

Browse files
committed
[IRGen][DebugInfo] split method declaration and definition.
1 parent 9e73dad commit dc70d2f

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

lib/IRGen/IRGenDebugInfo.cpp

Lines changed: 12 additions & 0 deletions
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,

test/DebugInfo/method.swift

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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+
public struct Foo {
5+
static func static_method() {}
6+
func method() {}
7+
}
8+
9+
public class Bar {
10+
static func static_method() {}
11+
func method() {}
12+
}
13+
14+
func a_function() {}
15+
16+
// CHECK: distinct !DISubprogram(name: "static_method",
17+
// CHECK-SAME: declaration:
18+
// CHECK: distinct !DISubprogram(name: "method",
19+
// CHECK-SAME: declaration:
20+
// CHECK: distinct !DISubprogram(name: "static_method",
21+
// CHECK-SAME: declaration:
22+
// CHECK: distinct !DISubprogram(name: "method",
23+
// CHECK-SAME: declaration:
24+
25+
// CHECK: distinct !DISubprogram(name: "a_function",
26+
// CHECK-NOT: declaration:
27+
// CHECK-SAME: )

0 commit comments

Comments
 (0)