@@ -11,6 +11,7 @@ class C {
1111 weak var d: D?
1212}
1313class D {}
14+ struct S {}
1415class DBox {
1516 var d: D
1617}
@@ -32,6 +33,7 @@ sil [ossa] @callee_guaranteed: $@convention(thin) (@guaranteed C) -> ()
3233sil [ossa] @callee_owned : $@convention(thin) (@owned C) -> ()
3334sil [ossa] @callee_optional_d_guaranteed: $@convention(thin) (@guaranteed Optional<D>) -> ()
3435sil [ossa] @synchronization_point : $@convention(thin) () -> ()
36+ sil [ossa] @modify_s : $@yield_once @convention(thin) () -> @yields @inout S
3537
3638// =============================================================================
3739// = DECLARATIONS }}
@@ -807,6 +809,27 @@ exit:
807809 return %retval : $()
808810}
809811
812+ // Don't hoist over end_apply. These are lowered to calls to continuations
813+ // which can have the same sorts of side-effects as function calls.
814+
815+ // CHECK-LABEL: sil [ossa] @dont_hoist_over_end_apply : {{.*}} {
816+ // CHECK: end_apply
817+ // CHECK: end_borrow
818+ // CHECK-LABEL: } // end sil function 'dont_hoist_over_end_apply'
819+ sil [ossa] @dont_hoist_over_end_apply : $@convention(thin) (@owned C, S) -> () {
820+ entry(%instance : @owned $C, %input : $S):
821+ %lifetime = begin_borrow [lexical] %instance : $C
822+ %modify_s = function_ref @modify_s : $@yield_once @convention(thin) () -> @yields @inout S
823+ (%addr, %continuation) = begin_apply %modify_s() : $@yield_once @convention(thin) () -> @yields @inout S
824+ store %input to [trivial] %addr : $*S
825+ end_apply %continuation
826+ end_borrow %lifetime : $C
827+ destroy_value %instance : $C
828+ %retval = tuple ()
829+ return %retval : $()
830+ }
831+
832+
810833// =============================================================================
811834// instruction tests }}
812835// =============================================================================
0 commit comments