Skip to content

Commit f113eaa

Browse files
authored
Merge pull request #70438 from meg-gupta/fixkeypathsilcombine
Invalidate stack nesting in keypath silcombine
2 parents 6783efd + 367b5fe commit f113eaa

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

lib/SILOptimizer/SILCombiner/SILCombinerApplyVisitors.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -600,6 +600,8 @@ bool SILCombiner::tryOptimizeInoutKeypath(BeginApplyInst *AI) {
600600
Builder.setInsertionPoint(endApply);
601601
});
602602

603+
invalidatedStackNesting = true;
604+
603605
eraseInstFromFunction(*endApply);
604606
eraseInstFromFunction(*AI);
605607
++NumOptimizedKeypaths;
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// RUN: %target-swift-frontend -emit-sil -O -enable-ossa-modules -sil-verify-all %s
2+
// REQUIRES: OS=macosx
3+
4+
import Foundation
5+
6+
// Check the following test does not crash with incorrect stack order
7+
open class DateFormatter {
8+
typealias CFType = CFDateFormatter
9+
open func copy(with zone: NSZone? = nil) -> Any {
10+
let copied = DateFormatter()
11+
12+
func __copy<T>(_ keyPath: ReferenceWritableKeyPath<DateFormatter, T>) {
13+
copied[keyPath: keyPath] = self[keyPath: keyPath]
14+
}
15+
16+
__copy(\.formattingContext)
17+
return copied
18+
}
19+
20+
public enum Context : Int {
21+
case unknown
22+
case dynamic
23+
case standalone
24+
case listItem
25+
case beginningOfSentence
26+
case middleOfSentence
27+
}
28+
open var formattingContext: Context = .unknown
29+
}
30+

0 commit comments

Comments
 (0)