Skip to content

Commit a7ee751

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

File tree

4 files changed

+35
-8
lines changed

4 files changed

+35
-8
lines changed

lib/SILGen/SILGenDestructor.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,7 @@ void SILGenFunction::emitMoveOnlyMemberDestruction(SILValue selfValue,
490490
NominalTypeDecl *nom,
491491
CleanupLocation cleanupLoc,
492492
SILBasicBlock *finishBB) {
493+
selfValue = B.createDropDeinit(cleanupLoc, selfValue);
493494
if (selfValue->getType().isAddress()) {
494495
if (auto *structDecl = dyn_cast<StructDecl>(nom)) {
495496
for (VarDecl *vd : nom->getStoredProperties()) {

test/SILGen/forget.swift

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ func invokedDeinit() {}
2222
// CHECK: store {{.*}} to [init]
2323
// CHECK: [[SELF_MMC:%.*]] = mark_must_check [no_consume_or_assign] [[SELF_REF]] : $*MaybeFile
2424
// CHECK: [[SELF_VAL:%.*]] = load [copy] [[SELF_MMC]] : $*MaybeFile
25-
// CHECK: switch_enum [[SELF_VAL]] : $MaybeFile, case #MaybeFile.some!enumelt: bb1, case #MaybeFile.none!enumelt: bb2
25+
// CHECK: [[DD:%.*]] = drop_deinit [[SELF_VAL]] : $MaybeFile
26+
// CHECK: switch_enum [[DD]] : $MaybeFile, case #MaybeFile.some!enumelt: bb1, case #MaybeFile.none!enumelt: bb2
2627
//
2728
// CHECK: bb1([[FILE:%.*]] : @owned $File):
2829
// CHECK: destroy_value [[FILE]] : $File
@@ -50,7 +51,8 @@ func invokedDeinit() {}
5051
// CHECK: load_borrow {{.*}} : $*File
5152
// CHECK: [[SELF_MMC:%.*]] = mark_must_check [no_consume_or_assign] [[SELF_REF]] : $*File
5253
// CHECK: [[SELF_VAL:%.*]] = load [copy] [[SELF_MMC]] : $*File
53-
// CHECK: end_lifetime [[SELF_VAL]] : $File
54+
// CHECK: [[DD:%.*]] = drop_deinit [[SELF_VAL]] : $File
55+
// CHECK: end_lifetime [[DD]] : $File
5456

5557
deinit {
5658
invokedDeinit()
@@ -90,7 +92,8 @@ func invokedDeinit() {}
9092
// CHECK: [[MMC:%.*]] = mark_must_check [no_consume_or_assign] [[ACCESS]] : $*PointerTree
9193
// CHECK: [[COPIED_SELF:%.*]] = load [copy] [[MMC]] : $*PointerTree
9294
// CHECK: end_access [[ACCESS]] : $*PointerTree
93-
// CHECK: ([[LEFT:%.*]], [[FILE:%.*]], {{%.*}}, [[RIGHT:%.*]]) = destructure_struct [[COPIED_SELF]] : $PointerTree
95+
// CHECK: [[DD:%.*]] = drop_deinit [[COPIED_SELF]]
96+
// CHECK: ([[LEFT:%.*]], [[FILE:%.*]], {{%.*}}, [[RIGHT:%.*]]) = destructure_struct [[DD]] : $PointerTree
9497
// CHECK: destroy_value [[LEFT]] : $Ptr
9598
// CHECK: destroy_value [[FILE]] : $File
9699
// CHECK: destroy_value [[RIGHT]] : $Ptr
@@ -167,7 +170,8 @@ final class Wallet {
167170
// CHECK: [[SELF_MMC:%.*]] = mark_must_check [no_consume_or_assign] [[SELF_ACCESS]]
168171
// CHECK: [[SELF_COPY:%.*]] = load [copy] [[SELF_MMC]] : $*Ticket
169172
// CHECK: end_access [[SELF_ACCESS:%.*]] : $*Ticket
170-
// CHECK: switch_enum [[SELF_COPY]] : $Ticket, case #Ticket.empty!enumelt: bb4, case #Ticket.within!enumelt: bb5
173+
// CHECK: [[DD:%.*]] = drop_deinit [[SELF_COPY]] : $Ticket
174+
// CHECK: switch_enum [[DD]] : $Ticket, case #Ticket.empty!enumelt: bb4, case #Ticket.within!enumelt: bb5
171175
// CHECK: bb4:
172176
// CHECK: br bb6
173177
// CHECK: bb5([[PREV_SELF_WALLET:%.*]] : @owned $Wallet):

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)