@@ -1148,11 +1148,21 @@ class TypeRefBuilder {
1148
1148
}
1149
1149
1150
1150
// / Extract conforming type's name from a Conformance Descriptor
1151
- llvm::Optional<std::string> getConformingTypeName (
1151
+ // / Returns a pair of (mangledTypeName, fullyQualifiedTypeName)
1152
+ llvm::Optional<std::pair<std::string, std::string>> getConformingTypeName (
1152
1153
const uintptr_t conformanceDescriptorAddress,
1153
1154
const ExternalProtocolConformanceDescriptor<
1154
1155
ObjCInteropKind, PointerSize> &conformanceDescriptor) {
1155
1156
std::string typeName;
1157
+ std::string mangledTypeName = " " ;
1158
+
1159
+ // If this is a conformance added to an ObjC class, detect that here and return class name
1160
+ if (conformanceDescriptor.getTypeKind () == TypeReferenceKind::DirectObjCClassName) {
1161
+ auto className = conformanceDescriptor.getDirectObjCClassName ();
1162
+ typeName = MANGLING_MODULE_OBJC.str () + std::string (" ." ) + className;
1163
+ return std::make_pair (mangledTypeName, typeName);
1164
+ }
1165
+
1156
1166
// Compute the address of the type descriptor as follows:
1157
1167
// - Compute the address of the TypeRef field in the protocol
1158
1168
// descriptor
@@ -1179,6 +1189,21 @@ class TypeRefBuilder {
1179
1189
(const char *)contextDescriptorFieldAddress,
1180
1190
(int32_t )*contextDescriptorOffset);
1181
1191
1192
+ // Instead of a type descriptor this may just be a symbol reference, check that first
1193
+ if (auto symbol = OpaquePointerReader (remote::RemoteAddress (contextTypeDescriptorAddress),
1194
+ PointerSize)) {
1195
+ if (!symbol->getSymbol ().empty ()) {
1196
+ mangledTypeName = symbol->getSymbol ().str ();
1197
+ Demangle::Context Ctx;
1198
+ auto demangledRoot =
1199
+ Ctx.demangleSymbolAsNode (mangledTypeName);
1200
+ assert (demangledRoot->getKind () == Node::Kind::Global);
1201
+ typeName =
1202
+ nodeToString (demangledRoot->getChild (0 )->getChild (0 ));
1203
+ return std::make_pair (mangledTypeName, typeName);
1204
+ }
1205
+ }
1206
+
1182
1207
auto contextTypeDescriptorBytes = OpaqueByteReader (
1183
1208
remote::RemoteAddress (contextTypeDescriptorAddress),
1184
1209
sizeof (ExternalContextDescriptor<ObjCInteropKind, PointerSize>));
@@ -1213,7 +1238,7 @@ class TypeRefBuilder {
1213
1238
typeName = optionalParentName.getValue () + " ." + typeName;
1214
1239
}
1215
1240
1216
- return typeName;
1241
+ return std::make_pair (mangledTypeName, typeName) ;
1217
1242
}
1218
1243
1219
1244
// / Extract protocol name from a Conformance Descriptor
@@ -1317,9 +1342,9 @@ class TypeRefBuilder {
1317
1342
(const ExternalProtocolConformanceDescriptor<
1318
1343
ObjCInteropKind, PointerSize> *)descriptorBytes.get ();
1319
1344
1320
- auto optionalConformingTypeName = getConformingTypeName (
1345
+ auto optionalConformingTypeNamePair = getConformingTypeName (
1321
1346
conformanceDescriptorAddress, *conformanceDescriptorPtr);
1322
- if (!optionalConformingTypeName .hasValue ())
1347
+ if (!optionalConformingTypeNamePair .hasValue ())
1323
1348
return llvm::None;
1324
1349
1325
1350
auto optionalConformanceProtocol = getConformanceProtocolName (
@@ -1328,15 +1353,18 @@ class TypeRefBuilder {
1328
1353
return llvm::None;
1329
1354
1330
1355
std::string mangledTypeName;
1331
- auto it =
1332
- typeNameToManglingMap.find (optionalConformingTypeName.getValue ());
1333
- if (it != typeNameToManglingMap.end ()) {
1334
- mangledTypeName = it->second ;
1356
+ if (optionalConformingTypeNamePair.getValue ().first .empty ()) {
1357
+ auto it = typeNameToManglingMap.find (optionalConformingTypeNamePair.getValue ().second );
1358
+ if (it != typeNameToManglingMap.end ()) {
1359
+ mangledTypeName = it->second ;
1360
+ } else {
1361
+ mangledTypeName = " " ;
1362
+ }
1335
1363
} else {
1336
- mangledTypeName = " " ;
1364
+ mangledTypeName = optionalConformingTypeNamePair. getValue (). first ;
1337
1365
}
1338
1366
1339
- return ProtocolConformanceInfo{optionalConformingTypeName .getValue (),
1367
+ return ProtocolConformanceInfo{optionalConformingTypeNamePair .getValue (). second ,
1340
1368
optionalConformanceProtocol.getValue (),
1341
1369
mangledTypeName};
1342
1370
}
0 commit comments