Skip to content

Commit 934aad8

Browse files
authored
Merge pull request #82408 from atrick/fix-immortal
Fix lifetime dependence diagnostics on Void types.
2 parents c238840 + 36d2b5b commit 934aad8

File tree

3 files changed

+25
-3
lines changed

3 files changed

+25
-3
lines changed

SwiftCompilerSources/Sources/Optimizer/FunctionPasses/LifetimeDependenceDiagnostics.swift

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,9 +199,16 @@ private struct DiagnoseDependence {
199199
if function.hasUnsafeNonEscapableResult {
200200
return .continueWalk
201201
}
202-
// If the dependence scope is global, then it has immortal lifetime.
203-
if case .global = dependence.scope {
202+
// Check for immortal lifetime.
203+
switch dependence.scope {
204+
case .global:
204205
return .continueWalk
206+
case let .unknown(value):
207+
if value.type.isVoid {
208+
return .continueWalk
209+
}
210+
default:
211+
break
205212
}
206213
// Check that the parameter dependence for this result is the same
207214
// as the current dependence scope.

SwiftCompilerSources/Sources/Optimizer/Utilities/ForwardingUtils.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ extension ForwardingUseDefWalker {
118118
}
119119
mutating func walkUpDefault(forwarded value: Value, _ path: PathContext)
120120
-> WalkResult {
121-
if let inst = value.forwardingInstruction {
121+
if let inst = value.forwardingInstruction, !inst.forwardedOperands.isEmpty {
122122
return walkUp(instruction: inst, path)
123123
}
124124
if let phi = Phi(value) {

test/SILOptimizer/lifetime_dependence/verify_diagnostics.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,11 @@ public struct NEInt: ~Escapable {
106106
init(owner: borrowing NCInt) {
107107
self.i = owner.i
108108
}
109+
110+
@_lifetime(immortal)
111+
init(immortal i: Int) {
112+
self.i = i
113+
}
109114
}
110115

111116
struct TestDeinitCallsAddressor: ~Copyable, ~Escapable {
@@ -228,3 +233,13 @@ class ClassStorage {
228233
_ = ne
229234
}
230235
}
236+
237+
// =============================================================================
238+
// Immortal
239+
// =============================================================================
240+
241+
@_lifetime(immortal)
242+
func testVoid() -> NEInt {
243+
let ne = NEInt(immortal: 3)
244+
return _overrideLifetime(ne, borrowing: ())
245+
}

0 commit comments

Comments
 (0)