mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[SUA] Add test for allocation of classes without metadata (#63759)
Add test for allocating classes with pruned metadata and refactor `computeMallocTypeSummary()` to make it easier to understand: * Use early returns for error (metadata absent) conditions * Remove reliance on implicit dependency---having a type descriptor currently implies that there is also class metadata---in case this ever changes Co-authored-by: Julian Lettner <julian.lettner@apple.com>
This commit is contained in:
@@ -125,41 +125,33 @@ computeMallocTypeSummary(const HeapMetadata *heapMetadata) {
|
||||
auto *classMetadata = heapMetadata->getClassObject();
|
||||
auto *typeDesc = heapMetadata->getTypeContextDescriptor();
|
||||
|
||||
malloc_type_summary_t summary = {};
|
||||
// Pruned metadata or unclassified
|
||||
if (!classMetadata || !typeDesc)
|
||||
return {.type_kind = MALLOC_TYPE_KIND_SWIFT};
|
||||
|
||||
// Objc
|
||||
if (classMetadata && classMetadata->isPureObjC()) {
|
||||
summary.type_kind = MALLOC_TYPE_KIND_OBJC;
|
||||
return summary;
|
||||
}
|
||||
if (classMetadata->isPureObjC())
|
||||
return {.type_kind = MALLOC_TYPE_KIND_OBJC};
|
||||
|
||||
// Runtime internal and unclassified
|
||||
if (!typeDesc) {
|
||||
summary.type_kind = MALLOC_TYPE_KIND_CXX;
|
||||
return summary;
|
||||
}
|
||||
malloc_type_summary_t summary = {.type_kind = MALLOC_TYPE_KIND_SWIFT};
|
||||
summary.layout_semantics.reference_count =
|
||||
(classMetadata->getFlags() & ClassFlags::UsesSwiftRefcounting);
|
||||
|
||||
// Swift
|
||||
summary.type_kind = MALLOC_TYPE_KIND_SWIFT;
|
||||
auto *fieldDesc = typeDesc->Fields.get();
|
||||
if (!fieldDesc)
|
||||
return summary;
|
||||
|
||||
bool isGenericData = true;
|
||||
if (auto *fieldDesc = typeDesc->Fields.get()) {
|
||||
for (auto &field : *fieldDesc) {
|
||||
if (field.isIndirectCase()) {
|
||||
isGenericData = false;
|
||||
if (field.isVar())
|
||||
summary.layout_semantics.data_pointer = true;
|
||||
else
|
||||
summary.layout_semantics.immutable_pointer = true;
|
||||
}
|
||||
for (auto &field : *fieldDesc) {
|
||||
if (field.isIndirectCase()) {
|
||||
isGenericData = false;
|
||||
if (field.isVar())
|
||||
summary.layout_semantics.data_pointer = true;
|
||||
else
|
||||
summary.layout_semantics.immutable_pointer = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (classMetadata->Flags & ClassFlags::UsesSwiftRefcounting) {
|
||||
summary.layout_semantics.reference_count = true;
|
||||
} else {
|
||||
summary.layout_semantics.generic_data = isGenericData;
|
||||
}
|
||||
summary.layout_semantics.generic_data = isGenericData;
|
||||
|
||||
return summary;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user