Merge pull request #85959 from jckarter/borrow-accessor-address-only-non-escapable

SIL: Handle address ReturnInsts from borrow accessors as yielding uses.
This commit is contained in:
Joe Groff
2025-12-11 09:43:27 -08:00
committed by GitHub
2 changed files with 34 additions and 1 deletions

View File

@@ -139,7 +139,12 @@ extension AddressUseVisitor {
let svi = operand.instruction as! SingleValueInstruction
return loadedAddressUse(of: operand, intoValue: svi)
case is YieldInst:
case is YieldInst,
// Return should only occur in a borrow or inout accessor, in which case the
// returned address should be structurally used as if it were a projected
// use in the caller, even though there is no code here in the callee to
// formally end the access.
is ReturnInst:
return yieldedAddressUse(of: operand)
case let sdai as SourceDestAddrInstruction

View File

@@ -0,0 +1,28 @@
// RUN: %target-swift-emit-sil -enable-experimental-feature Lifetimes -enable-experimental-feature BorrowAndMutateAccessors -verify %s
// REQUIRES: swift_feature_Lifetimes
// REQUIRES: swift_feature_BorrowAndMutateAccessors
struct Butt<T: ~Escapable>: ~Escapable {
var x: T
var xx: T {
@_lifetime(copy self)
borrow {
return x
}
}
}
struct Tubb<T>: ~Escapable {
var x: T
@_lifetime(immortal)
init() { fatalError() }
var xx: T {
borrow {
return x
}
}
}