Skip to content

Commit c4a2200

Browse files
committed
Fix lifetime_dependence_borrow_fail diagnostic.
Report the correct variable name.
1 parent 05c501a commit c4a2200

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

SwiftCompilerSources/Sources/Optimizer/Utilities/LifetimeDependenceUtils.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -597,6 +597,11 @@ struct VariableIntroducerUseDefWalker : LifetimeDependenceUseDefWalker {
597597
if let inst = value.definingInstruction, VariableScopeInstruction(inst) != nil {
598598
return introducer(value, owner)
599599
}
600+
// Finding a variable introducer requires following the mark_dependence forwarded value, not the base value like the
601+
// default LifetimeDependenceUseDefWalker.
602+
if value is MarkDependenceInst {
603+
return walkUpDefault(forwarded: value, owner)
604+
}
600605
return walkUpDefault(dependent: value, owner: owner)
601606
}
602607

test/SILOptimizer/lifetime_dependence/lifetime_dependence_borrow_fail.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,11 @@ func bv_incorrect_annotation2(_ w1: borrowing Wrapper, _ w2: borrowing Wrapper)
7777
} // expected-note @-1{{this use causes the lifetime-dependent value to escape}}
7878

7979
let ptr = UnsafeRawPointer(bitPattern: 1)!
80-
let nc = NC(ptr, 0) // expected-error {{lifetime-dependent variable 'nc' escapes its scope}}
80+
let nc = NC(ptr, 0)
8181

8282
func bv_global(dummy: BV) -> BV {
83-
nc.getBV()
83+
nc.getBV() // expected-error {{lifetime-dependent value escapes its scope}}
84+
// expected-note @-4{{it depends on the lifetime of variable 'nc'}}
8485
} // expected-note {{this use causes the lifetime-dependent value to escape}}
8586

8687
func testEmpty(nc: consuming NC) {

0 commit comments

Comments
 (0)