@@ -908,7 +908,7 @@ class ReflectionContext
908
908
// Figure out where the stored properties of this class begin
909
909
// by looking at the size of the superclass
910
910
auto start =
911
- this ->readInstanceStartAndAlignmentFromClassMetadata (MetadataAddress);
911
+ this ->readInstanceStartFromClassMetadata (MetadataAddress);
912
912
913
913
// Perform layout
914
914
if (start)
@@ -1202,8 +1202,42 @@ class ReflectionContext
1202
1202
}
1203
1203
}
1204
1204
1205
- const RecordTypeInfo *getRecordTypeInfo (const TypeRef *TR,
1206
- remote::TypeInfoProvider *ExternalTypeInfo) {
1205
+ // / Given a typeref, attempt to calculate where the fields that don't belong
1206
+ // / to this instance ends. For example, for a superclass, the size of it's non
1207
+ // / instance fields would be one word for the isa pointer plus one word for
1208
+ // / the refcount field. For a subclass the size would be the superclass's size
1209
+ // / (including fields). Note that this is not the same as the start of the
1210
+ // / subclass's fields, as this value does not account for padding. Check
1211
+ // / MetadataReader::readInstanceStartFromClassMetadata for similar
1212
+ // / functionality.
1213
+ llvm::Optional<unsigned >
1214
+ readSizeOfFieldsNotBelongingToInstanceFromTypeRef (const TypeRef *TR) {
1215
+ size_t isaAndRetainCountSize = sizeof (StoredSize) + sizeof (long long );
1216
+
1217
+ const TypeRef *superclass = getBuilder ().lookupSuperclass (TR);
1218
+ if (!superclass)
1219
+ // If there is no superclass the stat of the instance's field is right
1220
+ // after the isa and retain fields.
1221
+ return isaAndRetainCountSize;
1222
+
1223
+ auto superclassStart =
1224
+ readSizeOfFieldsNotBelongingToInstanceFromTypeRef (superclass);
1225
+ if (!superclassStart)
1226
+ return llvm::None;
1227
+
1228
+ auto *superTI = getBuilder ().getTypeConverter ().getClassInstanceTypeInfo (
1229
+ superclass, *superclassStart, nullptr );
1230
+ if (!superTI)
1231
+ return llvm::None;
1232
+
1233
+ // The start of the subclass's fields is right after the super class's ones.
1234
+ size_t start = superTI->getSize ();
1235
+ return start;
1236
+ }
1237
+
1238
+ const RecordTypeInfo *
1239
+ getRecordTypeInfo (const TypeRef *TR,
1240
+ remote::TypeInfoProvider *ExternalTypeInfo) {
1207
1241
auto *TypeInfo = getTypeInfo (TR, ExternalTypeInfo);
1208
1242
return dyn_cast_or_null<const RecordTypeInfo>(TypeInfo);
1209
1243
}
0 commit comments