Skip to content

Commit c891d8a

Browse files
committed
LifetimeDependenceDiagnostics: avoid infinite recursion on error
Fix a simple typo that results in infinite recursion on invalid code. Fixes rdar://147470493 ([nonescapable] LifetimeDependenceInsertion: infinite recursion in VariableUseDefWalker.walkup with immortal setter)
1 parent 36551e3 commit c891d8a

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

SwiftCompilerSources/Sources/Optimizer/Utilities/LifetimeDependenceUtils.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1285,7 +1285,7 @@ extension LifetimeDependenceUseDefAddressWalker {
12851285
case let store as StoringInstruction:
12861286
return walkUp(newLifetime: store.source)
12871287
case let srcDestInst as SourceDestAddrInstruction:
1288-
return walkUp(newLifetime: srcDestInst.destination)
1288+
return walkUp(newLifetime: srcDestInst.source)
12891289
case let apply as FullApplySite:
12901290
if let f = apply.referencedFunction, f.isConvertPointerToPointerArgument {
12911291
return walkUp(newLifetime: apply.parameterOperands[0].value)

test/SILOptimizer/lifetime_dependence/verify_diagnostics.sil

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ sil @reborrowNE : $@convention(thin) (@guaranteed NE) -> @lifetime(borrow 0) @ow
5353

5454
sil @initHolder : $@convention(thin) () -> @out Holder
5555
sil @getNE : $@convention(thin) (@in_guaranteed Holder) -> @lifetime(borrow address_for_deps 0) @owned NE
56+
sil @getNEIndirect : $@convention(thin) (@in_guaranteed Holder) -> @lifetime(borrow address_for_deps 0) @out NE
5657

5758
sil @initTrivialHolder : $@convention(thin) () -> @out TrivialHolder
5859
sil @getTrivialNE : $@convention(thin) (@in_guaranteed TrivialHolder) -> @lifetime(borrow address_for_deps 0) @owned NE
@@ -218,3 +219,27 @@ bb0(%0 : $*T, %1 : $@thick T.Type):
218219
%21 = tuple ()
219220
return %21
220221
}
222+
223+
// Test VariableDefUseWalker: initialization with copy_addr.
224+
sil shared [thunk] [ossa] @testCopyInit : $@convention(thin) (@in_guaranteed Holder) -> @out NE {
225+
bb0(%0 : $*NE, %1 : $*Holder):
226+
%2 = alloc_stack $Holder
227+
copy_addr %1 to [init] %2
228+
%4 = load [take] %2
229+
%5 = alloc_stack $Holder
230+
%6 = store_borrow %4 to %5
231+
%7 = alloc_stack $NE // expected-error {{lifetime-dependent value escapes its scope}}
232+
233+
%8 = function_ref @getNEIndirect : $@convention(thin) (@in_guaranteed Holder) -> @lifetime(borrow address_for_deps 0) @out NE
234+
%9 = apply %8(%7, %6) : $@convention(thin) (@in_guaranteed Holder) -> @lifetime(borrow address_for_deps 0) @out NE
235+
mark_dependence_addr [unresolved] %7 on %6
236+
%11 = load [take] %7
237+
store %11 to [init] %0 // expected-note {{this use causes the lifetime-dependent value to escape}}
238+
end_borrow %6
239+
dealloc_stack %7
240+
dealloc_stack %5
241+
destroy_value %4
242+
dealloc_stack %2
243+
%18 = tuple ()
244+
return %18
245+
}

0 commit comments

Comments
 (0)