mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Sometimes in SILGenPattern, we need use an indirect cast on object that does not require re-abstraction as an optimization. A notable case where this happens are various casts related to NSError. In such a case, if we have a borrowed cast operand, perform a copy before the store to preserve semantic sil invariants. rdar://31880847
22 lines
834 B
Swift
22 lines
834 B
Swift
// RUN: %target-swift-frontend -parse-stdlib -module-name Swift -parse-as-library -emit-silgen -enable-sil-ownership %s | %FileCheck %s
|
|
|
|
protocol Error {}
|
|
|
|
enum MyError : Error {
|
|
case case1
|
|
}
|
|
|
|
// CHECK: bb{{[0-9]+}}([[ERROR:%.*]] : @owned $Error):
|
|
// CHECK-NEXT: [[BORROWED_ERROR:%.*]] = begin_borrow [[ERROR]]
|
|
// CHECK-NEXT: [[ERROR_SLOT:%.*]] = alloc_stack $Error
|
|
// CHECK-NEXT: [[COPIED_BORROWED_ERROR:%.*]] = copy_value [[BORROWED_ERROR]]
|
|
// CHECK-NEXT: store [[COPIED_BORROWED_ERROR]] to [init] [[ERROR_SLOT]]
|
|
// CHECK-NEXT: [[ERROR_SLOT_CAST_RESULT:%.*]] = alloc_stack $MyError
|
|
// CHECK-NEXT: checked_cast_addr_br copy_on_success Error in [[ERROR_SLOT]] : $*Error to MyError in [[ERROR_SLOT_CAST_RESULT]] : $*MyError
|
|
func test1(f: () throws -> ()) throws {
|
|
do {
|
|
let _ = try f()
|
|
} catch MyError.case1 {
|
|
}
|
|
}
|