@@ -36,6 +36,7 @@ sil [ossa] @callee_optional_d_guaranteed: $@convention(thin) (@guaranteed Option
3636sil [ossa] @synchronization_point : $@convention(thin) () -> ()
3737sil [ossa] @modify_s : $@yield_once @convention(thin) () -> @yields @inout S
3838sil [ossa] @barrier : $@convention(thin) () -> ()
39+ sil [ossa] @failable : $@convention(thin) () -> @error Error
3940
4041
4142// =============================================================================
@@ -891,7 +892,7 @@ exit:
891892
892893// Don't hoist over end_apply. These are lowered to calls to continuations
893894// which can have the same sorts of side-effects as function calls.
894-
895+ //
895896// CHECK-LABEL: sil [ossa] @dont_hoist_over_end_apply : {{.*}} {
896897// CHECK: end_apply
897898// CHECK: end_borrow
@@ -909,6 +910,40 @@ entry(%instance : @owned $C, %input : $S):
909910 return %retval : $()
910911}
911912
913+ // Don't hoist over abort_apply. These are lowered to calls to continuations
914+ // which can have the same sorts of side-effects as function calls.
915+ //
916+ // CHECK-LABEL: sil [ossa] @dont_hoist_over_abort_apply : {{.*}} {
917+ // CHECK: {{bb[0-9]+}}([[REGISTER_1:%[^,]+]] : $Error):
918+ // CHECK: abort_apply
919+ // CHECK: end_borrow
920+ // CHECK: destroy_value
921+ // CHECK: tuple
922+ // CHECK: throw
923+ // CHECK-LABEL: } // end sil function 'dont_hoist_over_abort_apply'
924+ sil [ossa] @dont_hoist_over_abort_apply : $@convention(thin) (@owned C, S) -> @error Error {
925+ entry(%instance : @owned $C, %input : $S):
926+ %lifetime = begin_borrow [lexical] %instance : $C
927+ %callee_guaranteed = function_ref @callee_guaranteed : $@convention(thin) (@guaranteed C) -> ()
928+ apply %callee_guaranteed(%lifetime) : $@convention(thin) (@guaranteed C) -> ()
929+ %modify_s = function_ref @modify_s : $@yield_once @convention(thin) () -> @yields @inout S
930+ (%addr, %continuation) = begin_apply %modify_s() : $@yield_once @convention(thin) () -> @yields @inout S
931+ %failable = function_ref @failable : $@convention(thin) () -> @error Error
932+ try_apply %failable() : $@convention(thin) () -> @error Error, normal success, error failure
933+ success(%retval : $()):
934+ store %input to [trivial] %addr : $*S
935+ end_apply %continuation
936+ end_borrow %lifetime : $C
937+ destroy_value %instance : $C
938+ return %retval : $()
939+ failure(%error : $Error):
940+ abort_apply %continuation
941+ %blah = tuple ()
942+ end_borrow %lifetime : $C
943+ destroy_value %instance : $C
944+ throw %error : $Error
945+ }
946+
912947// Don't hoist out of a block when one of its predecessors has a terminator that
913948// is a use of the end_borrow.
914949//
0 commit comments