Merge pull request #65776 from mikeash/dealloc-partial-class-instance-setclass-readonly

[Runtime] Immediate release and return when destroying partial instance of pure ObjC class.
This commit is contained in:
swift-ci
2023-05-09 19:08:22 -07:00
committed by GitHub

View File

@@ -854,6 +854,17 @@ void swift::swift_deallocPartialClassInstance(HeapObject *object,
// Destroy ivars
auto *classMetadata = _swift_getClassOfAllocated(object)->getClassObject();
assert(classMetadata && "Not a class?");
#if SWIFT_OBJC_INTEROP
// If the object's class is already pure ObjC class, just release it and move
// on. There are no ivar destroyers. This avoids attempting to mutate
// placeholder objects statically created in read-only memory.
if (classMetadata->isPureObjC()) {
objc_release((id)object);
return;
}
#endif
while (classMetadata != metadata) {
#if SWIFT_OBJC_INTEROP
// If we have hit a pure Objective-C class, we won't see another ivar