|
1 |
| -// RUN: %target-sil-opt %s -dump-addr-escape-info -o /dev/null | %FileCheck %s |
| 1 | +// RUN: %target-sil-opt %s -dump-addr-escape-info -o /dev/null \ |
| 2 | +// RUN: -enable-experimental-feature LifetimeDependence \ |
| 3 | +// RUN: -enable-experimental-feature AddressableTypes \ |
| 4 | +// RUN: | %FileCheck %s |
| 5 | + |
| 6 | +// REQUIRES: swift_feature_LifetimeDependence |
| 7 | +// REQUIRES: swift_feature_AddressableTypes |
2 | 8 |
|
3 | 9 | // REQUIRES: swift_in_compiler
|
4 | 10 |
|
@@ -37,6 +43,13 @@ protocol P {}
|
37 | 43 |
|
38 | 44 | extension Int : P {}
|
39 | 45 |
|
| 46 | +@_addressableForDependencies |
| 47 | +struct Addressable { |
| 48 | + @_hasStorage var a: Int |
| 49 | +} |
| 50 | + |
| 51 | +struct NE : ~Escapable {} |
| 52 | + |
40 | 53 | sil @no_arguments : $@convention(thin) () -> ()
|
41 | 54 | sil @indirect_argument : $@convention(thin) (@in Int) -> ()
|
42 | 55 | sil @indirect_struct_argument : $@convention(thin) (@in Str) -> ()
|
@@ -69,6 +82,14 @@ sil @modifyStr : $@convention(method) (@inout Str) -> ()
|
69 | 82 | sil @guaranteed_yield_coroutine : $@yield_once @convention(thin) (@inout X) -> @yields @inout X
|
70 | 83 | sil @in_ptr : $@convention(thin) (@in Builtin.RawPointer) -> ()
|
71 | 84 |
|
| 85 | +sil @addressable_independent_arg : $@convention(thin) (@in_guaranteed Addressable) -> Builtin.RawPointer |
| 86 | + |
| 87 | +sil @addressable_dependent_arg : $@convention(thin) (@in_guaranteed Addressable) -> @lifetime(borrow address_for_deps 0) @owned NE |
| 88 | + |
| 89 | +sil @addressable_noescape_arg : $@convention(thin) (@in_guaranteed Addressable) -> @lifetime(borrow address_for_deps 0) @owned NE { |
| 90 | +[%0: noescape] |
| 91 | +} |
| 92 | + |
72 | 93 | // CHECK-LABEL: Address escape information for test_simple:
|
73 | 94 | // CHECK: value: %1 = struct_element_addr %0 : $*Str, #Str.a
|
74 | 95 | // CHECK-NEXT: ==> %7 = apply %6(%5) : $@convention(thin) (@in Int) -> ()
|
@@ -862,3 +883,76 @@ bb0(%0 : @guaranteed $X):
|
862 | 883 | return %3 : $()
|
863 | 884 | }
|
864 | 885 |
|
| 886 | +// CHECK-LABEL: Address escape information for noescape_via_independent_addressable: |
| 887 | +// CHECK: pair 0 - 1 |
| 888 | +// CHECK-NEXT: apply %{{.*}}(%{{.*}}) : $@convention(thin) (@in_guaranteed Addressable) -> Builtin.RawPointer |
| 889 | +// CHECK-NEXT: alloc_stack $Addressable |
| 890 | +// CHECK-NEXT: no alias |
| 891 | +// CHECK-LABEL: End function noescape_via_independent_addressable |
| 892 | +sil [ossa] @noescape_via_independent_addressable : $@convention(thin) (Int) -> () { |
| 893 | +bb0(%0 : $Int): |
| 894 | + %1 = alloc_stack $Addressable |
| 895 | + %2 = struct_element_addr %1 : $*Addressable, #Addressable.a |
| 896 | + store %0 to [trivial] %2 |
| 897 | + |
| 898 | + %f = function_ref @addressable_independent_arg : $@convention(thin) (@in_guaranteed Addressable) -> Builtin.RawPointer |
| 899 | + %a = apply %f(%1) : $@convention(thin) (@in_guaranteed Addressable) -> Builtin.RawPointer |
| 900 | + |
| 901 | + fix_lifetime %a |
| 902 | + fix_lifetime %1 |
| 903 | + destroy_addr %1 |
| 904 | + dealloc_stack %1 |
| 905 | + |
| 906 | + %9 = tuple () |
| 907 | + return %9 : $() |
| 908 | +} |
| 909 | + |
| 910 | +// CHECK-LABEL: Address escape information for escape_via_dependent_addressable: |
| 911 | +// CHECK: pair 0 - 1 |
| 912 | +// CHECK-NEXT: %{{.*}} = apply %{{.*}}(%{{.*}}) : $@convention(thin) (@in_guaranteed Addressable) -> @lifetime(borrow address_for_deps 0) @owned NE |
| 913 | +// CHECK-NEXT: %{{.*}} = alloc_stack $Addressable |
| 914 | +// CHECK-NEXT: may alias |
| 915 | +// CHECK-LABEL: End function escape_via_dependent_addressable |
| 916 | +sil [ossa] @escape_via_dependent_addressable : $@convention(thin) (Int) -> () { |
| 917 | +bb0(%0 : $Int): |
| 918 | + %1 = alloc_stack $Addressable |
| 919 | + %2 = struct_element_addr %1 : $*Addressable, #Addressable.a |
| 920 | + store %0 to [trivial] %2 |
| 921 | + |
| 922 | + %f = function_ref @addressable_dependent_arg : $@convention(thin) (@in_guaranteed Addressable) -> @lifetime(borrow address_for_deps 0) @owned NE |
| 923 | + %a = apply %f(%1) : $@convention(thin) (@in_guaranteed Addressable) -> @lifetime(borrow address_for_deps 0) @owned NE |
| 924 | + |
| 925 | + fix_lifetime %a |
| 926 | + fix_lifetime %1 |
| 927 | + destroy_value %a |
| 928 | + destroy_addr %1 |
| 929 | + dealloc_stack %1 |
| 930 | + |
| 931 | + %9 = tuple () |
| 932 | + return %9 : $() |
| 933 | +} |
| 934 | + |
| 935 | +// CHECK-LABEL: Address escape information for escape_via_noescape_addressable: |
| 936 | +// CHECK: pair 0 - 1 |
| 937 | +// CHECK-NEXT: %{{.*}} = apply %{{.*}}(%{{.*}}) : $@convention(thin) (@in_guaranteed Addressable) -> @lifetime(borrow address_for_deps 0) @owned NE |
| 938 | +// CHECK-NEXT: %{{.*}} = alloc_stack $Addressable |
| 939 | +// CHECK-NEXT: no alias |
| 940 | +// CHECK-LABEL: End function escape_via_noescape_addressable |
| 941 | +sil [ossa] @escape_via_noescape_addressable : $@convention(thin) (Int) -> () { |
| 942 | +bb0(%0 : $Int): |
| 943 | + %1 = alloc_stack $Addressable |
| 944 | + %2 = struct_element_addr %1 : $*Addressable, #Addressable.a |
| 945 | + store %0 to [trivial] %2 |
| 946 | + |
| 947 | + %f = function_ref @addressable_noescape_arg : $@convention(thin) (@in_guaranteed Addressable) -> @lifetime(borrow address_for_deps 0) @owned NE |
| 948 | + %a = apply %f(%1) : $@convention(thin) (@in_guaranteed Addressable) -> @lifetime(borrow address_for_deps 0) @owned NE |
| 949 | + |
| 950 | + fix_lifetime %a |
| 951 | + fix_lifetime %1 |
| 952 | + destroy_value %a |
| 953 | + destroy_addr %1 |
| 954 | + dealloc_stack %1 |
| 955 | + |
| 956 | + %9 = tuple () |
| 957 | + return %9 : $() |
| 958 | +} |
0 commit comments