mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
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:
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
21
test/SILOptimizer/simplify_keypath_resilient.swift
Normal file
21
test/SILOptimizer/simplify_keypath_resilient.swift
Normal 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]
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user