@@ -361,24 +361,21 @@ class MetadataReader {
361361 bool isObjC = false ;
362362 bool isBridged = false ;
363363
364- // If we can determine the Objective-C class name, this is probably an
365- // error existential with NSError-compatible layout.
366- std::string ObjCClassName;
367- if (readObjCClassName (*MetadataAddress, ObjCClassName)) {
368- if (ObjCClassName == " __SwiftNativeNSError" )
369- isObjC = true ;
370- else
364+ auto Meta = readMetadata (*MetadataAddress);
365+ if (auto ClassMeta = dyn_cast<TargetClassMetadata<Runtime>>(Meta)) {
366+ if (ClassMeta->isPureObjC ()) {
367+ // If we can determine the Objective-C class name, this is probably an
368+ // error existential with NSError-compatible layout.
369+ std::string ObjCClassName;
370+ if (readObjCClassName (*MetadataAddress, ObjCClassName)) {
371+ if (ObjCClassName == " __SwiftNativeNSError" )
372+ isObjC = true ;
373+ else
374+ isBridged = true ;
375+ }
376+ } else {
371377 isBridged = true ;
372- } else {
373- // Otherwise, we can check to see if this is a class metadata with the
374- // kind value's least significant bit set, which indicates a pure
375- // Swift class.
376- auto Meta = readMetadata (*MetadataAddress);
377- auto ClassMeta = dyn_cast<TargetClassMetadata<Runtime>>(Meta);
378- if (!ClassMeta)
379- return None;
380-
381- isObjC = ClassMeta->isPureObjC ();
378+ }
382379 }
383380
384381 if (isBridged) {
@@ -413,11 +410,15 @@ class MetadataReader {
413410 StoredPointer InstanceAddress =
414411 InstanceMetadataAddressAddress + 2 * sizeof (StoredPointer);
415412
413+ // When built with Objective-C interop, the runtime also stores a conformance
414+ // to Hashable and the base type introducing the Hashable conformance.
415+ if (isObjC)
416+ InstanceAddress += 2 * sizeof (StoredPointer);
417+
416418 // Round up to alignment, and we have the start address of the
417419 // instance payload.
418420 auto AlignmentMask = VWT->getAlignmentMask ();
419- auto Offset = (sizeof (HeapObject) + AlignmentMask) & ~AlignmentMask;
420- InstanceAddress += Offset;
421+ InstanceAddress = (InstanceAddress + AlignmentMask) & ~AlignmentMask;
421422
422423 return RemoteExistential (
423424 RemoteAddress (*InstanceMetadataAddress),
0 commit comments