Skip to content

Commit 5817ca7

Browse files
author
Greg Parker
committed
[stdlib] Fix assertion failures in SwiftRuntimeTests (aka unittests/runtime).
1 parent f449ba7 commit 5817ca7

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

include/swift/Runtime/Metadata.h

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1569,10 +1569,21 @@ struct TargetClassMetadata : public TargetHeapMetadata<Runtime> {
15691569
Reserved(0), ClassSize(classSize), ClassAddressPoint(classAddressPoint),
15701570
Description(nullptr), IVarDestroyer(ivarDestroyer) {}
15711571

1572-
TargetClassMetadata(const TargetClassMetadata& other): Description(other.getDescription().get()) {
1573-
memcpy(this, &other, sizeof(*this));
1574-
setDescription(other.getDescription().get());
1575-
}
1572+
// Description's copy ctor is deleted so we have to do this the hard way.
1573+
TargetClassMetadata(const TargetClassMetadata& other)
1574+
: TargetHeapMetadata<Runtime>(other),
1575+
SuperClass(other.SuperClass),
1576+
CacheData{other.CacheData[0], other.CacheData[1]},
1577+
Data(other.Data),
1578+
Flags(other.Flags),
1579+
InstanceAddressPoint(other.InstanceAddressPoint),
1580+
InstanceSize(other.InstanceSize),
1581+
InstanceAlignMask(other.InstanceAlignMask),
1582+
Reserved(other.Reserved),
1583+
ClassSize(other.ClassSize),
1584+
ClassAddressPoint(other.ClassAddressPoint),
1585+
Description(other.Description.get()),
1586+
IVarDestroyer(other.IVarDestroyer) {}
15761587

15771588
/// The metadata for the superclass. This is null for the root class.
15781589
ConstTargetMetadataPointer<Runtime, swift::TargetClassMetadata> SuperClass;

unittests/runtime/Metadata.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,8 @@ TEST(MetadataTest, getGenericMetadata) {
291291

292292
FullMetadata<ClassMetadata> MetadataTest2 = {
293293
{ { nullptr }, { &_TWVBo } },
294-
{ { { MetadataKind::Class } }, nullptr, 0, ClassFlags(), nullptr, 0, 0, 0, 0, 0 }
294+
{ { { MetadataKind::Class } }, nullptr, /*rodata*/ 1,
295+
ClassFlags(), nullptr, 0, 0, 0, 0, 0 }
295296
};
296297

297298
TEST(MetadataTest, getMetatypeMetadata) {

0 commit comments

Comments
 (0)