mirror of
https://github.com/apple/swift.git
synced 2026-06-20 15:42:51 +02:00
47 lines
1.4 KiB
Swift
47 lines
1.4 KiB
Swift
// RUN: %target-swift-frontend %s -module-name=test -emit-assembly \
|
|
// RUN: -enable-throws-prediction -O -enable-split-cold-code \
|
|
// RUN: | %FileCheck --check-prefix CHECK-ENABLED %s
|
|
|
|
//// Test disabling just the pass doesn't yield a split.
|
|
// RUN: %target-swift-frontend %s -module-name=test -emit-assembly \
|
|
// RUN: -enable-throws-prediction -O -disable-split-cold-code \
|
|
// RUN: | %FileCheck --check-prefix CHECK-DISABLED %s
|
|
|
|
//// Test using -Osize doesn't yield a split.
|
|
// RUN: %target-swift-frontend %s -module-name=test -emit-assembly \
|
|
// RUN: -enable-throws-prediction -Osize -enable-split-cold-code \
|
|
// RUN: | %FileCheck --check-prefix CHECK-DISABLED %s
|
|
|
|
//// Test disabling optimization entirely doesn't yield a split.
|
|
// RUN: %target-swift-frontend %s -module-name=test -emit-assembly \
|
|
// RUN: -enable-throws-prediction -enable-split-cold-code \
|
|
// RUN: | %FileCheck --check-prefix CHECK-DISABLED %s
|
|
|
|
|
|
// CHECK-ENABLED: .cold
|
|
|
|
// CHECK-DISABLED-NOT: .cold
|
|
|
|
enum MyError: Error { case err }
|
|
|
|
func reportError() -> Never {
|
|
fatalError()
|
|
}
|
|
|
|
func getRandom(_ b: Bool) throws -> Int {
|
|
if b {
|
|
return Int.random(in: 0..<1024)
|
|
} else {
|
|
throw MyError.err
|
|
}
|
|
}
|
|
|
|
public func numberWithLogging(_ b: Bool) -> Int {
|
|
do {
|
|
return try getRandom(b)
|
|
} catch {
|
|
print("Log: random number generator failed with b=\(b)")
|
|
reportError()
|
|
}
|
|
}
|