@@ -33,6 +33,10 @@ public struct Holder {
33
33
var c: C
34
34
}
35
35
36
+ public struct TrivialHolder {
37
+ var p: Builtin.RawPointer
38
+ }
39
+
36
40
struct A {}
37
41
38
42
struct NCWrapper : ~Copyable, ~Escapable {
@@ -44,7 +48,13 @@ sil @getNEPointer : $@convention(thin) (@guaranteed NE) -> Builtin.RawPointer
44
48
sil @useA : $@convention(thin) (A) -> ()
45
49
sil @makeNE : $@convention(thin) () -> @lifetime(immortal) @owned NE
46
50
sil @makeNEObject : $@convention(thin) () -> @lifetime(immortal) @owned NEObject
47
- sil @useNE : $@convention(thin) (NE) -> ()
51
+ sil @useNE : $@convention(thin) (@guaranteed NE) -> ()
52
+
53
+ sil @initHolder : $@convention(thin) () -> @out Holder
54
+ sil @getNE : $@convention(thin) (@in_guaranteed Holder) -> @lifetime(borrow address_for_deps 0) @owned NE
55
+
56
+ sil @initTrivialHolder : $@convention(thin) () -> @out TrivialHolder
57
+ sil @getTrivialNE : $@convention(thin) (@in_guaranteed TrivialHolder) -> @lifetime(borrow address_for_deps 0) @owned NE
48
58
49
59
// Test returning a owned dependence on a trivial value
50
60
sil [ossa] @return_trivial_dependence : $@convention(thin) (@guaranteed C) -> @lifetime(borrow 0) @owned NE {
@@ -80,8 +90,8 @@ bb0(%0 : @owned $Holder):
80
90
%c1 = apply %f1() : $@convention(thin) () -> @lifetime(immortal) @owned NE
81
91
%md = mark_dependence [unresolved] %c1 on %sb
82
92
%mv = move_value [var_decl] %md
83
- %f2 = function_ref @useNE : $@convention(thin) (NE) -> ()
84
- %c2 = apply %f2(%mv) : $@convention(thin) (NE) -> ()
93
+ %f2 = function_ref @useNE : $@convention(thin) (@guaranteed NE) -> ()
94
+ %c2 = apply %f2(%mv) : $@convention(thin) (@guaranteed NE) -> ()
85
95
destroy_value %mv
86
96
end_borrow %sb
87
97
dealloc_stack %stk
@@ -115,3 +125,41 @@ bb0(%0 : @owned $NCWrapper):
115
125
%17 = tuple ()
116
126
return %17
117
127
}
128
+
129
+ // Test that LifetimeDependence.Scope recognizes a singly-initialized alloc_stack.
130
+ sil [ossa] @testStackInit : $@convention(thin) () -> () {
131
+ bb0:
132
+ %0 = alloc_stack [lexical] [var_decl] $Holder, let, name "v"
133
+ %1 = function_ref @initHolder : $@convention(thin) () -> @out Holder
134
+ %2 = apply %1(%0) : $@convention(thin) () -> @out Holder
135
+ %3 = function_ref @getNE : $@convention(thin) (@in_guaranteed Holder) -> @lifetime(borrow address_for_deps 0) @owned NE
136
+ %4 = apply %3(%0) : $@convention(thin) (@in_guaranteed Holder) -> @lifetime(borrow address_for_deps 0) @owned NE
137
+ %5 = mark_dependence [unresolved] %4 on %0
138
+ %6 = move_value [var_decl] %5
139
+ %7 = function_ref @useNE : $@convention(thin) (@guaranteed NE) -> ()
140
+ %8 = apply %7(%6) : $@convention(thin) (@guaranteed NE) -> ()
141
+ destroy_value %6
142
+ destroy_addr %0
143
+ dealloc_stack %0
144
+ %12 = tuple ()
145
+ return %12
146
+ }
147
+
148
+ // Test that LifetimeDependence.Scope.computeRange handles a singly-initialized alloc_stack of trivial type by treating
149
+ // it as available for the entire function
150
+ sil [ossa] @testTrivialStackInit : $@convention(thin) () -> () {
151
+ bb0:
152
+ %0 = alloc_stack [lexical] [var_decl] $TrivialHolder, let, name "v"
153
+ %1 = function_ref @initTrivialHolder : $@convention(thin) () -> @out TrivialHolder
154
+ %2 = apply %1(%0) : $@convention(thin) () -> @out TrivialHolder
155
+ %3 = function_ref @getTrivialNE : $@convention(thin) (@in_guaranteed TrivialHolder) -> @lifetime(borrow 0) @owned NE
156
+ %4 = apply %3(%0) : $@convention(thin) (@in_guaranteed TrivialHolder) -> @lifetime(borrow 0) @owned NE
157
+ %5 = mark_dependence [unresolved] %4 on %0
158
+ dealloc_stack %0
159
+ %6 = move_value [var_decl] %5
160
+ %7 = function_ref @useNE : $@convention(thin) (@guaranteed NE) -> ()
161
+ %8 = apply %7(%6) : $@convention(thin) (@guaranteed NE) -> ()
162
+ destroy_value %6
163
+ %12 = tuple ()
164
+ return %12
165
+ }
0 commit comments