Skip to content

Commit 334024d

Browse files
committed
[Runtime] Use the old remangler to compute the @objc protocol name.
The “old” mangling that is used for runtime names of @objc protocols uses a simpler substitution scheme, so you can’t simply take a mangled name from the new mangling and fix up the ends. Fixes rdar://problem/45685649.
1 parent 983b5ee commit 334024d

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

stdlib/public/runtime/MetadataLookup.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -997,8 +997,7 @@ class DecodedMetadataBuilder {
997997
#if SWIFT_OBJC_INTEROP
998998
// Look for a Swift-defined @objc protocol with the Swift 3 mangling that
999999
// is used for Objective-C entities.
1000-
std::string objcMangledName =
1001-
"_TtP" + mangledName.substr(0, mangledName.size()-1) + "_";
1000+
std::string objcMangledName = "_Tt" + mangleNodeOld(node) + "_";
10021001
if (auto protocol = objc_getProtocol(objcMangledName.c_str()))
10031002
return ProtocolDescriptorRef::forObjC(protocol);
10041003
#endif

test/Runtime/demangleToMetadataObjC.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ let DemangleToMetadataTests = TestSuite("DemangleToMetadataObjC")
1515
@objc protocol P1 { }
1616
protocol P2 { }
1717
@objc protocol P3: P1 { }
18+
@objc protocol mainP4 { }
1819

1920
DemangleToMetadataTests.test("@objc classes") {
2021
expectEqual(type(of: C()), _typeByMangledName("4main1CC")!)
@@ -25,10 +26,13 @@ DemangleToMetadataTests.test("@objc enums") {
2526
}
2627

2728
func f1_composition_objc_protocol(_: P1) { }
29+
func f1_composition_objc_protocol_P4(_: mainP4) { }
2830

2931
DemangleToMetadataTests.test("@objc protocols") {
3032
expectEqual(type(of: f1_composition_objc_protocol),
3133
_typeByMangledName("yy4main2P1_pc")!)
34+
expectEqual(type(of: f1_composition_objc_protocol_P4),
35+
_typeByMangledName("yy4main0A2P4_pc")!)
3236
}
3337

3438
DemangleToMetadataTests.test("Objective-C classes") {

0 commit comments

Comments
 (0)