mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
I also removed the -verify-sil-ownership flag in favor of a disable flag -disable-sil-ownership-verifier. I used this on only two tests that still need work to get them to pass with ownership, but whose problems are well understood, small corner cases. I am going to fix them in follow on commits. I detail them below: 1. SILOptimizer/definite_init_inout_super_init.swift. This is a test case where DI is supposed to error. The only problem is that we crash before we error since the code emitting by SILGen to trigger this error does not pass ownership invariants. I have spoken with JoeG about this and he suggested that I fix this earlier in the compiler. Since we do not run the ownership verifier without asserts enabled, this should not affect compiler users. Given that it has triggered DI errors previously I think it is safe to disable ownership here. 2. PrintAsObjC/extensions.swift. In this case, the signature generated by type lowering for one of the thunks here uses an unsafe +0 return value instead of doing an autorelease return. The ownership checker rightly flags this leak. This is going to require either an AST level change or a change to TypeLowering. I think it is safe to turn this off since it is such a corner case that it was found by a test that has nothing to do with it. rdar://43398898
137 lines
6.2 KiB
Plaintext
137 lines
6.2 KiB
Plaintext
// RUN: %empty-directory(%t)
|
|
// RUN: %build-irgen-test-overlays
|
|
// RUN: %target-swift-frontend(mock-sdk: -sdk %S/Inputs -I %t) %s -emit-ir | %FileCheck %s
|
|
|
|
// REQUIRES: CPU=x86_64
|
|
// REQUIRES: objc_interop
|
|
|
|
// CHECK: [[SGIZMO:%T12objc_dealloc10SwiftGizmoC]] = type
|
|
// CHECK: [[GIZMO:%TSo5GizmoC]] = type <{ %objc_class* }>
|
|
|
|
sil_stage raw
|
|
|
|
import Builtin
|
|
import Swift
|
|
import gizmo
|
|
|
|
class X { }
|
|
sil_vtable X {}
|
|
sil @$s12objc_dealloc1XCfD : $@convention(method) (X) -> ()
|
|
|
|
func onDestruct() { }
|
|
|
|
class SwiftGizmo : Gizmo {
|
|
var x : X
|
|
override init()
|
|
deinit
|
|
}
|
|
sil_vtable SwiftGizmo {}
|
|
sil @$s12objc_dealloc10SwiftGizmoCfD : $@convention(method) (SwiftGizmo) -> ()
|
|
|
|
sil @$s12objc_dealloc10onDestructyyF : $@convention(thin) () -> () {
|
|
bb0:
|
|
%0 = tuple ()
|
|
%1 = tuple () // user: %2
|
|
return %1 : $() // id: %2
|
|
}
|
|
|
|
sil [ossa] @$s12objc_dealloc10SwiftGizmoCfd : $@convention(thin) (@owned SwiftGizmo) -> @owned Builtin.NativeObject {
|
|
bb0(%0 : @owned $SwiftGizmo):
|
|
// function_ref objc_dealloc.onDestruct () -> ()
|
|
%1 = function_ref @$s12objc_dealloc10onDestructyyF : $@convention(thin) () -> () // user: %2
|
|
%2 = apply %1() : $@convention(thin) () -> ()
|
|
%3 = begin_borrow %0 : $SwiftGizmo
|
|
%4 = ref_element_addr %3 : $SwiftGizmo, #SwiftGizmo.x // user: %4
|
|
destroy_addr %4 : $*X // id: %4
|
|
end_borrow %3 : $SwiftGizmo
|
|
%5 = unchecked_ref_cast %0 : $SwiftGizmo to $Builtin.NativeObject // user: %6
|
|
return %5 : $Builtin.NativeObject // id: %6
|
|
}
|
|
|
|
sil [ossa] @$s12objc_dealloc10SwiftGizmoC1xAA1XCfgTo : $@convention(objc_method) (SwiftGizmo) -> @autoreleased X {
|
|
bb0(%0 : @unowned $SwiftGizmo):
|
|
%1 = begin_borrow %0 : $SwiftGizmo
|
|
%2 = ref_element_addr %1 : $SwiftGizmo, #SwiftGizmo.x // user: %2
|
|
%3 = load [copy] %2 : $*X // users: %4, %3
|
|
end_borrow %1 : $SwiftGizmo
|
|
return %3 : $X // id: %4
|
|
}
|
|
|
|
sil [ossa] @$s12objc_dealloc10SwiftGizmoC1xAA1XCfsTo : $@convention(objc_method) (X, SwiftGizmo) -> () {
|
|
bb0(%0 : @unowned $X, %1 : @unowned $SwiftGizmo):
|
|
%2 = copy_value %0 : $X
|
|
%3 = copy_value %1 : $SwiftGizmo
|
|
%4 = begin_borrow %3 : $SwiftGizmo
|
|
%5 = ref_element_addr %4 : $SwiftGizmo, #SwiftGizmo.x // user: %5
|
|
assign %2 to %5 : $*X // id: %5
|
|
end_borrow %4 : $SwiftGizmo
|
|
destroy_value %3 : $SwiftGizmo // id: %6
|
|
%7 = tuple () // user: %8
|
|
return %7 : $() // id: %8
|
|
}
|
|
|
|
// CHECK: define internal void @"$s12objc_dealloc10SwiftGizmoCfDTo"([[OPAQUE:%.*]]*, i8*) unnamed_addr
|
|
sil [ossa] @$s12objc_dealloc10SwiftGizmoCfDTo : $@convention(objc_method) (SwiftGizmo) -> () {
|
|
bb0(%0 : @unowned $SwiftGizmo):
|
|
// CHECK-NEXT: entry
|
|
// CHECK-NEXT: [[OBJC_SUPER:%[a-zA-Z0-9_]+]] = alloca %objc_super, align 8
|
|
// CHECK: [[SGIZMOVAL:%[a-zA-Z0-9]+]] = bitcast [[OPAQUE]]* %0 to [[SGIZMO]]*
|
|
|
|
// Call to onDestruct()
|
|
// CHECK: call swiftcc void @"$s12objc_dealloc10onDestructyyF"()
|
|
|
|
// function_ref objc_dealloc.onDestruct () -> ()
|
|
%1 = function_ref @$s12objc_dealloc10onDestructyyF : $@convention(thin) () -> () // user: %2
|
|
%2 = apply %1() : $@convention(thin) () -> ()
|
|
|
|
// Destroy instance variables
|
|
// FIXME: This should move to .cxx_destruct
|
|
// CHECK: [[XOFFSET:%[a-zA-Z0-9]+]] = load i64, i64* @"$s12objc_dealloc10SwiftGizmoC1xAA1XCvpWvd", align 8
|
|
// CHECK-NEXT: bitcast
|
|
// CHECK-NEXT: [[IVAR_ADDR:%[a-zA-Z0-9]+]] = getelementptr inbounds i8, i8* {{.*}}, i64 [[XOFFSET]]
|
|
// CHECK-NEXT: [[XADDR:%[.a-zA-Z0-9]+]] = bitcast i8* [[IVAR_ADDR]] to %T12objc_dealloc1XC**
|
|
// CHECK-NEXT: [[X:%[a-zA-Z0-9]+]] = load %T12objc_dealloc1XC*, %T12objc_dealloc1XC** [[XADDR]], align 8
|
|
// CHECK-NEXT: call void bitcast (void (%swift.refcounted*)* @swift_release to void (%T12objc_dealloc1XC*)*)(%T12objc_dealloc1XC* [[X]])
|
|
%3 = begin_borrow %0 : $SwiftGizmo
|
|
%4 = ref_element_addr %3 : $SwiftGizmo, #SwiftGizmo.x // user: %4
|
|
destroy_addr %4 : $*X // id: %4
|
|
end_borrow %3 : $SwiftGizmo
|
|
|
|
// Call super -dealloc.
|
|
// CHECK: [[SUPER:%[a-zA-Z0-9]+]] = bitcast [[SGIZMO]]* [[SGIZMOVAL]] to [[GIZMO]]*
|
|
// CHECK-NEXT: [[SUPER_OBJ:%[a-zA-Z0-9]+]] = bitcast [[GIZMO]]* [[SUPER]] to %objc_object*
|
|
// CHECK-NEXT: [[TMP:%.*]] = call swiftcc %swift.metadata_response @"$s12objc_dealloc10SwiftGizmoCMa"(i64 0)
|
|
// CHECK-NEXT: [[T0:%.*]] = extractvalue %swift.metadata_response [[TMP]], 0
|
|
// CHECK-NEXT: [[T1:%.*]] = bitcast %swift.type* [[T0]] to %objc_class*
|
|
// CHECK-NEXT: [[OBJC_SUPER_RECEIVER:%[a-zA-Z0-9]+]] = getelementptr inbounds %objc_super, %objc_super* [[OBJC_SUPER]], i32 0, i32 0
|
|
// CHECK-NEXT: store %objc_object* [[SUPER_OBJ]], %objc_object** [[OBJC_SUPER_RECEIVER]], align 8
|
|
// CHECK-NEXT: [[OBJC_SUPER_CLASS:%[a-zA-Z0-9]+]] = getelementptr inbounds %objc_super, %objc_super* [[OBJC_SUPER]], i32 0, i32 1
|
|
// CHECK-NEXT: store %objc_class* [[T1]], %objc_class** [[OBJC_SUPER_CLASS]], align 8
|
|
// CHECK-NEXT: [[DEALLOC_SEL:%[a-zA-Z0-9]+]] = load i8*, i8** @"\01L_selector(dealloc)", align 8
|
|
// CHECK-NEXT: call void bitcast (void ()* @objc_msgSendSuper2 to void (%objc_super*, i8*)*)(%objc_super* [[OBJC_SUPER]], i8* [[DEALLOC_SEL]])
|
|
%5 = objc_super_method %0 : $SwiftGizmo, #Gizmo.deinit!deallocator.1.foreign : (Gizmo) -> () -> (), $@convention(objc_method) (Gizmo) -> () // user: %7
|
|
%6 = upcast %0 : $SwiftGizmo to $Gizmo // user: %7
|
|
%7 = apply %5(%6) : $@convention(objc_method) (Gizmo) -> ()
|
|
|
|
// CHECK-NEXT: ret void
|
|
%8 = tuple () // user: %9
|
|
return %8 : $() // id: %9
|
|
}
|
|
|
|
// @objc ObjectiveC.SwiftGizmo.__ivar_destroyer
|
|
sil [ossa] @$s12objc_dealloc10SwiftGizmoCfETo : $@convention(objc_method) (SwiftGizmo) -> () {
|
|
bb0(%0 : @unowned $SwiftGizmo):
|
|
%3 = tuple ()
|
|
return %3 : $() // id: %4
|
|
}
|
|
|
|
sil [ossa] @$s12objc_dealloc10SwiftGizmoCACycfcTo : $@convention(objc_method) (@owned SwiftGizmo) -> @owned SwiftGizmo {
|
|
bb0(%0 : @owned $SwiftGizmo):
|
|
return %0 : $SwiftGizmo
|
|
}
|
|
|
|
sil [ossa] @$s12objc_dealloc10SwiftGizmoC7bellsOnACSgSi_tcfcTo : $@convention(objc_method) (Int, @owned SwiftGizmo) -> @owned SwiftGizmo? {
|
|
bb0(%0 : $Int, %1 : @owned $SwiftGizmo):
|
|
unreachable
|
|
}
|