Skip to content

Commit 53d1844

Browse files
committed
[DebugInfo] Emit witness and objc method declarations in debug info
When emitting a method definition in debug info, the compiler should also emit the method's declaration, because LLVM LTO can't unify type definitions when a child DIE is a full subprogram definition. This is already the behavior for standard methods, this patch implements the same behavior for witness and objc methods as well. rdar://123334375
1 parent ab9e07d commit 53d1844

File tree

3 files changed

+36
-1
lines changed

3 files changed

+36
-1
lines changed

lib/IRGen/IRGenDebugInfo.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2834,7 +2834,9 @@ IRGenDebugInfoImpl::emitFunction(const SILDebugScope *DS, llvm::Function *Fn,
28342834
// Because there's no good way to cross the CU boundary to insert a nested
28352835
// DISubprogram definition in one CU into a type defined in another CU when
28362836
// doing LTO builds.
2837-
if (Rep == SILFunctionTypeRepresentation::Method) {
2837+
if (Rep == SILFunctionTypeRepresentation::Method ||
2838+
Rep == SILFunctionTypeRepresentation::ObjCMethod ||
2839+
Rep == SILFunctionTypeRepresentation::WitnessMethod) {
28382840
llvm::DISubprogram::DISPFlags SPFlags = llvm::DISubprogram::toSPFlags(
28392841
/*IsLocalToUnit=*/Fn ? Fn->hasInternalLinkage() : true,
28402842
/*IsDefinition=*/false, /*IsOptimized=*/Opts.shouldOptimize());
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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 witness method.
4+
5+
// CHECK: define{{.*}}@"$s4main14PutCharPrinterCAA09CharacterD0A2aDPxycfCTW"{{.*}} !dbg ![[INIT_DEF_DBG:[0-9]+]]
6+
// CHECK: ![[INIT_DEF_DBG]] = distinct !DISubprogram(name: "init", linkageName: "$s4main14PutCharPrinterCAA09CharacterD0A2aDPxycfCTW"
7+
// CHECK-SAME: DISPFlagDefinition{{.*}} declaration: ![[FUNC_DEF_DBG:[0-9]+]]
8+
// CHECK: ![[FUNC_DEF_DBG]] = !DISubprogram(name: "init", linkageName: "$s4main14PutCharPrinterCAA09CharacterD0A2aDPxycfCTW"
9+
10+
protocol CharacterPrinter {
11+
init()
12+
}
13+
14+
class PutCharPrinter: CharacterPrinter {
15+
public required init() {}
16+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// REQUIRES: objc_interop
2+
// RUN: %target-swift-frontend -primary-file %s -emit-ir -gdwarf-types -o - | %FileCheck %s
3+
4+
// Verify that we added a declaration for a witness method.
5+
6+
// CHECK: define {{.*}}"$s4main9SomeClassC3fooyyFTo"{{.*}} !dbg ![[INIT_DEF_DBG:[0-9]+]]
7+
// CHECK: ![[INIT_DEF_DBG]] = distinct !DISubprogram(name: "foo", linkageName: "$s4main9SomeClassC3fooyyFTo"
8+
// CHECK-SAME: DISPFlagDefinition{{.*}} declaration: ![[FUNC_DEF_DBG:[0-9]+]]
9+
// CHECK: ![[FUNC_DEF_DBG]] = !DISubprogram(name: "foo", linkageName: "$s4main9SomeClassC3fooyyFTo"
10+
11+
import Foundation
12+
13+
class SomeClass {
14+
public required init() {}
15+
16+
@objc func foo() {}
17+
}

0 commit comments

Comments
 (0)