Skip to content

Commit 60449d5

Browse files
committed
[ownership-verifier] Add two tests to ensure that the verifier accepts forwarded @owned aggregates.
I am going to add some negative tests in a forthcoming commit. I just wrote these locally and wanted to get them into tree. rdar://29791263
1 parent f462d20 commit 60449d5

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

test/SIL/ownership-verifier/use_verifier.sil

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ import Builtin
1313
// Declarations //
1414
//////////////////
1515

16+
enum Optional<T> {
17+
case some(T)
18+
case nome
19+
}
20+
1621
struct TrivialStruct {
1722
var f1: Builtin.Int32
1823
var f2: Builtin.Int32
@@ -23,6 +28,11 @@ struct NonTrivialStructWithTrivialField {
2328
var payload: Builtin.Int32
2429
}
2530

31+
struct TupleContainingNonTrivialStruct {
32+
var t: (Builtin.NativeObject, Builtin.NativeObject)
33+
var opt: Optional<Builtin.NativeObject>
34+
}
35+
2636
////////////////
2737
// Test Cases //
2838
////////////////
@@ -70,3 +80,24 @@ bb0(%0 : $Builtin.NativeObject):
7080
%9999 = tuple()
7181
return %9999 : $()
7282
}
83+
84+
/////////////////////
85+
// Aggregate Tests //
86+
/////////////////////
87+
88+
// These tests make sure that we properly handle @owned forwarding of multiple
89+
// levels of aggregate.
90+
91+
sil @owned_aggregates_simple : $@convention(thin) (@owned Builtin.NativeObject, @owned Builtin.NativeObject) -> (@owned (Builtin.NativeObject, Builtin.NativeObject)) {
92+
bb0(%0 : $Builtin.NativeObject, %1 : $Builtin.NativeObject):
93+
%2 = tuple(%0 : $Builtin.NativeObject, %1 : $Builtin.NativeObject)
94+
return %2 : $(Builtin.NativeObject, Builtin.NativeObject)
95+
}
96+
97+
sil @multiple_level_owned_aggregates : $@convention(thin) (@owned Builtin.NativeObject, @owned Builtin.NativeObject, @owned Builtin.NativeObject) -> (@owned TupleContainingNonTrivialStruct) {
98+
bb0(%0 : $Builtin.NativeObject, %1 : $Builtin.NativeObject, %2 : $Builtin.NativeObject):
99+
%3 = tuple(%0 : $Builtin.NativeObject, %1 : $Builtin.NativeObject)
100+
%4 = enum $Optional<Builtin.NativeObject>, #Optional.some!enumelt.1, %2 : $Builtin.NativeObject
101+
%5 = struct $TupleContainingNonTrivialStruct(%3 : $(Builtin.NativeObject, Builtin.NativeObject), %4 : $Optional<Builtin.NativeObject>)
102+
return %5 : $TupleContainingNonTrivialStruct
103+
}

0 commit comments

Comments
 (0)