From f69793cc5f9aee2a085021c3b27f2bd9ea3ceae5 Mon Sep 17 00:00:00 2001 From: Erik Eckstein Date: Thu, 22 May 2025 19:07:54 +0200 Subject: [PATCH] DeadStoreElimination: don't assume that the operand of an `dealloc_stack` is an `alloc_stack`. It can also be a `partial_apply`. Fixes a compiler crash https://github.com/swiftlang/swift/issues/81698 rdar://151822502 --- .../Optimizer/FunctionPasses/DeadStoreElimination.swift | 2 +- SwiftCompilerSources/Sources/SIL/Instruction.swift | 6 +----- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/SwiftCompilerSources/Sources/Optimizer/FunctionPasses/DeadStoreElimination.swift b/SwiftCompilerSources/Sources/Optimizer/FunctionPasses/DeadStoreElimination.swift index 26d765f47907f..43c798f6879e5 100644 --- a/SwiftCompilerSources/Sources/Optimizer/FunctionPasses/DeadStoreElimination.swift +++ b/SwiftCompilerSources/Sources/Optimizer/FunctionPasses/DeadStoreElimination.swift @@ -256,7 +256,7 @@ private extension Deallocation { private extension DeallocStackInst { func isStackDeallocation(of base: AccessBase) -> Bool { - if case .stack(let allocStack) = base, allocstack == allocStack { + if case .stack(let allocStack) = base, operand.value == allocStack { return true } return false diff --git a/SwiftCompilerSources/Sources/SIL/Instruction.swift b/SwiftCompilerSources/Sources/SIL/Instruction.swift index 9b4ccbd8b0a4d..e0f8749af38db 100644 --- a/SwiftCompilerSources/Sources/SIL/Instruction.swift +++ b/SwiftCompilerSources/Sources/SIL/Instruction.swift @@ -647,11 +647,7 @@ extension Deallocation { } -final public class DeallocStackInst : Instruction, UnaryInstruction, Deallocation { - public var allocstack: AllocStackInst { - return operand.value as! AllocStackInst - } -} +final public class DeallocStackInst : Instruction, UnaryInstruction, Deallocation {} final public class DeallocStackRefInst : Instruction, UnaryInstruction, Deallocation { public var allocRef: AllocRefInstBase { operand.value as! AllocRefInstBase }