Skip to content

Commit e32d245

Browse files
authored
Merge pull request #23285 from slavapestov/remoteast-linux-error-fix-5.1
RemoteAST: Fix Error existential introspection on Linux [5.1]
2 parents e230e9f + c20d085 commit e32d245

File tree

2 files changed

+20
-21
lines changed

2 files changed

+20
-21
lines changed

include/swift/Remote/MetadataReader.h

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -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),

test/RemoteAST/existentials.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// UNSUPPORTED: linux
2-
// <rdar://problem/42793848>
31
// RUN: %target-swift-remoteast-test %s | %FileCheck %s
42

53
// REQUIRES: swift-remoteast-test

0 commit comments

Comments
 (0)