Skip to content

Commit 479b5b9

Browse files
committed
[ownership] Add an interior_pointer error test for open_existential_box.
I didn't find one in the file, so I added it.
1 parent 27cd40b commit 479b5b9

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

test/SIL/ownership-verifier/interior_pointer.sil

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
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
22
// REQUIRES: asserts
33

44
sil_stage canonical
@@ -11,6 +11,10 @@ class KlassUser {
1111
var field: Klass
1212
}
1313

14+
protocol Error {
15+
var _code: Int { get }
16+
}
17+
1418
sil @use_builtinnativeobject_inguaranteed : $@convention(thin) (@in_guaranteed Builtin.NativeObject) -> ()
1519

1620
// CHECK-LABEL: Function: 'simple_error_ref_element_addr'
@@ -136,3 +140,21 @@ bb0(%0 : @owned $KlassUser, %0a : @guaranteed $Klass):
136140
%3 = load [copy] %result : $*Klass
137141
return %3 : $Klass
138142
}
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

Comments
 (0)