Files
swift-mirror/test/SILGen/ivar_destroyer_objc.swift
Andrew Trick 5b37728f2a Fix OSSA in SILGenFunction::emitIVarDestroyer
It is illegal to borrow an unowned value. Unowned values are only
allowed to have specific instantaneous uses.

In this case, an unchecked conversion is valid because there is an
assumption that within a destructor, self is guaranteed.
2021-01-01 19:22:19 -08:00

19 lines
768 B
Swift

// RUN: %target-swift-emit-silgen(mock-sdk: %clang-importer-sdk) %s | %FileCheck %s
// REQUIRES: objc_interop
import Foundation
// CHECK-LABEL: sil hidden [ossa] @$s19ivar_destroyer_objc7ObjCFooCfETo : $@convention(objc_method) (ObjCFoo) -> () {
// CHECK: bb0(%0 : @unowned $ObjCFoo):
// CHECK: [[CONVERT:%.*]] = unchecked_ownership_conversion %0 : $ObjCFoo, @unowned to @guaranteed
// CHECK: ref_element_addr [[CONVERT]] : $ObjCFoo, #ObjCFoo.object
// CHECK: begin_access [deinit] [static]
// CHECK: destroy_addr
// CHECK: end_access
// CHECK: end_borrow [[CONVERT]] : $ObjCFoo
// CHECK-LABEL: } // end sil function '$s19ivar_destroyer_objc7ObjCFooCfETo'
internal class ObjCFoo : NSObject {
var object: AnyObject
init(o: AnyObject) { object = o }
}