|
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 {}
|
6 | 7 |
|
7 | 8 | enum Never {}
|
| 9 | + |
| 10 | +struct Pointer { |
| 11 | + var rawValue: Builtin.RawPointer |
| 12 | +} |
| 13 | + |
| 14 | +struct Int32 { |
| 15 | + var int: Builtin.Int32 |
| 16 | +} |
8 | 17 | sil @run : $@convention(thin) () -> Never
|
9 | 18 | sil @getOwned : $@convention(thin) () -> @owned C
|
10 | 19 | sil @barrier : $@convention(thin) () -> ()
|
11 | 20 | sil [ossa] @getC : $@convention(thin) () -> @owned C
|
12 | 21 | sil [ossa] @borrowC : $@convention(thin) (@guaranteed C) -> ()
|
13 | 22 | sil [ossa] @takeC : $@convention(thin) (@owned C) -> ()
|
| 23 | +sil @getPointer : $@convention(thin) () -> (@owned Pointer) |
| 24 | + |
14 | 25 | struct S {}
|
15 | 26 |
|
16 | 27 | struct MoS: ~Copyable {}
|
@@ -963,3 +974,28 @@ entry(%c : @owned $C):
|
963 | 974 | %run = function_ref @run : $@convention(thin) () -> Never
|
964 | 975 | unreachable
|
965 | 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