Skip to content

Commit aa47423

Browse files
committed
[SILOpt] Don't opt move-only lifetimes.
According to language rules, such lifetimes are fixed and the relative order of their deinits is guaranteed. rdar://110913116
1 parent 4c02d77 commit aa47423

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

test/SILOptimizer/canonicalize_ossa_lifetime_unit.sil

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ class C {}
55
@_moveOnly struct MoS {}
66
@_moveOnly struct MoE {}
77

8+
@_moveOnly struct MoS {}
9+
@_moveOnly struct MoE {}
10+
811
// When access scopes are respected, the lifetime which previously extended
912
// beyond the access scope still extends beyond it.
1013
// CHECK-LABEL: begin running test 1 of 2 on retract_value_lifetime_into_access_scope_when_access_scopes_not_respected: canonicalize-ossa-lifetime with: true, false, true, @trace
@@ -91,3 +94,46 @@ entry(%instance : @owned $MoE):
9194
%retval = tuple ()
9295
return %retval : $()
9396
}
97+
98+
sil @empty : $@convention(thin) () -> () {
99+
[global: ]
100+
bb0:
101+
%0 = tuple ()
102+
return %0 : $()
103+
}
104+
105+
// Even though the apply of %empty is not a deinit barrier, verify that the
106+
// destroy is not hoisted, because MoS is move-only.
107+
// CHECK-LABEL: begin running test {{.*}} on dont_move_destroy_value_of_moveonly_struct: canonicalize-ossa-lifetime with: true, false, true, @argument
108+
// CHECK-LABEL: sil [ossa] @dont_move_destroy_value_of_moveonly_struct : {{.*}} {
109+
// CHECK: {{bb[0-9]+}}([[INSTANCE:%[^,]+]] :
110+
// CHECK: apply
111+
// CHECK: destroy_value [[INSTANCE]]
112+
// CHECK-LABEL: } // end sil function 'dont_move_destroy_value_of_moveonly_struct'
113+
// CHECK-LABEL: end running test {{.*}} on dont_move_destroy_value_of_moveonly_struct: canonicalize-ossa-lifetime with: true, false, true, @argument
114+
sil [ossa] @dont_move_destroy_value_of_moveonly_struct : $@convention(thin) (@owned MoS) -> () {
115+
entry(%instance : @owned $MoS):
116+
test_specification "canonicalize-ossa-lifetime true false true @argument"
117+
%empty = function_ref @empty : $@convention(thin) () -> ()
118+
apply %empty() : $@convention(thin) () -> ()
119+
destroy_value %instance : $MoS
120+
%retval = tuple ()
121+
return %retval : $()
122+
}
123+
124+
// CHECK-LABEL: begin running test {{.*}} on dont_move_destroy_value_of_moveonly_enum: canonicalize-ossa-lifetime with: true, false, true, @argument
125+
// CHECK-LABEL: sil [ossa] @dont_move_destroy_value_of_moveonly_enum : {{.*}} {
126+
// CHECK: {{bb[0-9]+}}([[INSTANCE:%[^,]+]] :
127+
// CHECK: apply
128+
// CHECK: destroy_value [[INSTANCE]]
129+
// CHECK-LABEL: } // end sil function 'dont_move_destroy_value_of_moveonly_enum'
130+
// CHECK-LABEL: end running test {{.*}} on dont_move_destroy_value_of_moveonly_enum: canonicalize-ossa-lifetime with: true, false, true, @argument
131+
sil [ossa] @dont_move_destroy_value_of_moveonly_enum : $@convention(thin) (@owned MoE) -> () {
132+
entry(%instance : @owned $MoE):
133+
test_specification "canonicalize-ossa-lifetime true false true @argument"
134+
%empty = function_ref @empty : $@convention(thin) () -> ()
135+
apply %empty() : $@convention(thin) () -> ()
136+
destroy_value %instance : $MoE
137+
%retval = tuple ()
138+
return %retval : $()
139+
}

0 commit comments

Comments
 (0)