diff --git a/SwiftCompilerSources/Sources/Optimizer/Utilities/LifetimeDependenceUtils.swift b/SwiftCompilerSources/Sources/Optimizer/Utilities/LifetimeDependenceUtils.swift index 41214f0ca46..fd14c264f01 100644 --- a/SwiftCompilerSources/Sources/Optimizer/Utilities/LifetimeDependenceUtils.swift +++ b/SwiftCompilerSources/Sources/Optimizer/Utilities/LifetimeDependenceUtils.swift @@ -597,6 +597,11 @@ struct VariableIntroducerUseDefWalker : LifetimeDependenceUseDefWalker { if let inst = value.definingInstruction, VariableScopeInstruction(inst) != nil { return introducer(value, owner) } + // Finding a variable introducer requires following the mark_dependence forwarded value, not the base value like the + // default LifetimeDependenceUseDefWalker. + if value is MarkDependenceInst { + return walkUpDefault(forwarded: value, owner) + } return walkUpDefault(dependent: value, owner: owner) } diff --git a/test/SILOptimizer/lifetime_dependence/lifetime_dependence_borrow_fail.swift b/test/SILOptimizer/lifetime_dependence/lifetime_dependence_borrow_fail.swift index 918f7eeedb2..350b0d63691 100644 --- a/test/SILOptimizer/lifetime_dependence/lifetime_dependence_borrow_fail.swift +++ b/test/SILOptimizer/lifetime_dependence/lifetime_dependence_borrow_fail.swift @@ -77,10 +77,11 @@ func bv_incorrect_annotation2(_ w1: borrowing Wrapper, _ w2: borrowing Wrapper) } // expected-note @-1{{this use causes the lifetime-dependent value to escape}} let ptr = UnsafeRawPointer(bitPattern: 1)! -let nc = NC(ptr, 0) // expected-error {{lifetime-dependent variable 'nc' escapes its scope}} +let nc = NC(ptr, 0) func bv_global(dummy: BV) -> BV { - nc.getBV() + nc.getBV() // expected-error {{lifetime-dependent value escapes its scope}} + // expected-note @-4{{it depends on the lifetime of variable 'nc'}} } // expected-note {{this use causes the lifetime-dependent value to escape}} func testEmpty(nc: consuming NC) {