Skip to content

Commit 11cf38e

Browse files
committed
[5.10][Runtime] Fix lazy ivar list copying.
The `ivar` reference still pointed to the original list, so the first modification went to the wrong place. Change `ivar` to a pointer, and re-point it when we copy the list. rdar://116339597 (cherry picked from commit e2b4d2f)
1 parent ff980ef commit 11cf38e

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

stdlib/public/runtime/Metadata.cpp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3453,17 +3453,17 @@ static void initObjCClass(ClassMetadata *self,
34533453
for (unsigned i = 0; i != numFields; ++i) {
34543454
auto *eltLayout = fieldTypes[i];
34553455

3456-
ClassIvarEntry &ivar = ivars->getIvars()[i];
3456+
ClassIvarEntry *ivar = &ivars->getIvars()[i];
34573457

34583458
// Fill in the field offset global, if this ivar has one.
3459-
if (ivar.Offset) {
3460-
if (*ivar.Offset != fieldOffsets[i])
3461-
*ivar.Offset = fieldOffsets[i];
3459+
if (ivar->Offset) {
3460+
if (*ivar->Offset != fieldOffsets[i])
3461+
*ivar->Offset = fieldOffsets[i];
34623462
}
34633463

34643464
// If the ivar's size doesn't match the field layout we
34653465
// computed, overwrite it and give it better type information.
3466-
if (ivar.Size != eltLayout->size) {
3466+
if (ivar->Size != eltLayout->size) {
34673467
// If we're going to modify the ivar list, we need to copy it first.
34683468
if (!copiedIvarList) {
34693469
auto ivarListSize = sizeof(ClassIvarList) +
@@ -3473,10 +3473,13 @@ static void initObjCClass(ClassMetadata *self,
34733473
memcpy(ivars, rodata->IvarList, ivarListSize);
34743474
rodata->IvarList = ivars;
34753475
copiedIvarList = true;
3476+
3477+
// Update ivar to point to the newly copied list.
3478+
ivar = &ivars->getIvars()[i];
34763479
}
3477-
ivar.Size = eltLayout->size;
3478-
ivar.Type = nullptr;
3479-
ivar.Log2Alignment =
3480+
ivar->Size = eltLayout->size;
3481+
ivar->Type = nullptr;
3482+
ivar->Log2Alignment =
34803483
getLog2AlignmentFromMask(eltLayout->flags.getAlignmentMask());
34813484
}
34823485
}

0 commit comments

Comments
 (0)