Skip to content

Commit a5ce0dc

Browse files
committed
[cxx-interop][IRGen] Emit type metadata accessors correctly
This change makes sure we correctly emit IR for type metadata accessors for C++ reference types. This fixes linker errors when a type metadata of a C++ reference type is used in multiple object files that are later linked together, for instance, if a C++ reference type is conformed to different Swift protocols in different Swift source files: ``` duplicate symbol 'type metadata accessor for __C.SharedObject' in: main.o second.o ld: 1 duplicate symbols ``` rdar://129027705
1 parent 67c0fd8 commit a5ce0dc

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

lib/IRGen/MetadataRequest.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1102,9 +1102,6 @@ MetadataAccessStrategy irgen::getTypeMetadataAccessStrategy(CanType type) {
11021102
assert(type->hasUnboundGenericType());
11031103
}
11041104

1105-
if (type->isForeignReferenceType())
1106-
return MetadataAccessStrategy::PublicUniqueAccessor;
1107-
11081105
if (requiresForeignTypeMetadata(nominal))
11091106
return MetadataAccessStrategy::ForeignAccessor;
11101107

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: split-file %s %t
3+
// RUN: %target-build-swift -I %S/Inputs %t/main.swift %t/second.swift -cxx-interoperability-mode=default -Xfrontend -disable-availability-checking
4+
5+
// XFAIL: OS=windows-msvc
6+
7+
//--- main.swift
8+
import ReferenceCounted
9+
10+
protocol P1 {}
11+
extension GlobalCount : P1 {}
12+
13+
//--- second.swift
14+
import ReferenceCounted
15+
16+
protocol P2 {}
17+
extension GlobalCount : P2 {}

0 commit comments

Comments
 (0)