Skip to content

Commit 6afe8c1

Browse files
committed
Runtime: Unconditionally realize superclass metadata in swift_updateClassMetadata()
Previously we were only doing this in assert builds, or if the new Objective-C runtime metadata update hook mechanism was available. However, swift_checkMetadataState() gets called on the superclass of a class, and it assumes that the metadata entry for the superclass already exists in the singleton cache. So even on an older runtime when there's no initialization work to be done, we have to realize the superclass to populate the singleton cache so that the check can succeed. Fixes <rdar://problem/45569020>.
1 parent c7d3017 commit 6afe8c1

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

stdlib/public/runtime/Metadata.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2616,7 +2616,6 @@ swift::swift_updateClassMetadata(ClassMetadata *self,
26162616
size_t numFields,
26172617
const TypeLayout * const *fieldTypes,
26182618
size_t *fieldOffsets) {
2619-
#ifndef NDEBUG
26202619
// If there is a mangled superclass name, demangle it to the superclass
26212620
// type.
26222621
const ClassMetadata *super = nullptr;
@@ -2645,7 +2644,6 @@ swift::swift_updateClassMetadata(ClassMetadata *self,
26452644
assert(self->Superclass == getRootSuperclass());
26462645
else
26472646
assert(self->Superclass == super);
2648-
#endif
26492647

26502648
// FIXME: Plumb this through
26512649
#if 1

test/Interpreter/objc_class_resilience.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,15 @@ ResilientClassTestSuite.test("Category") {
3838
expectEqual(42, takesMyProtocol(ResilientFieldWithCategory()))
3939
}
4040

41+
// rdar://problem/45569020 - Make sure we initialize the superclass first
42+
class ResilientSuperclass {
43+
var value: ResilientInt?
44+
}
45+
46+
class ResilientSubclass : ResilientSuperclass {}
47+
48+
ResilientClassTestSuite.test("Superclass") {
49+
_blackHole(ResilientSubclass())
50+
}
51+
4152
runAllTests()

0 commit comments

Comments
 (0)