File tree Expand file tree Collapse file tree 5 files changed +45
-0
lines changed
SwiftCompilerSources/Sources Expand file tree Collapse file tree 5 files changed +45
-0
lines changed Original file line number Diff line number Diff line change @@ -309,6 +309,11 @@ struct AliasAnalysis {
309
309
if destroy. destroyedValue. type. isNoEscapeFunction {
310
310
return . noEffects
311
311
}
312
+ if destroy. isDeadEnd {
313
+ // We don't have to take deinit effects into acount for a `destroy_value [dead_end]`.
314
+ // Such destroys are lowered to no-ops and will not call any deinit.
315
+ return . noEffects
316
+ }
312
317
return defaultEffects ( of: destroy, on: memLoc)
313
318
314
319
default :
Original file line number Diff line number Diff line change @@ -506,6 +506,11 @@ final public class UnmanagedAutoreleaseValueInst : RefCountingInst {}
506
506
507
507
final public class DestroyValueInst : Instruction , UnaryInstruction {
508
508
public var destroyedValue : Value { operand. value }
509
+
510
+ /// True if this `destroy_value` is inside a dead-end block is only needed to formally
511
+ /// end the lifetime of its operand.
512
+ /// Such `destroy_value` instructions are lowered to no-ops.
513
+ public var isDeadEnd : Bool { bridged. DestroyValueInst_isDeadEnd ( ) }
509
514
}
510
515
511
516
final public class DestroyAddrInst : Instruction , UnaryInstruction {
Original file line number Diff line number Diff line change @@ -951,6 +951,7 @@ struct BridgedInstruction {
951
951
952
952
BRIDGED_INLINE SwiftInt ProjectBoxInst_fieldIndex () const ;
953
953
BRIDGED_INLINE bool EndCOWMutationInst_doKeepUnique () const ;
954
+ BRIDGED_INLINE bool DestroyValueInst_isDeadEnd () const ;
954
955
BRIDGED_INLINE SwiftInt EnumInst_caseIndex () const ;
955
956
BRIDGED_INLINE SwiftInt UncheckedEnumDataInst_caseIndex () const ;
956
957
BRIDGED_INLINE SwiftInt InitEnumDataAddrInst_caseIndex () const ;
Original file line number Diff line number Diff line change @@ -1111,6 +1111,10 @@ bool BridgedInstruction::EndCOWMutationInst_doKeepUnique() const {
1111
1111
return getAs<swift::EndCOWMutationInst>()->doKeepUnique ();
1112
1112
}
1113
1113
1114
+ bool BridgedInstruction::DestroyValueInst_isDeadEnd () const {
1115
+ return getAs<swift::DestroyValueInst>()->isDeadEnd ();
1116
+ }
1117
+
1114
1118
SwiftInt BridgedInstruction::EnumInst_caseIndex () const {
1115
1119
return getAs<swift::EnumInst>()->getCaseIndex ();
1116
1120
}
Original file line number Diff line number Diff line change @@ -1009,6 +1009,36 @@ bb0 (%0 : $*C):
1009
1009
return %2 : $()
1010
1010
}
1011
1011
1012
+ // CHECK-LABEL: @test_destroy_value_with_effects
1013
+ // CHECK: PAIR #1.
1014
+ // CHECK-NEXT: destroy_value %0 : $X
1015
+ // CHECK-NEXT: %2 = ref_element_addr %1 : $X, #X.x
1016
+ // CHECK-NEXT: r=1,w=1
1017
+ sil [ossa] @test_destroy_value_with_effects : $@convention(thin) (@owned X) -> () {
1018
+ bb0 (%0 : @owned $X):
1019
+ %1 = begin_borrow %0 : $X
1020
+ %2 = ref_element_addr %1 : $X, #X.x
1021
+ fix_lifetime %2 : $*X
1022
+ end_borrow %1 : $X
1023
+ destroy_value %0 : $X
1024
+ unreachable
1025
+ }
1026
+
1027
+ // CHECK-LABEL: @test_deadend_destroy_value
1028
+ // CHECK: PAIR #1.
1029
+ // CHECK-NEXT: destroy_value [dead_end] %0 : $X
1030
+ // CHECK-NEXT: %2 = ref_element_addr %1 : $X, #X.x
1031
+ // CHECK-NEXT: r=0,w=0
1032
+ sil [ossa] @test_deadend_destroy_value : $@convention(thin) (@owned X) -> () {
1033
+ bb0 (%0 : @owned $X):
1034
+ %1 = begin_borrow %0 : $X
1035
+ %2 = ref_element_addr %1 : $X, #X.x
1036
+ fix_lifetime %2 : $*X
1037
+ end_borrow %1 : $X
1038
+ destroy_value [dead_end] %0 : $X
1039
+ unreachable
1040
+ }
1041
+
1012
1042
// CHECK-LABEL: @test_copy_value
1013
1043
// CHECK: PAIR #1.
1014
1044
// CHECK-NEXT: %2 = copy_value %1 : $C
You can’t perform that action at this time.
0 commit comments