Skip to content

Commit df245a6

Browse files
eecksteinkavon
authored andcommitted
SILGen: emit drop_deinit in move-only destructors
1 parent c16f5a0 commit df245a6

File tree

3 files changed

+27
-4
lines changed

3 files changed

+27
-4
lines changed

lib/SILGen/SILGenDestructor.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,7 @@ void SILGenFunction::emitMoveOnlyMemberDestruction(SILValue selfValue,
499499
NominalTypeDecl *nom,
500500
CleanupLocation cleanupLoc,
501501
SILBasicBlock *finishBB) {
502+
selfValue = B.createDropDeinit(cleanupLoc, selfValue);
502503
if (selfValue->getType().isAddress()) {
503504
if (auto *structDecl = dyn_cast<StructDecl>(nom)) {
504505
for (VarDecl *vd : nom->getStoredProperties()) {

test/SILGen/moveonly_deinits.swift

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,17 @@ var value: Bool { false }
6666
// SILGEN-LABEL: sil hidden [ossa] @$s16moveonly_deinits19KlassPairWithDeinitVfD : $@convention(method) (@owned KlassPairWithDeinit) -> () {
6767
// SILGEN: bb0([[ARG:%.*]] :
6868
// SILGEN: [[MARK:%.*]] = mark_must_check [consumable_and_assignable] [[ARG]]
69-
// SILGEN: ([[LHS:%.*]], [[RHS:%.*]]) = destructure_struct [[MARK]]
69+
// SILGEN: [[DD:%.*]] = drop_deinit [[MARK]]
70+
// SILGEN: ([[LHS:%.*]], [[RHS:%.*]]) = destructure_struct [[DD]]
7071
// SILGEN: destroy_value [[LHS]]
7172
// SILGEN: destroy_value [[RHS]]
7273
// SILGEN: } // end sil function '$s16moveonly_deinits19KlassPairWithDeinitVfD'
7374

7475
// SILGEN-LABEL: sil hidden [ossa] @$s16moveonly_deinits17IntPairWithDeinitVfD : $@convention(method) (@owned IntPairWithDeinit) -> () {
7576
// SILGEN: bb0([[ARG:%.*]] :
7677
// SILGEN: [[MARKED:%.*]] = mark_must_check [consumable_and_assignable] [[ARG]]
77-
// SILGEN: end_lifetime [[MARKED]]
78+
// SILGEN: [[DD:%.*]] = drop_deinit [[MARKED]]
79+
// SILGEN: end_lifetime [[DD]]
7880
// SILGEN: } // end sil function '$s16moveonly_deinits17IntPairWithDeinitVfD'
7981

8082
////////////////////////
@@ -330,7 +332,8 @@ func consumeKlassEnumPairWithDeinit(_ x: __owned KlassEnumPairWithDeinit) { }
330332
// SILGEN-LABEL: sil hidden [ossa] @$s16moveonly_deinits23KlassEnumPairWithDeinitOfD : $@convention(method) (@owned KlassEnumPairWithDeinit) -> () {
331333
// SILGEN: bb0([[ARG:%.*]] :
332334
// SILGEN: [[MARK:%.*]] = mark_must_check [consumable_and_assignable] [[ARG]]
333-
// SILGEN: switch_enum [[MARK]] : $KlassEnumPairWithDeinit, case #KlassEnumPairWithDeinit.lhs!enumelt: [[BB_LHS:bb[0-9]+]], case #KlassEnumPairWithDeinit.rhs!enumelt: [[BB_RHS:bb[0-9]+]]
335+
// SILGEN: [[DD:%.*]] = drop_deinit [[MARK]]
336+
// SILGEN: switch_enum [[DD]] : $KlassEnumPairWithDeinit, case #KlassEnumPairWithDeinit.lhs!enumelt: [[BB_LHS:bb[0-9]+]], case #KlassEnumPairWithDeinit.rhs!enumelt: [[BB_RHS:bb[0-9]+]]
334337
//
335338
// SILGEN: [[BB_LHS]]([[ARG:%.*]] :
336339
// SILGEN-NEXT: destroy_value [[ARG]]
@@ -348,7 +351,8 @@ func consumeKlassEnumPairWithDeinit(_ x: __owned KlassEnumPairWithDeinit) { }
348351
// SILGEN-LABEL: sil hidden [ossa] @$s16moveonly_deinits21IntEnumPairWithDeinitOfD : $@convention(method) (@owned IntEnumPairWithDeinit) -> () {
349352
// SILGEN: bb0([[ARG:%.*]] :
350353
// SILGEN: [[MARK:%.*]] = mark_must_check [consumable_and_assignable] [[ARG]]
351-
// SILGEN: switch_enum [[MARK]] : $IntEnumPairWithDeinit, case #IntEnumPairWithDeinit.lhs!enumelt: [[BB_LHS:bb[0-9]+]], case #IntEnumPairWithDeinit.rhs!enumelt: [[BB_RHS:bb[0-9]+]]
354+
// SILGEN: [[DD:%.*]] = drop_deinit [[MARK]]
355+
// SILGEN: switch_enum [[DD]] : $IntEnumPairWithDeinit, case #IntEnumPairWithDeinit.lhs!enumelt: [[BB_LHS:bb[0-9]+]], case #IntEnumPairWithDeinit.rhs!enumelt: [[BB_RHS:bb[0-9]+]]
352356
//
353357
// SILGEN: [[BB_LHS]]([[ARG:%.*]] :
354358
// SILGEN-NEXT: br [[BB_CONT:bb[0-9]+]]
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// RUN: %target-swift-emit-silgen -module-name=test -primary-file %s | %FileCheck %s
2+
3+
@_moveOnly
4+
public struct GenericMoveOnly<T> {
5+
var i: Int
6+
var s: T
7+
8+
// CHECK-LABEL: sil [ossa] @$s4test15GenericMoveOnlyVfD : $@convention(method) <T> (@in GenericMoveOnly<T>) -> ()
9+
// CHECK: [[DD:%.*]] = drop_deinit %0 : $*GenericMoveOnly<T>
10+
// CHECK: [[SE:%.*]] = struct_element_addr %2 : $*GenericMoveOnly<T>, #GenericMoveOnly.s
11+
// CHECK: [[A:%.*]] = begin_access [deinit] [static] %3 : $*T
12+
// CHECK: destroy_addr [[A]] : $*T
13+
// CHECK: } // end sil function '$s4test15GenericMoveOnlyVfD'
14+
deinit {
15+
}
16+
}
17+
18+

0 commit comments

Comments
 (0)