Skip to content

Commit bd1cc77

Browse files
committed
[IRGen][DebugInfo] split method declaration and definition.
1 parent 66a7ebe commit bd1cc77

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

lib/IRGen/IRGenDebugInfo.cpp

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

2470+
// When the function is a method, we only want a DW_AT_declaration there,
2471+
// because LLVM LTO can't unify type definitions when a child DIE is a full
2472+
// subprogram definition.
2473+
if (Rep == SILFunctionTypeRepresentation::Method) {
2474+
llvm::DISubprogram::DISPFlags SPFlags = llvm::DISubprogram::toSPFlags(
2475+
/*IsLocalToUnit=*/Fn ? Fn->hasInternalLinkage() : true,
2476+
/*IsDefinition=*/false, /*IsOptimized=*/Opts.shouldOptimize());
2477+
Decl = DBuilder.createMethod(Scope, Name, LinkageName, File, Line, DIFnTy,
2478+
0, 0, nullptr, Flags, SPFlags,
2479+
TemplateParameters, Error);
2480+
}
2481+
24702482
// Construct the DISubprogram.
24712483
llvm::DISubprogram *SP = DBuilder.createFunction(
24722484
Scope, Name, LinkageName, File, Line, DIFnTy, ScopeLine, Flags, SPFlags,

test/DebugInfo/method.swift

+27
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)