Skip to content

Commit 656c393

Browse files
committed
projectExistential: Use the metadata field offset as size comparison
It's more accurate to use the offset of the "metadata field" of the existential's RecordTypeInfo when projecting an existential during remote reflection.
1 parent 0372874 commit 656c393

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

include/swift/Reflection/ReflectionContext.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,19 +149,19 @@ class ReflectionContext
149149
// container. If it doesn't, the first word is a pointer to a heap box.
150150
case RecordKind::Existential: {
151151
auto Fields = ExistentialRecordTI->getFields();
152-
auto Metadata = std::find_if(Fields.begin(), Fields.end(),
152+
auto ExistentialMetadataField = std::find_if(Fields.begin(), Fields.end(),
153153
[](const FieldInfo &FI) -> bool {
154154
return FI.Name.compare("metadata") == 0;
155155
});
156-
if (Metadata == Fields.end())
156+
if (ExistentialMetadataField == Fields.end())
157157
return false;
158158

159159
// Get the metadata pointer for the contained instance type.
160160
// This is equivalent to:
161161
// auto PointerArray = reinterpret_cast<uintptr_t*>(ExistentialAddress);
162162
// uintptr_t MetadataAddress = PointerArray[Offset];
163163
auto MetadataAddressAddress
164-
= RemoteAddress(ExistentialAddress + Metadata->Offset);
164+
= RemoteAddress(ExistentialAddress + ExistentialMetadataField->Offset);
165165

166166
StoredPointer MetadataAddress = 0;
167167
if (!getReader().readInteger(MetadataAddressAddress, &MetadataAddress))
@@ -177,7 +177,7 @@ class ReflectionContext
177177
if (!InstanceTI)
178178
return false;
179179

180-
if (InstanceTI->getSize() < ExistentialRecordTI->getSize()) {
180+
if (InstanceTI->getSize() <= ExistentialMetadataField->Offset) {
181181
// The value fits in the existential container, so it starts at the
182182
// start of the container.
183183
*OutInstanceAddress = ExistentialAddress;

0 commit comments

Comments
 (0)