Merge pull request #79314 from eeckstein/fix-simplify-keypath

SimplifyKeyPath: insert the correct destroy operation for an operand of a removed keypath
This commit is contained in:
eeckstein
2025-02-12 15:18:39 +01:00
committed by GitHub
2 changed files with 26 additions and 1 deletions

View File

@@ -19,7 +19,11 @@ extension KeyPathInst : OnoneSimplifiable {
let builder = Builder(after: self, context)
for operand in self.operands {
if !operand.value.type.isTrivial(in: parentFunction) {
builder.createDestroyValue(operand: operand.value)
if operand.value.type.isAddress {
builder.createDestroyAddr(address: operand.value)
} else {
builder.createDestroyValue(operand: operand.value)
}
}
}
}

View File

@@ -0,0 +1,21 @@
// RUN: %target-swift-frontend -primary-file %s -enable-library-evolution -emit-sil | %FileCheck %s
public enum E: Hashable {
case e
}
public struct S {
public var dict: [E: Int] = [:]
}
// Check that the keypath simplification does not crash when inserting a compensating destroy.
// CHECK-LABEL: sil @$s26simplify_keypath_resilient6testityyF :
// CHECK-NOT: keypath
// CHECK: } // end sil function '$s26simplify_keypath_resilient6testityyF'
@inlinable
public func testit() {
let _ = \S.dict[.e]
}