File tree Expand file tree Collapse file tree 2 files changed +24
-0
lines changed Expand file tree Collapse file tree 2 files changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -179,6 +179,14 @@ bool swift::isInstructionTriviallyDead(SILInstruction *inst) {
179
179
if (isa<BorrowedFromInst>(inst))
180
180
return false ;
181
181
182
+ // A dead `destructure_struct` with an owned argument can appear for a non-copyable or
183
+ // non-escapable struct which has only trivial elements. The instruction is not trivially
184
+ // dead because it ends the lifetime of its operand.
185
+ if (isa<DestructureStructInst>(inst) &&
186
+ inst->getOperand (0 )->getOwnershipKind () == OwnershipKind::Owned) {
187
+ return false ;
188
+ }
189
+
182
190
// These invalidate enums so "write" memory, but that is not an essential
183
191
// operation so we can remove these if they are trivially dead.
184
192
if (isa<UncheckedTakeEnumDataAddrInst>(inst))
Original file line number Diff line number Diff line change @@ -11,6 +11,11 @@ struct S : ~Copyable {
11
11
deinit {}
12
12
}
13
13
14
+ struct S2 : ~Copyable {
15
+ @_hasStorage var a: Int { get set }
16
+ @_hasStorage var b: Int { get set }
17
+ }
18
+
14
19
struct FileDescriptor: ~Copyable {
15
20
var fd: Builtin.Int64
16
21
@@ -169,3 +174,14 @@ bb0:
169
174
%13 = tuple ()
170
175
return %13
171
176
}
177
+
178
+ // CHECK-LABEL: sil [ossa] @dont_remove_destructure_struct_of_non_copyable :
179
+ // CHECK: destructure_struct
180
+ // CHECK-LABEL: } // end sil function 'dont_remove_destructure_struct_of_non_copyable'
181
+ sil [ossa] @dont_remove_destructure_struct_of_non_copyable : $@convention(method) (@owned S2) -> () {
182
+ bb0(%0 : @owned $S2):
183
+ (%1, %2) = destructure_struct %0
184
+ %r = tuple ()
185
+ return %r
186
+ }
187
+
You can’t perform that action at this time.
0 commit comments