IRGen: Perform completely fragile layout for all classes, not just @objc ancestry

Otherwise, Objective C categories don't work for classes with
resilient fields, such as the value types defined in the Foundation
overlay.

Fixes <rdar://problem/40819319>, <https://bugs.swift.org/browse/SR-7882>.
This commit is contained in:
Slava Pestov
2018-06-13 22:22:27 -07:00
parent cd5d7386d1
commit d3868ad23d
3 changed files with 35 additions and 52 deletions

View File

@@ -141,9 +141,9 @@ namespace {
unsigned NumInherited = 0;
// If the class has @objc ancestry, we lay out resiliently-typed fields
// as if they were fragile.
bool CompletelyFragileLayout = false;
// For now we always lay out resiliently-typed fields as if they
// were fragile.
bool CompletelyFragileLayout;
// Does the class metadata require dynamic initialization above and
// beyond what the runtime can automatically achieve?
@@ -171,6 +171,11 @@ namespace {
ReferenceCounting refcounting)
: StructLayoutBuilder(IGM)
{
// Perform fragile layout if Objective-C interop is enabled.
CompletelyFragileLayout =
(IGM.Context.LangOpts.EnableObjCInterop &&
!IGM.IRGen.Opts.EnableClassResilience);
// Start by adding a heap header.
switch (refcounting) {
case ReferenceCounting::Native:
@@ -249,10 +254,6 @@ namespace {
}
if (superclass->hasClangNode()) {
// Perform fragile layout if the class has @objc ancestry.
if (!IGM.IRGen.Opts.EnableClassResilience)
CompletelyFragileLayout = true;
// If the superclass was imported from Objective-C, its size is
// not known at compile time. However, since the field offset
// vector only stores offsets of stored properties defined in