@@ -63,6 +63,11 @@ public class KlassBar : KlassFoo {
6363 init()
6464}
6565
66+ indirect public enum IndirectEnum : Hashable {
67+ case A
68+ case B(IndirectEnum)
69+ }
70+
6671sil @use_Int : $@convention(thin) (Int) -> ()
6772sil @use_Int64 : $@convention(thin) (Int64) -> ()
6873sil @use_Generic : $@convention(thin) <T>(@in_guaranteed T) -> ()
@@ -514,6 +519,39 @@ bb0(%0 : $boo):
514519 return %0 : $boo
515520}
516521
522+ // CHECK-LABEL: sil @no_fso_recursive_result_is_not_returned :
523+ // CHECK-NOT: release_value
524+ // CHECK: bb2:
525+ // CHECK-NEXT: retain_value %0
526+ // CHECK: return
527+ // CHECK-LABEL: } // end sil function 'no_fso_recursive_result_is_not_returned'
528+ sil @no_fso_recursive_result_is_not_returned : $@convention(method) (@guaranteed IndirectEnum, @guaranteed IndirectEnum) -> @owned IndirectEnum {
529+ bb0(%0 : $IndirectEnum, %1 : $IndirectEnum):
530+ switch_enum %1 : $IndirectEnum, case #IndirectEnum.B!enumelt: bb1, default bb2
531+
532+ bb1(%3 : ${ var IndirectEnum }):
533+ %4 = project_box %3 : ${ var IndirectEnum }, 0
534+ %5 = load %4 : $*IndirectEnum
535+ %6 = function_ref @no_fso_recursive_result_is_not_returned : $@convention(method) (@guaranteed IndirectEnum, @guaranteed IndirectEnum) -> @owned IndirectEnum
536+
537+ // The result of the self-recursion is not returned (but put in a box).
538+ // This prevents guaranteed -> owned return value specialization.
539+ %7 = apply %6(%0, %5) : $@convention(method) (@guaranteed IndirectEnum, @guaranteed IndirectEnum) -> @owned IndirectEnum
540+ %8 = alloc_box ${ var IndirectEnum }
541+ %9 = project_box %8 : ${ var IndirectEnum }, 0
542+ store %7 to %9 : $*IndirectEnum
543+ %11 = enum $IndirectEnum, #IndirectEnum.B!enumelt, %8 : ${ var IndirectEnum }
544+ br bb3(%11 : $IndirectEnum)
545+
546+ bb2:
547+ retain_value %0 : $IndirectEnum
548+ br bb3(%0 : $IndirectEnum)
549+
550+ bb3(%35 : $IndirectEnum):
551+ return %35 : $IndirectEnum
552+ }
553+
554+
517555// Make sure we do not move the retain_value in the throw block.
518556//
519557// CHECK-LABEL: sil [serialized] [signature_optimized_thunk] [always_inline] @owned_to_unowned_retval_with_error_result : $@convention(thin) (@owned boo) -> (@owned boo, @error Error) {
0 commit comments