Skip to content

Commit 8200a87

Browse files
committed
Fix LifetimeDependenceDefUseWalker to follow inout dependence
Fixes rdar://157796728 ([nonescapable] [miscompile] No diagnostic error when an inout MutableSpan is reassigned to a different lifetime source)
1 parent 77ee27a commit 8200a87

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

SwiftCompilerSources/Sources/Optimizer/Utilities/LifetimeDependenceUtils.swift

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1121,15 +1121,28 @@ extension LifetimeDependenceDefUseWalker {
11211121
if apply.isCallee(operand: operand) {
11221122
return leafUse(of: operand)
11231123
}
1124+
// Find any copied dependence on this source operand, either targeting the result or an inout parameter. If the
1125+
// lifetime dependence is scoped, then we can ignore it because a mark_dependence [nonescaping] represents the
1126+
// dependence.
1127+
for targetOperand in apply.argumentOperands {
1128+
guard !targetOperand.value.isEscapable else {
1129+
continue
1130+
}
1131+
if let dep = apply.parameterDependence(target: targetOperand, source: operand),
1132+
!dep.isScoped {
1133+
let targetAddress = targetOperand.value
1134+
assert(targetAddress.type.isAddress, "a parameter dependence target must be 'inout'")
1135+
if dependentUse(of: operand, dependentAddress: targetAddress) == .abortWalk {
1136+
return .abortWalk
1137+
}
1138+
}
1139+
}
11241140
if let dep = apply.resultDependence(on: operand),
11251141
!dep.isScoped {
11261142
// Operand is nonescapable and passed as a call argument. If the
11271143
// result inherits its lifetime, then consider any nonescapable
11281144
// result value to be a dependent use.
11291145
//
1130-
// If the lifetime dependence is scoped, then we can ignore it
1131-
// because a mark_dependence [nonescaping] represents the
1132-
// dependence.
11331146
if let result = apply.singleDirectResult, !result.isEscapable {
11341147
if dependentUse(of: operand, dependentValue: result) == .abortWalk {
11351148
return .abortWalk

0 commit comments

Comments
 (0)