@@ -361,24 +361,21 @@ class MetadataReader {
361
361
bool isObjC = false ;
362
362
bool isBridged = false ;
363
363
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 {
371
377
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
+ }
382
379
}
383
380
384
381
if (isBridged) {
@@ -413,11 +410,15 @@ class MetadataReader {
413
410
StoredPointer InstanceAddress =
414
411
InstanceMetadataAddressAddress + 2 * sizeof (StoredPointer);
415
412
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
+
416
418
// Round up to alignment, and we have the start address of the
417
419
// instance payload.
418
420
auto AlignmentMask = VWT->getAlignmentMask ();
419
- auto Offset = (sizeof (HeapObject) + AlignmentMask) & ~AlignmentMask;
420
- InstanceAddress += Offset;
421
+ InstanceAddress = (InstanceAddress + AlignmentMask) & ~AlignmentMask;
421
422
422
423
return RemoteExistential (
423
424
RemoteAddress (*InstanceMetadataAddress),
0 commit comments