|
1 | 1 | // RUN: %target-sil-opt -sil-print-types -test-runner %s -o /dev/null 2>&1 | %FileCheck %s
|
2 | 2 |
|
| 3 | +import Builtin |
3 | 4 | import Swift
|
4 | 5 |
|
5 | 6 | class C {}
|
| 7 | + |
| 8 | +enum Never {} |
| 9 | + |
| 10 | +struct Pointer { |
| 11 | + var rawValue: Builtin.RawPointer |
| 12 | +} |
| 13 | + |
| 14 | +struct Int32 { |
| 15 | + var int: Builtin.Int32 |
| 16 | +} |
| 17 | +sil @run : $@convention(thin) () -> Never |
6 | 18 | sil @getOwned : $@convention(thin) () -> @owned C
|
7 | 19 | sil @barrier : $@convention(thin) () -> ()
|
8 | 20 | sil [ossa] @getC : $@convention(thin) () -> @owned C
|
9 | 21 | sil [ossa] @borrowC : $@convention(thin) (@guaranteed C) -> ()
|
10 | 22 | sil [ossa] @takeC : $@convention(thin) (@owned C) -> ()
|
| 23 | +sil @getPointer : $@convention(thin) () -> (@owned Pointer) |
| 24 | + |
11 | 25 | struct S {}
|
12 | 26 |
|
13 | 27 | struct MoS: ~Copyable {}
|
@@ -885,6 +899,33 @@ die:
|
885 | 899 | unreachable
|
886 | 900 | }
|
887 | 901 |
|
| 902 | +// CHECK-LABEL: begin running test {{.*}} on consume_copy_before_use_in_dead_end_2 |
| 903 | +// CHECK-LABEL: sil [ossa] @consume_copy_before_use_in_dead_end_2 : {{.*}} { |
| 904 | +// CHECK-NOT: destroy_value [dead_end] |
| 905 | +// CHECK-LABEL: } // end sil function 'consume_copy_before_use_in_dead_end_2' |
| 906 | +// CHECK-LABEL: end running test {{.*}} on consume_copy_before_use_in_dead_end_2 |
| 907 | +sil [ossa] @consume_copy_before_use_in_dead_end_2 : $@convention(thin) (@owned C) -> () { |
| 908 | +entry(%c : @owned $C): |
| 909 | + cond_br undef, exit, die |
| 910 | + |
| 911 | +exit: |
| 912 | + destroy_value %c |
| 913 | + %retval = tuple () |
| 914 | + return %retval |
| 915 | + |
| 916 | +die: |
| 917 | + %move = move_value %c |
| 918 | + %copy = copy_value %move |
| 919 | + specify_test "canonicalize_ossa_lifetime true false true %move" |
| 920 | + apply undef(%move) : $@convention(thin) (@owned C) -> () |
| 921 | + %addr = alloc_stack $C |
| 922 | + %token = store_borrow %copy to %addr |
| 923 | + apply undef() : $@convention(thin) () -> () |
| 924 | + %reload = load_borrow %token |
| 925 | + apply undef(%reload) : $@convention(thin) (@guaranteed C) -> () |
| 926 | + unreachable |
| 927 | +} |
| 928 | + |
888 | 929 | // The destroy of a value must not be hoisted over a destroy of a copy of a
|
889 | 930 | // partial_apply [on_stack] which captures the value.
|
890 | 931 | // CHECK-LABEL: begin running test {{.*}} on destroy_after_pa_copy_destroy
|
@@ -918,3 +959,43 @@ entry(%a: @owned $C):
|
918 | 959 | %retval = tuple ()
|
919 | 960 | return %retval
|
920 | 961 | }
|
| 962 | + |
| 963 | +// CHECK-LABEL: begin running test {{.*}} on extend_lifetime_to_deadend_despite_copy_consume |
| 964 | +// CHECK-LABEL: sil [ossa] @extend_lifetime_to_deadend_despite_copy_consume : {{.*}} { |
| 965 | +// CHECK: copy_value |
| 966 | +// CHECK-LABEL: } // end sil function 'extend_lifetime_to_deadend_despite_copy_consume' |
| 967 | +// CHECK-LABEL: end running test {{.*}} on extend_lifetime_to_deadend_despite_copy_consume |
| 968 | +sil [ossa] @extend_lifetime_to_deadend_despite_copy_consume : $@convention(thin) (@owned C) -> () { |
| 969 | +entry(%c : @owned $C): |
| 970 | + specify_test "canonicalize_ossa_lifetime true false true @argument" |
| 971 | + %cc = copy_value %c |
| 972 | + %takeC = function_ref @takeC : $@convention(thin) (@owned C) -> () |
| 973 | + apply %takeC(%cc) : $@convention(thin) (@owned C) -> () |
| 974 | + %run = function_ref @run : $@convention(thin) () -> Never |
| 975 | + unreachable |
| 976 | +} |
| 977 | + |
| 978 | +/// If there's a pointer escape (here, mark_dependence) of the value, we can't |
| 979 | +/// canonicalize its lifetime. |
| 980 | +// CHECK-LABEL: begin running test {{.*}} on dont_canonicalize_on_pointer_escape |
| 981 | +// CHECK-LABEL: sil [ossa] @dont_canonicalize_on_pointer_escape : {{.*}} { |
| 982 | +// CHECK: load |
| 983 | +// CHECK-NEXT: destroy_value |
| 984 | +// CHECK-LABEL: } // end sil function 'dont_canonicalize_on_pointer_escape' |
| 985 | +// CHECK-LABEL: end running test {{.*}} on dont_canonicalize_on_pointer_escape |
| 986 | +sil [ossa] @dont_canonicalize_on_pointer_escape : $@convention(thin) () -> () { |
| 987 | +entry: |
| 988 | + %getC = function_ref @getC : $@convention(thin) () -> (@owned C) |
| 989 | + %getPointer = function_ref @getPointer : $@convention(thin) () -> (@owned Pointer) |
| 990 | + %c = apply %getC() : $@convention(thin) () -> (@owned C) |
| 991 | + %pointer = apply %getPointer() : $@convention(thin) () -> (@owned Pointer) |
| 992 | + specify_test "canonicalize_ossa_lifetime true false true %c" |
| 993 | + %rawPointer = struct_extract %pointer, #Pointer.rawValue |
| 994 | + %o = pointer_to_address %rawPointer to [strict] $*Int32 |
| 995 | + %dependent = mark_dependence [nonescaping] %o on %c |
| 996 | + %int_addr = struct_element_addr %dependent, #Int32.int |
| 997 | + %int = load [trivial] %int_addr |
| 998 | + destroy_value %c |
| 999 | + %retval = tuple () |
| 1000 | + return %retval : $() |
| 1001 | +} |
0 commit comments