Files
swift-mirror/test/SILOptimizer/stack_promotion_crash.swift
Erik Eckstein 1d0eacc4be SIL: fix handling of non-constant address indices in SmallProjectionPath
When trying to pop a specific element from a SmallProjectionPath, skip `index_addr` with a non-constant index, because the index could be 0.
Otherwise `pop` would return nil which lets escape analysis think that there is no match and no escape.

Fixes a mis-compile caused by invalid escape analysis.

https://github.com/swiftlang/swift/issues/89178
rdar://177183914
2026-06-01 12:39:03 +02:00

50 lines
787 B
Swift

// RUN: %empty-directory(%t)
// RUN: %target-build-swift -O %s -o %t/a.out
// RUN: %target-codesign %t/a.out
// RUN: %target-run %t/a.out | %FileCheck %s
// REQUIRES: executable_test
// Check that the compiled code does not crash because of a wrong
// stack-promoted array.
// End-to-end test for https://github.com/apple/swift/issues/52844.
public struct Beta {
var gamma: [Int]
}
class Delta {
var epsilon: Beta? = Beta(gamma: [])
func main() {
for _ in 1...100 {
crash()
}
}
func crash() {
epsilon?.gamma = [0]
}
}
func testit() {
Delta().main()
}
protocol P {}
final class C: P {}
@inline(never)
func test2() -> [P] {
let a: [AnyObject?] = [ C(), C(), ]
return a.compactMap { $0 as? P }
}
testit()
test2()
// CHECK: ok
print("ok")