EscapeUtils: consider that a begin_apply can yield it's indirect arguments

This is the only apply instruction where address arguments actually can "escape"
This commit is contained in:
Erik Eckstein
2023-02-13 15:52:02 +01:00
parent 113e23df03
commit d602836a26
2 changed files with 36 additions and 1 deletions

View File

@@ -547,7 +547,9 @@ fileprivate struct EscapeWalker<V: EscapeVisitor> : ValueDefUseWalker,
}
// Indirect arguments cannot escape the function, but loaded values from such can.
if !followLoads(at: path.projectionPath) {
if !followLoads(at: path.projectionPath) &&
// Except for begin_apply: it can yield an address value.
!apply.isBeginApplyWithIndirectResults {
return .continueWalk
}
@@ -824,3 +826,13 @@ private extension SmallProjectionPath {
EscapeUtilityTypes.EscapePath(projectionPath: self, followStores: false, knownType: nil)
}
}
private extension ApplySite {
var isBeginApplyWithIndirectResults: Bool {
guard let ba = self as? BeginApplyInst else {
return false
}
// Note that the token result is always a non-address type.
return ba.results.contains { $0.type.isAddress }
}
}