File tree Expand file tree Collapse file tree 2 files changed +30
-0
lines changed
lib/SILOptimizer/SILCombiner Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -1146,6 +1146,10 @@ SILInstruction *SILCombiner::visitUncheckedTakeEnumDataAddrInst(
11461146 }
11471147
11481148 if (onlyDestroys) {
1149+ // Destroying whole non-copyable enums with a deinit would wrongly trigger calling its deinit.
1150+ if (tedai->getOperand ()->getType ().isValueTypeWithDeinit ())
1151+ return nullptr ;
1152+
11491153 // The unchecked_take_enum_data_addr is dead: remove it and replace all
11501154 // destroys with a destroy of its operand.
11511155 while (!tedai->use_empty ()) {
Original file line number Diff line number Diff line change @@ -185,3 +185,29 @@ bb0(%0 : @owned $S2):
185185 return %r
186186}
187187
188+ // CHECK-LABEL: sil [ossa] @dont_fold_destroy_of_take_enum_with_deinit_ossa :
189+ // CHECK: bb0(%0 : $*MaybeFileDescriptor):
190+ // CHECK-NEXT: %1 = unchecked_take_enum_data_addr %0
191+ // CHECK-NEXT: destroy_addr %1
192+ // CHECK: } // end sil function 'dont_fold_destroy_of_take_enum_with_deinit_ossa'
193+ sil [ossa] @dont_fold_destroy_of_take_enum_with_deinit_ossa : $@convention(thin) (@in MaybeFileDescriptor) -> () {
194+ bb0(%0 : $*MaybeFileDescriptor):
195+ %1 = unchecked_take_enum_data_addr %0, #MaybeFileDescriptor.some!enumelt
196+ destroy_addr %1
197+ %r = tuple ()
198+ return %r : $()
199+ }
200+
201+ // CHECK-LABEL: sil @dont_fold_destroy_of_take_enum_with_deinit :
202+ // CHECK: bb0(%0 : $*MaybeFileDescriptor):
203+ // CHECK-NEXT: %1 = unchecked_take_enum_data_addr %0
204+ // CHECK-NEXT: destroy_addr %1
205+ // CHECK: } // end sil function 'dont_fold_destroy_of_take_enum_with_deinit'
206+ sil @dont_fold_destroy_of_take_enum_with_deinit : $@convention(thin) (@in MaybeFileDescriptor) -> () {
207+ bb0(%0 : $*MaybeFileDescriptor):
208+ %1 = unchecked_take_enum_data_addr %0, #MaybeFileDescriptor.some!enumelt
209+ destroy_addr %1
210+ %r = tuple ()
211+ return %r : $()
212+ }
213+
You can’t perform that action at this time.
0 commit comments