|
| 1 | +// RUN: %target-sil-opt -closure-lifetime-fixup %s | %FileCheck %s |
| 2 | + |
| 3 | +sil_stage raw |
| 4 | + |
| 5 | +import Swift |
| 6 | +import Builtin |
| 7 | +import SwiftShims |
| 8 | + |
| 9 | +class FakeNSString {} |
| 10 | + |
| 11 | +sil @$sSSSgIgg_AAIegg_TR : $@convention(thin) (@guaranteed Optional<String>, @noescape @callee_guaranteed (@guaranteed Optional<String>) -> ()) -> () |
| 12 | +sil @noescapeBlock3 : $@convention(c) (Optional<@convention(block) @noescape (Optional<FakeNSString>) -> ()>, Optional<@convention(block) @noescape (Optional<FakeNSString>) -> ()>, Optional<FakeNSString>) -> () |
| 13 | +sil @$sSS10FoundationE19_bridgeToObjectiveCSo8FakeNSStringCyF : $@convention(method) (@guaranteed String) -> @owned FakeNSString |
| 14 | +sil @$sSS21_builtinStringLiteral17utf8CodeUnitCount7isASCIISSBp_BwBi1_tcfC : $@convention(method) (Builtin.RawPointer, Builtin.Word, Builtin.Int1, @thin String.Type) -> @owned String |
| 15 | +sil @$sSSSgIegg_So8FakeNSStringCSgIyBy_TR : $@convention(c) (@inout_aliasable @block_storage @callee_guaranteed (@guaranteed Optional<String>) -> (), Optional<FakeNSString>) -> () |
| 16 | + |
| 17 | +// Just make sure that we perform the optimization and do not trigger the ownership verifier. |
| 18 | +// |
| 19 | +// CHECK-LABEL: sil [ossa] @test1 : $@convention(thin) (@guaranteed Optional<@callee_guaranteed (@guaranteed Optional<String>) -> ()>, @guaranteed Optional<@callee_guaranteed (@guaranteed Optional<String>) -> ()>) -> () { |
| 20 | +// CHECK-NOT: convert_escape_to_noescape [not_guaranteed] |
| 21 | +// CHECK: } // end sil function 'test1' |
| 22 | +sil [ossa] @test1 : $@convention(thin) (@guaranteed Optional<@callee_guaranteed (@guaranteed Optional<String>) -> ()>, @guaranteed Optional<@callee_guaranteed (@guaranteed Optional<String>) -> ()>) -> () { |
| 23 | +bb0(%0 : @guaranteed $Optional<@callee_guaranteed (@guaranteed Optional<String>) -> ()>, %1 : @guaranteed $Optional<@callee_guaranteed (@guaranteed Optional<String>) -> ()>): |
| 24 | + %2 = copy_value %0 : $Optional<@callee_guaranteed (@guaranteed Optional<String>) -> ()> |
| 25 | + switch_enum %2 : $Optional<@callee_guaranteed (@guaranteed Optional<String>) -> ()>, case #Optional.some!enumelt.1: bb1, case #Optional.none!enumelt: bb12 |
| 26 | + |
| 27 | +bb1(%4 : @owned $@callee_guaranteed (@guaranteed Optional<String>) -> ()): |
| 28 | + %5 = convert_escape_to_noescape [not_guaranteed] %4 : $@callee_guaranteed (@guaranteed Optional<String>) -> () to $@noescape @callee_guaranteed (@guaranteed Optional<String>) -> () |
| 29 | + %6 = enum $Optional<@noescape @callee_guaranteed (@guaranteed Optional<String>) -> ()>, #Optional.some!enumelt.1, %5 : $@noescape @callee_guaranteed (@guaranteed Optional<String>) -> () |
| 30 | + destroy_value %4 : $@callee_guaranteed (@guaranteed Optional<String>) -> () |
| 31 | + br bb2(%6 : $Optional<@noescape @callee_guaranteed (@guaranteed Optional<String>) -> ()>) |
| 32 | + |
| 33 | +bb2(%9 : $Optional<@noescape @callee_guaranteed (@guaranteed Optional<String>) -> ()>): |
| 34 | + switch_enum %9 : $Optional<@noescape @callee_guaranteed (@guaranteed Optional<String>) -> ()>, case #Optional.some!enumelt.1: bb3, case #Optional.none!enumelt: bb4 |
| 35 | + |
| 36 | +bb3(%11 : $@noescape @callee_guaranteed (@guaranteed Optional<String>) -> ()): |
| 37 | + %12 = function_ref @$sSSSgIgg_AAIegg_TR : $@convention(thin) (@guaranteed Optional<String>, @noescape @callee_guaranteed (@guaranteed Optional<String>) -> ()) -> () |
| 38 | + %13 = partial_apply [callee_guaranteed] %12(%11) : $@convention(thin) (@guaranteed Optional<String>, @noescape @callee_guaranteed (@guaranteed Optional<String>) -> ()) -> () |
| 39 | + %14 = mark_dependence %13 : $@callee_guaranteed (@guaranteed Optional<String>) -> () on %11 : $@noescape @callee_guaranteed (@guaranteed Optional<String>) -> () |
| 40 | + %15 = copy_value %14 : $@callee_guaranteed (@guaranteed Optional<String>) -> () |
| 41 | + %16 = alloc_stack $@block_storage @callee_guaranteed (@guaranteed Optional<String>) -> () |
| 42 | + %17 = project_block_storage %16 : $*@block_storage @callee_guaranteed (@guaranteed Optional<String>) -> () |
| 43 | + store %15 to [init] %17 : $*@callee_guaranteed (@guaranteed Optional<String>) -> () |
| 44 | + %19 = function_ref @$sSSSgIegg_So8FakeNSStringCSgIyBy_TR : $@convention(c) (@inout_aliasable @block_storage @callee_guaranteed (@guaranteed Optional<String>) -> (), Optional<FakeNSString>) -> () |
| 45 | + %20 = init_block_storage_header %16 : $*@block_storage @callee_guaranteed (@guaranteed Optional<String>) -> (), invoke %19 : $@convention(c) (@inout_aliasable @block_storage @callee_guaranteed (@guaranteed Optional<String>) -> (), Optional<FakeNSString>) -> (), type $@convention(block) @noescape (Optional<FakeNSString>) -> () |
| 46 | + %21 = copy_block_without_escaping %20 : $@convention(block) @noescape (Optional<FakeNSString>) -> () withoutEscaping %14 : $@callee_guaranteed (@guaranteed Optional<String>) -> () |
| 47 | + %22 = enum $Optional<@convention(block) @noescape (Optional<FakeNSString>) -> ()>, #Optional.some!enumelt.1, %21 : $@convention(block) @noescape (Optional<FakeNSString>) -> () |
| 48 | + destroy_addr %17 : $*@callee_guaranteed (@guaranteed Optional<String>) -> () |
| 49 | + dealloc_stack %16 : $*@block_storage @callee_guaranteed (@guaranteed Optional<String>) -> () |
| 50 | + br bb5(%22 : $Optional<@convention(block) @noescape (Optional<FakeNSString>) -> ()>) |
| 51 | + |
| 52 | +bb4: |
| 53 | + %26 = enum $Optional<@convention(block) @noescape (Optional<FakeNSString>) -> ()>, #Optional.none!enumelt |
| 54 | + br bb5(%26 : $Optional<@convention(block) @noescape (Optional<FakeNSString>) -> ()>) |
| 55 | + |
| 56 | +bb5(%28 : @owned $Optional<@convention(block) @noescape (Optional<FakeNSString>) -> ()>): |
| 57 | + %29 = copy_value %1 : $Optional<@callee_guaranteed (@guaranteed Optional<String>) -> ()> |
| 58 | + switch_enum %29 : $Optional<@callee_guaranteed (@guaranteed Optional<String>) -> ()>, case #Optional.some!enumelt.1: bb6, case #Optional.none!enumelt: bb11 |
| 59 | + |
| 60 | +bb6(%31 : @owned $@callee_guaranteed (@guaranteed Optional<String>) -> ()): |
| 61 | + %32 = convert_escape_to_noescape [not_guaranteed] %31 : $@callee_guaranteed (@guaranteed Optional<String>) -> () to $@noescape @callee_guaranteed (@guaranteed Optional<String>) -> () |
| 62 | + %33 = enum $Optional<@noescape @callee_guaranteed (@guaranteed Optional<String>) -> ()>, #Optional.some!enumelt.1, %32 : $@noescape @callee_guaranteed (@guaranteed Optional<String>) -> () |
| 63 | + destroy_value %31 : $@callee_guaranteed (@guaranteed Optional<String>) -> () |
| 64 | + br bb7(%33 : $Optional<@noescape @callee_guaranteed (@guaranteed Optional<String>) -> ()>) |
| 65 | + |
| 66 | +bb7(%36 : $Optional<@noescape @callee_guaranteed (@guaranteed Optional<String>) -> ()>): |
| 67 | + switch_enum %36 : $Optional<@noescape @callee_guaranteed (@guaranteed Optional<String>) -> ()>, case #Optional.some!enumelt.1: bb8, case #Optional.none!enumelt: bb9 |
| 68 | + |
| 69 | +bb8(%38 : $@noescape @callee_guaranteed (@guaranteed Optional<String>) -> ()): |
| 70 | + %39 = function_ref @$sSSSgIgg_AAIegg_TR : $@convention(thin) (@guaranteed Optional<String>, @noescape @callee_guaranteed (@guaranteed Optional<String>) -> ()) -> () |
| 71 | + %40 = partial_apply [callee_guaranteed] %39(%38) : $@convention(thin) (@guaranteed Optional<String>, @noescape @callee_guaranteed (@guaranteed Optional<String>) -> ()) -> () |
| 72 | + %41 = mark_dependence %40 : $@callee_guaranteed (@guaranteed Optional<String>) -> () on %38 : $@noescape @callee_guaranteed (@guaranteed Optional<String>) -> () |
| 73 | + %42 = copy_value %41 : $@callee_guaranteed (@guaranteed Optional<String>) -> () |
| 74 | + %43 = alloc_stack $@block_storage @callee_guaranteed (@guaranteed Optional<String>) -> () |
| 75 | + %44 = project_block_storage %43 : $*@block_storage @callee_guaranteed (@guaranteed Optional<String>) -> () |
| 76 | + store %42 to [init] %44 : $*@callee_guaranteed (@guaranteed Optional<String>) -> () |
| 77 | + %46 = function_ref @$sSSSgIegg_So8FakeNSStringCSgIyBy_TR : $@convention(c) (@inout_aliasable @block_storage @callee_guaranteed (@guaranteed Optional<String>) -> (), Optional<FakeNSString>) -> () |
| 78 | + %47 = init_block_storage_header %43 : $*@block_storage @callee_guaranteed (@guaranteed Optional<String>) -> (), invoke %46 : $@convention(c) (@inout_aliasable @block_storage @callee_guaranteed (@guaranteed Optional<String>) -> (), Optional<FakeNSString>) -> (), type $@convention(block) @noescape (Optional<FakeNSString>) -> () |
| 79 | + %48 = copy_block_without_escaping %47 : $@convention(block) @noescape (Optional<FakeNSString>) -> () withoutEscaping %41 : $@callee_guaranteed (@guaranteed Optional<String>) -> () |
| 80 | + %49 = enum $Optional<@convention(block) @noescape (Optional<FakeNSString>) -> ()>, #Optional.some!enumelt.1, %48 : $@convention(block) @noescape (Optional<FakeNSString>) -> () |
| 81 | + destroy_addr %44 : $*@callee_guaranteed (@guaranteed Optional<String>) -> () |
| 82 | + dealloc_stack %43 : $*@block_storage @callee_guaranteed (@guaranteed Optional<String>) -> () |
| 83 | + br bb10(%49 : $Optional<@convention(block) @noescape (Optional<FakeNSString>) -> ()>) |
| 84 | + |
| 85 | +bb9: |
| 86 | + %53 = enum $Optional<@convention(block) @noescape (Optional<FakeNSString>) -> ()>, #Optional.none!enumelt |
| 87 | + br bb10(%53 : $Optional<@convention(block) @noescape (Optional<FakeNSString>) -> ()>) |
| 88 | + |
| 89 | +bb10(%55 : @owned $Optional<@convention(block) @noescape (Optional<FakeNSString>) -> ()>): |
| 90 | + %56 = string_literal utf8 "Foobar" |
| 91 | + %57 = integer_literal $Builtin.Word, 6 |
| 92 | + %58 = integer_literal $Builtin.Int1, -1 |
| 93 | + %59 = metatype $@thin String.Type |
| 94 | + %60 = function_ref @$sSS21_builtinStringLiteral17utf8CodeUnitCount7isASCIISSBp_BwBi1_tcfC : $@convention(method) (Builtin.RawPointer, Builtin.Word, Builtin.Int1, @thin String.Type) -> @owned String |
| 95 | + %61 = apply %60(%56, %57, %58, %59) : $@convention(method) (Builtin.RawPointer, Builtin.Word, Builtin.Int1, @thin String.Type) -> @owned String |
| 96 | + %62 = function_ref @$sSS10FoundationE19_bridgeToObjectiveCSo8FakeNSStringCyF : $@convention(method) (@guaranteed String) -> @owned FakeNSString |
| 97 | + %63 = begin_borrow %61 : $String |
| 98 | + %64 = apply %62(%63) : $@convention(method) (@guaranteed String) -> @owned FakeNSString |
| 99 | + end_borrow %63 : $String |
| 100 | + %66 = enum $Optional<FakeNSString>, #Optional.some!enumelt.1, %64 : $FakeNSString |
| 101 | + destroy_value %61 : $String |
| 102 | + %68 = function_ref @noescapeBlock3 : $@convention(c) (Optional<@convention(block) @noescape (Optional<FakeNSString>) -> ()>, Optional<@convention(block) @noescape (Optional<FakeNSString>) -> ()>, Optional<FakeNSString>) -> () |
| 103 | + %69 = apply %68(%28, %55, %66) : $@convention(c) (Optional<@convention(block) @noescape (Optional<FakeNSString>) -> ()>, Optional<@convention(block) @noescape (Optional<FakeNSString>) -> ()>, Optional<FakeNSString>) -> () |
| 104 | + destroy_value %66 : $Optional<FakeNSString> |
| 105 | + destroy_value %55 : $Optional<@convention(block) @noescape (Optional<FakeNSString>) -> ()> |
| 106 | + destroy_value %28 : $Optional<@convention(block) @noescape (Optional<FakeNSString>) -> ()> |
| 107 | + %73 = tuple () |
| 108 | + return %73 : $() |
| 109 | + |
| 110 | +bb11: |
| 111 | + %75 = enum $Optional<@noescape @callee_guaranteed (@guaranteed Optional<String>) -> ()>, #Optional.none!enumelt |
| 112 | + br bb7(%75 : $Optional<@noescape @callee_guaranteed (@guaranteed Optional<String>) -> ()>) |
| 113 | + |
| 114 | +bb12: |
| 115 | + %77 = enum $Optional<@noescape @callee_guaranteed (@guaranteed Optional<String>) -> ()>, #Optional.none!enumelt |
| 116 | + br bb2(%77 : $Optional<@noescape @callee_guaranteed (@guaranteed Optional<String>) -> ()>) |
| 117 | +} |
0 commit comments