Skip to content

Commit b6639e1

Browse files
authored
Merge pull request #79314 from eeckstein/fix-simplify-keypath
SimplifyKeyPath: insert the correct destroy operation for an operand of a removed keypath
2 parents e256e04 + 2962474 commit b6639e1

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

SwiftCompilerSources/Sources/Optimizer/InstructionSimplification/SimplifyKeyPath.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@ extension KeyPathInst : OnoneSimplifiable {
1919
let builder = Builder(after: self, context)
2020
for operand in self.operands {
2121
if !operand.value.type.isTrivial(in: parentFunction) {
22-
builder.createDestroyValue(operand: operand.value)
22+
if operand.value.type.isAddress {
23+
builder.createDestroyAddr(address: operand.value)
24+
} else {
25+
builder.createDestroyValue(operand: operand.value)
26+
}
2327
}
2428
}
2529
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// RUN: %target-swift-frontend -primary-file %s -enable-library-evolution -emit-sil | %FileCheck %s
2+
3+
public enum E: Hashable {
4+
case e
5+
}
6+
7+
public struct S {
8+
public var dict: [E: Int] = [:]
9+
}
10+
11+
// Check that the keypath simplification does not crash when inserting a compensating destroy.
12+
13+
// CHECK-LABEL: sil @$s26simplify_keypath_resilient6testityyF :
14+
// CHECK-NOT: keypath
15+
// CHECK: } // end sil function '$s26simplify_keypath_resilient6testityyF'
16+
@inlinable
17+
public func testit() {
18+
let _ = \S.dict[.e]
19+
}
20+
21+

0 commit comments

Comments
 (0)