@@ -49,6 +49,17 @@ class C {
4949 var w : FakeOptional<Builtin.NativeObject>
5050}
5151
52+ enum E {
53+ case A(C)
54+ case B
55+ }
56+
57+ struct StructWithEnum {
58+ @_hasStorage var e: E { get }
59+ init(e: E)
60+ }
61+
62+
5263sil @cls_use : $@convention(thin) (@owned Cls) -> ()
5364
5465class Container {
@@ -2391,3 +2402,43 @@ bb0:
23912402 %15 = tuple ()
23922403 return %15 : $()
23932404}
2405+
2406+ sil @closure : $@convention(thin) (@inout E, @guaranteed C) -> ()
2407+ sil @call_closure : $@convention(method) (@guaranteed @noescape @callee_guaranteed (@inout E) -> (), @inout StructWithEnum) -> @out S2
2408+
2409+ // CHECK-LABEL: sil @test_apply_with_out_arg :
2410+ // CHECK: retain_value
2411+ // CHECK: strong_release
2412+ // CHECK: release_value
2413+ // CHECK: } // end sil function 'test_apply_with_out_arg'
2414+ sil @test_apply_with_out_arg : $@convention(method) (@guaranteed StructWithEnum) -> () {
2415+ bb0(%0 : $StructWithEnum):
2416+ %1 = alloc_stack $StructWithEnum
2417+ store %0 to %1 : $*StructWithEnum
2418+ %3 = struct_element_addr %1 : $*StructWithEnum, #StructWithEnum.e
2419+ %4 = load %3 : $*E
2420+ retain_value %4 : $E
2421+ switch_enum %4 : $E, case #E.A!enumelt: bb1, default bb2
2422+
2423+
2424+ bb1(%7 : $C):
2425+ %8 = alloc_stack $S2
2426+ %9 = function_ref @closure : $@convention(thin) (@inout E, @guaranteed C) -> ()
2427+ %10 = partial_apply [callee_guaranteed] [on_stack] %9(%7) : $@convention(thin) (@inout E, @guaranteed C) -> ()
2428+ %11 = function_ref @call_closure : $@convention(method) (@guaranteed @noescape @callee_guaranteed (@inout E) -> (), @inout StructWithEnum) -> @out S2
2429+ %12 = apply %11(%8, %10, %1) : $@convention(method) (@guaranteed @noescape @callee_guaranteed (@inout E) -> (), @inout StructWithEnum) -> @out S2
2430+ dealloc_stack %10 : $@noescape @callee_guaranteed (@inout E) -> ()
2431+ strong_release %7 : $C
2432+ dealloc_stack %8 : $*S2
2433+ br bb3
2434+
2435+ bb2:
2436+ release_value %4 : $E
2437+ br bb3
2438+
2439+ bb3:
2440+ dealloc_stack %1 : $*StructWithEnum
2441+ %21 = tuple ()
2442+ return %21 : $()
2443+ }
2444+
0 commit comments