Skip to content

Commit f9fcd88

Browse files
authored
Merge pull request #85959 from jckarter/borrow-accessor-address-only-non-escapable
SIL: Handle address ReturnInsts from borrow accessors as yielding uses.
2 parents 3b99b43 + 79225fa commit f9fcd88

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

SwiftCompilerSources/Sources/Optimizer/Utilities/AddressUtils.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,12 @@ extension AddressUseVisitor {
139139
let svi = operand.instruction as! SingleValueInstruction
140140
return loadedAddressUse(of: operand, intoValue: svi)
141141

142-
case is YieldInst:
142+
case is YieldInst,
143+
// Return should only occur in a borrow or inout accessor, in which case the
144+
// returned address should be structurally used as if it were a projected
145+
// use in the caller, even though there is no code here in the callee to
146+
// formally end the access.
147+
is ReturnInst:
143148
return yieldedAddressUse(of: operand)
144149

145150
case let sdai as SourceDestAddrInstruction
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// RUN: %target-swift-emit-sil -enable-experimental-feature Lifetimes -enable-experimental-feature BorrowAndMutateAccessors -verify %s
2+
3+
// REQUIRES: swift_feature_Lifetimes
4+
// REQUIRES: swift_feature_BorrowAndMutateAccessors
5+
6+
struct Butt<T: ~Escapable>: ~Escapable {
7+
var x: T
8+
9+
var xx: T {
10+
@_lifetime(copy self)
11+
borrow {
12+
return x
13+
}
14+
}
15+
}
16+
17+
struct Tubb<T>: ~Escapable {
18+
var x: T
19+
20+
@_lifetime(immortal)
21+
init() { fatalError() }
22+
23+
var xx: T {
24+
borrow {
25+
return x
26+
}
27+
}
28+
}

0 commit comments

Comments
 (0)