Files
swift-mirror/test/SILOptimizer/deadend-loop-crash.swift
Erik Eckstein c0017a2701 DeadCodeElimination: don't insert destroys for removed values in dead-end blocks
When an owned value has no lifetime ending uses it means that it is in a dead-end region.
We must not remove and inserting compensating destroys for it because that would potentially destroy the value too early.
Initialization of an object might be cut off and removed after a dead-end loop or an `unreachable`.
In this case a class destructor would see uninitialized fields.

Fixes a mis-compile
https://github.com/swiftlang/swift/issues/85851
rdar://165876726
2025-12-05 17:08:51 +01:00

36 lines
547 B
Swift

// RUN: %target-run-simple-swift(-O -Xllvm -sil-disable-pass=deadobject-elim) | %FileCheck %s
// REQUIRES: executable_test
#if canImport(Darwin)
import Darwin
#elseif canImport(Glibc)
import Glibc
#elseif os(WASI)
import WASILibc
#elseif canImport(Android)
import Android
#elseif os(Windows)
import CRT
#else
#error("Unsupported platform")
#endif
@inline(never)
public func hiddenExit() {
// CHECK: okay
print("okay")
exit(0)
}
func foo() -> Never {
while true {
hiddenExit()
}
}
func bar(_ x: Any...) {
}
bar(foo())