| // RUN: %target-sil-opt -assume-parsing-unqualified-ownership-sil -enable-sil-verify-all %s -array-specialize |
| |
| sil_stage canonical |
| |
| import Builtin |
| import Swift |
| |
| struct ArrayIntBuffer { |
| var storage : Builtin.NativeObject |
| } |
| |
| struct MyArray<T> { |
| var buffer : ArrayIntBuffer |
| } |
| |
| enum MyBool{ |
| case True |
| case False |
| } |
| |
| class MyClass { |
| } |
| |
| /// We need to split the loop exit edge from bb1 to bb3 before updating ssa form |
| /// after cloning. |
| sil @clone_switch_enum_exit : $@convention(thin) (@inout MyArray<MyClass>, @inout MyBool) -> MyBool { |
| bb0(%0 : $*MyArray<MyClass>, %1 : $*MyBool): |
| %3 = load %0 : $*MyArray<MyClass> |
| br bb1 |
| |
| bb1: |
| %2 = function_ref @arrayPropertyIsNative : $@convention(method) (@owned MyArray<MyClass>) -> Bool |
| %4 = load %1 : $*MyBool |
| retain_value %3 : $MyArray<MyClass> |
| %5 = apply %2(%3) : $@convention(method) (@owned MyArray<MyClass>) -> Bool |
| switch_enum %4 : $MyBool, case #MyBool.False!enumelt: bb3, case #MyBool.True!enumelt: bb2 |
| |
| bb2: |
| %6 = integer_literal $Builtin.Int1, -1 |
| cond_br %6, bb1, bb4 |
| |
| bb3: |
| br bb4 |
| |
| bb4: |
| return %4 : $MyBool |
| } |
| |
| protocol AProtocol : class { |
| } |
| |
| sil @cant_handle_open_existential_use_outside_loop : $@convention(thin) (@inout MyArray<MyClass>, @inout MyBool, @owned AProtocol) -> MyBool { |
| bb0(%0 : $*MyArray<MyClass>, %1 : $*MyBool, %10 : $AProtocol): |
| %3 = load %0 : $*MyArray<MyClass> |
| br bb1 |
| |
| bb1: |
| %2 = function_ref @arrayPropertyIsNative : $@convention(method) (@owned MyArray<MyClass>) -> Bool |
| %4 = load %1 : $*MyBool |
| retain_value %3 : $MyArray<MyClass> |
| %5 = apply %2(%3) : $@convention(method) (@owned MyArray<MyClass>) -> Bool |
| %11 = open_existential_ref %10 : $AProtocol to $@opened("B538073C-2428-11E5-AC93-C82A1428F987") AProtocol |
| switch_enum %4 : $MyBool, case #MyBool.False!enumelt: bb3, case #MyBool.True!enumelt: bb2 |
| |
| bb2: |
| %6 = integer_literal $Builtin.Int1, -1 |
| cond_br %6, bb1, bb4 |
| |
| bb3: |
| br bb4 |
| |
| bb4: |
| release_value %11 : $@opened("B538073C-2428-11E5-AC93-C82A1428F987") AProtocol |
| return %4 : $MyBool |
| } |
| |
| sil public_external [_semantics "array.props.isNativeTypeChecked"] @arrayPropertyIsNative : $@convention(method) (@owned MyArray<MyClass>) -> Bool { |
| bb0(%0: $MyArray<MyClass>): |
| unreachable |
| } |
| |
| // Make sure we can handle try_apply when splitting edges. This test used to crash. |
| |
| sil @throwing_fun : $@convention(thin) () -> (MyBool, @error Error) |
| |
| sil @clone_try_apply_exit : $@convention(thin) (@inout MyArray<MyClass>, @inout MyBool) -> (MyBool, @error Error) { |
| bb0(%0 : $*MyArray<MyClass>, %1 : $*MyBool): |
| %3 = load %0 : $*MyArray<MyClass> |
| br bb1 |
| |
| bb1: |
| %2 = function_ref @arrayPropertyIsNative : $@convention(method) (@owned MyArray<MyClass>) -> Bool |
| %4 = load %1 : $*MyBool |
| retain_value %3 : $MyArray<MyClass> |
| %5 = apply %2(%3) : $@convention(method) (@owned MyArray<MyClass>) -> Bool |
| %7 = function_ref @throwing_fun : $@convention(thin) () -> (MyBool, @error Error) |
| try_apply %7() : $@convention(thin) () -> (MyBool, @error Error), normal bb2, error bb5 |
| |
| bb2(%8 : $MyBool): |
| %6 = integer_literal $Builtin.Int1, -1 |
| cond_br %6, bb1, bb4 |
| |
| bb3: |
| br bb4 |
| |
| bb4: |
| return %4 : $MyBool |
| |
| bb5(%9 : $Error): |
| throw %9 : $Error |
| } |