Skip to content

Commit 86970b0

Browse files
committed
IRGen: Fragile layout of resiliently-typed class fields
Fixes <rdar://problem/38506059>.
1 parent d5868e5 commit 86970b0

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

lib/IRGen/GenClass.cpp

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -321,9 +321,21 @@ namespace {
321321
const ClassLayout *abstractLayout) {
322322
for (VarDecl *var : theClass->getStoredProperties()) {
323323
SILType type = classType.getFieldType(var, IGM.getSILModule());
324-
auto &eltType = IGM.getTypeInfo(type);
324+
auto &eltTypeForAccess = IGM.getTypeInfo(type);
325325

326-
if (!eltType.isFixedSize()) {
326+
// For now, the Objective-C runtime cannot support dynamic layout of
327+
// classes that contain resilient value types, so we just look through
328+
// the resilience boundary and assume fragile layout for class ivars
329+
// instead.
330+
Optional<CompletelyFragileScope> generateStaticLayoutRAII;
331+
332+
if (!IGM.IRGen.Opts.EnableClassResilience &&
333+
!isa<FixedTypeInfo>(eltTypeForAccess))
334+
generateStaticLayoutRAII.emplace(IGM);
335+
336+
auto &eltTypeForLayout = IGM.getTypeInfo(type);
337+
338+
if (!eltTypeForLayout.isFixedSize()) {
327339
ClassMetadataRequiresDynamicInitialization = true;
328340
ClassHasFixedSize = false;
329341

@@ -335,7 +347,8 @@ namespace {
335347
assert(!abstractLayout ||
336348
abstractLayout->getFieldIndex(var) == fieldIndex);
337349

338-
Elements.push_back(ElementLayout::getIncomplete(eltType, eltType));
350+
Elements.push_back(ElementLayout::getIncomplete(eltTypeForLayout,
351+
eltTypeForAccess));
339352
AllStoredProperties.push_back(var);
340353
AllFieldAccesses.push_back(getFieldAccess(abstractLayout, fieldIndex));
341354
}

0 commit comments

Comments
 (0)