@@ -33,6 +33,10 @@ public struct Holder {
3333 var c: C
3434}
3535
36+ public struct TrivialHolder {
37+ var p: Builtin.RawPointer
38+ }
39+
3640struct A {}
3741
3842struct NCWrapper : ~Copyable, ~Escapable {
@@ -44,7 +48,13 @@ sil @getNEPointer : $@convention(thin) (@guaranteed NE) -> Builtin.RawPointer
4448sil @useA : $@convention(thin) (A) -> ()
4549sil @makeNE : $@convention(thin) () -> @lifetime(immortal) @owned NE
4650sil @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
4858
4959// Test returning a owned dependence on a trivial value
5060sil [ossa] @return_trivial_dependence : $@convention(thin) (@guaranteed C) -> @lifetime(borrow 0) @owned NE {
@@ -80,8 +90,8 @@ bb0(%0 : @owned $Holder):
8090 %c1 = apply %f1() : $@convention(thin) () -> @lifetime(immortal) @owned NE
8191 %md = mark_dependence [unresolved] %c1 on %sb
8292 %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) -> ()
8595 destroy_value %mv
8696 end_borrow %sb
8797 dealloc_stack %stk
@@ -115,3 +125,41 @@ bb0(%0 : @owned $NCWrapper):
115125 %17 = tuple ()
116126 return %17
117127}
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