Skip to content

Commit 986cd42

Browse files
committed
[move-only] Fix TypeLowering to preserve value deinits
MoveOnlyLoadableStruct should only lower to memberwise destroys if it has no deinit.
1 parent 58f96a9 commit 986cd42

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

lib/SIL/IR/TypeLowering.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1581,6 +1581,19 @@ namespace {
15811581
return B.createStruct(loc, getLoweredType(), values);
15821582
}
15831583

1584+
void
1585+
emitLoweredDestroyValue(SILBuilder &B, SILLocation loc, SILValue aggValue,
1586+
TypeExpansionKind loweringStyle) const override {
1587+
// A value type with a deinit cannot be memberwise destroyed.
1588+
if (auto *nominal = getLoweredType().getNominalOrBoundGenericNominal()) {
1589+
if (nominal->getValueTypeDestructor()) {
1590+
emitDestroyValue(B, loc, aggValue);
1591+
return;
1592+
}
1593+
}
1594+
Super::emitLoweredDestroyValue(B, loc, aggValue, loweringStyle);
1595+
}
1596+
15841597
private:
15851598
void lowerChildren(TypeConverter &TC,
15861599
SmallVectorImpl<Child> &children) const override {

0 commit comments

Comments
 (0)