1
- // RUN: %target-sil-opt -sil-ownership-verifier-enable-testing -ownership-verifier-textual-error-dumper -enable-sil-verify-all=0 %s -o /dev/null 2>&1 | %FileCheck %s
1
+ // RUN: %target-sil-opt -module-name Swift - sil-ownership-verifier-enable-testing -ownership-verifier-textual-error-dumper -enable-sil-verify-all=0 %s -o /dev/null 2>&1 | %FileCheck %s
2
2
// REQUIRES: asserts
3
3
4
- import Swift
5
-
6
4
sil_stage canonical
7
5
6
+ import Builtin
7
+
8
8
class Klass {}
9
9
10
10
class KlassUser {
11
11
var field: Klass
12
12
}
13
13
14
+ protocol Error {
15
+ var _code: Int { get }
16
+ }
17
+
18
+ sil @use_builtinnativeobject_inguaranteed : $@convention(thin) (@in_guaranteed Builtin.NativeObject) -> ()
19
+
14
20
// CHECK-LABEL: Function: 'simple_error_ref_element_addr'
15
21
// CHECK-NEXT: Found outside of lifetime use?!
16
22
// CHECK-NEXT: Value: %1 = begin_borrow %0 : $KlassUser // users: %3, %2
@@ -43,16 +49,21 @@ bb0(%0 : @owned $KlassUser):
43
49
return %3 : $Klass
44
50
}
45
51
52
+ enum FakeOptional<T> {
53
+ case none
54
+ case some(T)
55
+ }
56
+
46
57
class OptionalBox<T> {
47
- var t: T?
58
+ var t: FakeOptional<T>
48
59
}
49
60
50
61
// CHECK-NOT: Function: 'inject_enum_addr_test'
51
62
sil [ossa] @inject_enum_addr_test : $@convention(thin) <T> (@owned OptionalBox<T>) -> () {
52
63
bb0(%0 : @owned $OptionalBox<T>):
53
64
%1 = begin_borrow %0 : $OptionalBox<T>
54
65
%2 = ref_element_addr %1 : $OptionalBox<T>, #OptionalBox.t
55
- inject_enum_addr %2 : $*Optional <T>, #Optional .none!enumelt
66
+ inject_enum_addr %2 : $*FakeOptional <T>, #FakeOptional .none!enumelt
56
67
end_borrow %1 : $OptionalBox<T>
57
68
destroy_value %0 : $OptionalBox<T>
58
69
%3 = tuple ()
@@ -64,7 +75,7 @@ sil [ossa] @init_enum_data_addr_test : $@convention(thin) <T> (@owned OptionalBo
64
75
bb0(%0 : @owned $OptionalBox<T>, %1 : $*T):
65
76
%2 = begin_borrow %0 : $OptionalBox<T>
66
77
%3 = ref_element_addr %2 : $OptionalBox<T>, #OptionalBox.t
67
- %4 = init_enum_data_addr %3 : $*Optional <T>, #Optional .some!enumelt
78
+ %4 = init_enum_data_addr %3 : $*FakeOptional <T>, #FakeOptional .some!enumelt
68
79
copy_addr %1 to [initialization] %4 : $*T
69
80
end_borrow %2 : $OptionalBox<T>
70
81
destroy_value %0 : $OptionalBox<T>
@@ -76,6 +87,10 @@ class Box<T> {
76
87
var t: T
77
88
}
78
89
90
+ struct Int {
91
+ var _value: Builtin.Int64
92
+ }
93
+
79
94
// CHECK-NOT: Function: 'unconditional_cast_test'
80
95
sil [ossa] @unconditional_cast_test : $@convention(thin) <T> (@owned Box<T>, @in Int) -> () {
81
96
bb0(%0 : @owned $Box<T>, %1 : $*Int):
@@ -86,4 +101,60 @@ bb0(%0 : @owned $Box<T>, %1 : $*Int):
86
101
destroy_value %0 : $Box<T>
87
102
%4 = tuple ()
88
103
return %4 : $()
89
- }
104
+ }
105
+
106
+ // CHECK-LABEL: Error#: 0. Begin Error in Function: 'store_borrow_result_used_outside_of_borrow_lifetime'
107
+ // CHECK-NEXT: Found outside of lifetime use?!
108
+ // CHECK-NEXT: Value: %1 = begin_borrow %0 : $Builtin.NativeObject // users: %4, %3
109
+ // CHECK-NEXT: Consuming User: end_borrow %1 : $Builtin.NativeObject // id: %4
110
+ // CHECK-NEXT: Non Consuming User: %7 = apply %6(%3) : $@convention(thin) (@in_guaranteed Builtin.NativeObject) -> ()
111
+ // CHECK-NEXT: Block: bb0
112
+ sil [ossa] @store_borrow_result_used_outside_of_borrow_lifetime : $@convention(thin) (@owned Builtin.NativeObject) -> () {
113
+ bb0(%0 : @owned $Builtin.NativeObject):
114
+ %0a = begin_borrow %0 : $Builtin.NativeObject
115
+ %1 = alloc_stack $Builtin.NativeObject
116
+ %result = store_borrow %0a to %1 : $*Builtin.NativeObject
117
+ end_borrow %0a : $Builtin.NativeObject
118
+ destroy_value %0 : $Builtin.NativeObject
119
+ %func = function_ref @use_builtinnativeobject_inguaranteed : $@convention(thin) (@in_guaranteed Builtin.NativeObject) -> ()
120
+ apply %func(%result) : $@convention(thin) (@in_guaranteed Builtin.NativeObject) -> ()
121
+ dealloc_stack %1 : $*Builtin.NativeObject
122
+ %9999 = tuple()
123
+ return %9999 : $()
124
+ }
125
+
126
+ // CHECK-LABEL: Error#: 0. Begin Error in Function: 'recursive_interior_pointer_error'
127
+ // CHECK-NEXT: Found outside of lifetime use?!
128
+ // CHECK-NEXT: Value: %2 = begin_borrow %0 : $KlassUser // users: %5, %3
129
+ // CHECK-NEXT: Consuming User: end_borrow %2 : $KlassUser // id: %5
130
+ // CHECK-NEXT: Non Consuming User: %7 = load [copy] %4 : $*Klass // user: %8
131
+ // CHECK-NEXT: Block: bb0
132
+ // CHECK: Error#: 0. End Error in Function: 'recursive_interior_pointer_error'
133
+ sil [ossa] @recursive_interior_pointer_error : $@convention(thin) (@owned KlassUser, @guaranteed Klass) -> @owned Klass {
134
+ bb0(%0 : @owned $KlassUser, %0a : @guaranteed $Klass):
135
+ %1 = begin_borrow %0 : $KlassUser
136
+ %2 = ref_tail_addr %1 : $KlassUser, $Klass
137
+ %result = store_borrow %0a to %2 : $*Klass
138
+ end_borrow %1 : $KlassUser
139
+ destroy_value %0 : $KlassUser
140
+ %3 = load [copy] %result : $*Klass
141
+ return %3 : $Klass
142
+ }
143
+
144
+ // CHECK-LABEL: Error#: 0. Begin Error in Function: 'open_existential_box_interior_pointer_error'
145
+ // CHECK-NEXT: Found outside of lifetime use?!
146
+ // CHECK-NEXT: Value: %1 = begin_borrow %0 : $Error // users: %3, %2
147
+ // CHECK-NEXT: Consuming User: end_borrow %1 : $Error // id: %3
148
+ // CHECK-NEXT: Non Consuming User: %6 = apply %5<@opened("01234567-89AB-CDEF-0123-000000000000") Error>(%2) : $@convention(witness_method: Error) <τ_0_0 where τ_0_0 : Error> (@in_guaranteed τ_0_0) -> Int // type-defs: %2; user: %7
149
+ // CHECK-NEXT: Block: bb0
150
+ // CHECK: Error#: 0. End Error in Function: 'open_existential_box_interior_pointer_error'
151
+ sil [ossa] @open_existential_box_interior_pointer_error : $@convention(thin) (@owned Error) -> Int {
152
+ bb0(%0 : @owned $Error):
153
+ %1 = begin_borrow %0 : $Error
154
+ %2 = open_existential_box %1 : $Error to $*@opened("01234567-89AB-CDEF-0123-000000000000") Error
155
+ end_borrow %1 : $Error
156
+ destroy_value %0 : $Error
157
+ %m = witness_method $@opened("01234567-89AB-CDEF-0123-000000000000") Error, #Error._code!getter, %2 : $*@opened("01234567-89AB-CDEF-0123-000000000000") Error : $@convention(witness_method: Error) <Self: Error> (@in_guaranteed Self) -> Int
158
+ %result = apply %m<@opened("01234567-89AB-CDEF-0123-000000000000") Error>(%2) : $@convention(witness_method: Error) <Self: Error> (@in_guaranteed Self) -> Int
159
+ return %result : $Int
160
+ }
0 commit comments