Skip to content

Commit a41d014

Browse files
committed
[move-only] Fix TypeLowering to preserve value deinits
MoveOnlyLoadableStruct should only lower to memberwise destroys if it has no deinit. (cherry picked from commit 986cd42)
1 parent dcc1e6a commit a41d014

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
@@ -1575,6 +1575,19 @@ namespace {
15751575
return B.createStruct(loc, getLoweredType(), values);
15761576
}
15771577

1578+
void
1579+
emitLoweredDestroyValue(SILBuilder &B, SILLocation loc, SILValue aggValue,
1580+
TypeExpansionKind loweringStyle) const override {
1581+
// A value type with a deinit cannot be memberwise destroyed.
1582+
if (auto *nominal = getLoweredType().getNominalOrBoundGenericNominal()) {
1583+
if (nominal->getValueTypeDestructor()) {
1584+
emitDestroyValue(B, loc, aggValue);
1585+
return;
1586+
}
1587+
}
1588+
Super::emitLoweredDestroyValue(B, loc, aggValue, loweringStyle);
1589+
}
1590+
15781591
private:
15791592
void lowerChildren(TypeConverter &TC,
15801593
SmallVectorImpl<Child> &children) const override {

0 commit comments

Comments
 (0)