@@ -1119,3 +1119,99 @@ TEST(WitnessTableTest, getGenericWitnessTable) {
1119
1119
});
1120
1120
}
1121
1121
}
1122
+
1123
+ TEST (TestOpaqueExistentialBox, test_assignWithCopy_pod) {
1124
+ auto any =
1125
+ swift_getExistentialTypeMetadata (ProtocolClassConstraint::Any,
1126
+ /* superclass=*/ nullptr , 0 , nullptr );
1127
+ auto anyVWT = any->getValueWitnesses ();
1128
+
1129
+ ValueWitnessTable testTable;
1130
+ testTable.size = sizeof (ValueBuffer);
1131
+ testTable.flags = ValueWitnessFlags ()
1132
+ .withAlignment (alignof (ValueBuffer))
1133
+ .withPOD (true )
1134
+ .withBitwiseTakable (true )
1135
+ .withInlineStorage (true );
1136
+ testTable.stride = sizeof (ValueBuffer);
1137
+ installCommonValueWitnesses (&testTable);
1138
+ FullOpaqueMetadata testMetadata = {{&testTable}, {{MetadataKind::Opaque}}};
1139
+ Metadata *metadata = &testMetadata.base ;
1140
+
1141
+ ValueWitnessTable testTable2;
1142
+ testTable2.size = sizeof (ValueBuffer);
1143
+ testTable2.flags = ValueWitnessFlags ()
1144
+ .withAlignment (alignof (ValueBuffer))
1145
+ .withPOD (true )
1146
+ .withBitwiseTakable (true )
1147
+ .withInlineStorage (true );
1148
+ testTable2.stride = sizeof (ValueBuffer);
1149
+ installCommonValueWitnesses (&testTable2);
1150
+ FullOpaqueMetadata testMetadata2 = {{&testTable}, {{MetadataKind::Opaque}}};
1151
+ Metadata *metadata2 = &testMetadata2.base ;
1152
+
1153
+ void *zeroPtr = nullptr ;
1154
+ void *otherPtr = &zeroPtr;
1155
+ struct {
1156
+ ValueBuffer buffer;
1157
+ Metadata *type;
1158
+ uintptr_t canary;
1159
+ } existBox{{{zeroPtr, zeroPtr, zeroPtr}}, metadata, 0x5A5A5A5AU },
1160
+ existBox2{{{otherPtr, otherPtr, zeroPtr}}, metadata2, 0xB5A5A5A5U };
1161
+
1162
+ anyVWT->assignWithCopy (reinterpret_cast <OpaqueValue *>(&existBox),
1163
+ reinterpret_cast <OpaqueValue *>(&existBox2), any);
1164
+ EXPECT_EQ (existBox.type , metadata2);
1165
+ EXPECT_EQ (existBox.canary , 0x5A5A5A5AU );
1166
+ EXPECT_EQ (existBox.buffer .PrivateData [0 ], otherPtr);
1167
+ EXPECT_EQ (existBox.buffer .PrivateData [1 ], otherPtr);
1168
+ EXPECT_EQ (existBox.buffer .PrivateData [2 ], zeroPtr);
1169
+ }
1170
+
1171
+ TEST (TestOpaqueExistentialBox, test_assignWithTake_pod) {
1172
+ auto any =
1173
+ swift_getExistentialTypeMetadata (ProtocolClassConstraint::Any,
1174
+ /* superclass=*/ nullptr , 0 , nullptr );
1175
+ auto anyVWT = any->getValueWitnesses ();
1176
+
1177
+ ValueWitnessTable testTable;
1178
+ testTable.size = sizeof (ValueBuffer);
1179
+ testTable.flags = ValueWitnessFlags ()
1180
+ .withAlignment (alignof (ValueBuffer))
1181
+ .withPOD (true )
1182
+ .withBitwiseTakable (true )
1183
+ .withInlineStorage (true );
1184
+ testTable.stride = sizeof (ValueBuffer);
1185
+ installCommonValueWitnesses (&testTable);
1186
+ FullOpaqueMetadata testMetadata = {{&testTable}, {{MetadataKind::Opaque}}};
1187
+ Metadata *metadata = &testMetadata.base ;
1188
+
1189
+ ValueWitnessTable testTable2;
1190
+ testTable2.size = sizeof (ValueBuffer);
1191
+ testTable2.flags = ValueWitnessFlags ()
1192
+ .withAlignment (alignof (ValueBuffer))
1193
+ .withPOD (true )
1194
+ .withBitwiseTakable (true )
1195
+ .withInlineStorage (true );
1196
+ testTable2.stride = sizeof (ValueBuffer);
1197
+ installCommonValueWitnesses (&testTable2);
1198
+ FullOpaqueMetadata testMetadata2 = {{&testTable}, {{MetadataKind::Opaque}}};
1199
+ Metadata *metadata2 = &testMetadata2.base ;
1200
+
1201
+ void *zeroPtr = nullptr ;
1202
+ void *otherPtr = &zeroPtr;
1203
+ struct {
1204
+ ValueBuffer buffer;
1205
+ Metadata *type;
1206
+ uintptr_t canary;
1207
+ } existBox{{{zeroPtr, zeroPtr, zeroPtr}}, metadata, 0x5A5A5A5AU },
1208
+ existBox2{{{otherPtr, otherPtr, zeroPtr}}, metadata2, 0xB5A5A5A5U };
1209
+
1210
+ anyVWT->assignWithTake (reinterpret_cast <OpaqueValue *>(&existBox),
1211
+ reinterpret_cast <OpaqueValue *>(&existBox2), any);
1212
+ EXPECT_EQ (existBox.type , metadata2);
1213
+ EXPECT_EQ (existBox.canary , 0x5A5A5A5AU );
1214
+ EXPECT_EQ (existBox.buffer .PrivateData [0 ], otherPtr);
1215
+ EXPECT_EQ (existBox.buffer .PrivateData [1 ], otherPtr);
1216
+ EXPECT_EQ (existBox.buffer .PrivateData [2 ], zeroPtr);
1217
+ }
0 commit comments