Files
swift-mirror/test/IRGen/exactcast.sil
Nate Chandler e5d87f75a8 [SIL] Add source formal type to checked_cast_br.
It is necessary for opaque values where for casts that will newly start
out as checked_cast_brs and be lowered to checked_cast_addr_brs, since
the latter has the source formal type, IRGen relies on being able to
access it, and there's no way in general to obtain the source formal
type from the source lowered type.
2023-07-27 15:04:15 -07:00

123 lines
4.8 KiB
Plaintext

// RUN: %target-swift-frontend -enable-objc-interop -emit-ir %s | %FileCheck %s -check-prefix CHECK -check-prefix CHECK-%target-import-type
// REQUIRES: CPU=x86_64
sil_stage canonical
import Builtin
import Swift
import SwiftShims
class Node {
@_hasStorage var index: Int { get set }
init(index: Int)
func check() -> Int
@objc deinit
}
class ParentNode : Node {
init(left: Node, right: Node, index: Int)
@objc deinit
override init(index: Int)
}
sil @_test_exact_checked_cast_branch : $@convention(method) (@guaranteed Node) -> Int {
bb0(%0 : $Node):
//CHECK-LABEL: define{{.*}}@_test_exact_checked_cast_branch
//CHECK: [[LOAD:%.*]] = load ptr
//CHECK-DIRECT-NEXT: = icmp eq ptr
//CHECK-INDIRECT-NEXT: = icmp eq ptr
//CHECK-NEXT: br i1
checked_cast_br [exact] Node in %0 : $Node to ParentNode, bb2, bb3 // id: %2
bb1: // Preds: bb2 bb3
return undef : $Int
bb2(%5 : $ParentNode): // Preds: bb0
br bb1 // id: %10
bb3: // Preds: bb0
br bb1 // id: %12
}
class BaseBase {
@inline(never) func foo()
init()
deinit
}
class Base<T> : BaseBase {
override init()
deinit
}
final class DerivedInt : Base<Int> {
@inline(never) override final func foo()
override init()
deinit
}
sil @test_exact_checked_cast_branch_dynamic_init : $@convention(thin) (@guaranteed BaseBase) -> Int {
bb0(%0 : $BaseBase):
//CHECK-LABEL: define{{.*}}@test_exact_checked_cast_branch_dynamic_init
//CHECK: call swiftcc {{.*}}@"$s9exactcast10DerivedIntCMa"({{.*}})
//CHECK: load
//CHECK: icmp eq ptr
//CHECK: br
checked_cast_br [exact] BaseBase in %0 : $BaseBase to DerivedInt, bb2, bb3 // id: %2
bb1:
return undef : $Int
bb2(%5 : $DerivedInt):
br bb1
bb3:
br bb1
}
sil @_TFC9pic_crash4NodecfMS0_FT5indexSi_S0_ : $@convention(method) (Int, @owned Node) -> @owned Node
sil @_TFC9pic_crash4NodeCfMS0_FT5indexSi_S0_ : $@convention(thin) (Int, @thick Node.Type) -> @owned Node
sil [transparent] @_TFC9pic_crash4Nodeg5indexSi : $@convention(method) (@guaranteed Node) -> Int
sil [transparent] @_TFC9pic_crash4Nodes5indexSi : $@convention(method) (Int, @guaranteed Node) -> ()
sil @_TFC9pic_crash10ParentNodecfMS0_FT4leftCS_4Node5rightS1_5indexSi_S0_ : $@convention(method) (@owned Node, @owned Node, Int, @owned ParentNode) -> @owned ParentNode
sil @_TFC9pic_crash10ParentNodeCfMS0_FT4leftCS_4Node5rightS1_5indexSi_S0_ : $@convention(thin) (@owned Node, @owned Node, Int, @thick ParentNode.Type) -> @owned ParentNode
sil @_TFC9pic_crash10ParentNodecfMS0_FT5indexSi_S0_ : $@convention(method) (Int, @owned ParentNode) -> @owned ParentNode
sil @_TFC9pic_crash10ParentNodeCfMS0_FT5indexSi_S0_ : $@convention(thin) (Int, @thick ParentNode.Type) -> @owned ParentNode
sil_vtable Node {
#Node.init!initializer: @_TFC9pic_crash4NodecfMS0_FT5indexSi_S0_ // pic_crash.Node.init (pic_crash.Node.Type)(index : Swift.Int) -> pic_crash.Node
#Node.check: @_test_exact_checked_cast_branch // pic_crash.Node.check (pic_crash.Node)() -> Swift.Int
#Node.index!getter: @_TFC9pic_crash4Nodeg5indexSi // pic_crash.Node.index.getter : Swift.Int
#Node.index!setter: @_TFC9pic_crash4Nodes5indexSi // pic_crash.Node.index.setter : Swift.Int
}
sil_vtable ParentNode {
#Node.init!initializer: @_TFC9pic_crash10ParentNodecfMS0_FT5indexSi_S0_ [override] // pic_crash.ParentNode.init (pic_crash.ParentNode.Type)(index : Swift.Int) -> pic_crash.ParentNode
#Node.check: @_test_exact_checked_cast_branch [override] // pic_crash.Node.check (pic_crash.Node)() -> Swift.Int
#Node.index!getter: @_TFC9pic_crash4Nodeg5indexSi [override] // pic_crash.Node.index.getter : Swift.Int
#Node.index!setter: @_TFC9pic_crash4Nodes5indexSi [override] // pic_crash.Node.index.setter : Swift.Int
#ParentNode.init!initializer: @_TFC9pic_crash10ParentNodecfMS0_FT4leftCS_4Node5rightS1_5indexSi_S0_ // pic_crash.ParentNode.init (pic_crash.ParentNode.Type)(left : pic_crash.Node, right : pic_crash.Node, index : Swift.Int) -> pic_crash.ParentNode
}
sil @$s5test104BaseB0C3fooyyF : $@convention(method) (@guaranteed BaseBase) -> ()
sil @$s5test104BaseB0CfD : $@convention(method) (@owned BaseBase) -> ()
sil @$s5test14BaseCfD : $@convention(method) (@owned BaseBase) -> ()
sil @$s5test110DerivedIntC3fooyyF : $@convention(method) (@guaranteed DerivedInt) -> ()
sil @$s5test110DerivedIntCfD : $@convention(method) (@owned DerivedInt) -> ()
sil_vtable BaseBase {
#BaseBase.foo: (BaseBase) -> () -> () : @$s5test104BaseB0C3fooyyF
#BaseBase.deinit!deallocator: @$s5test104BaseB0CfD
}
sil_vtable Base {
#BaseBase.foo: (BaseBase) -> () -> () : @$s5test104BaseB0C3fooyyF [inherited]
#Base.deinit!deallocator: @$s5test14BaseCfD
}
sil_vtable DerivedInt {
#BaseBase.foo: (BaseBase) -> () -> () : @$s5test110DerivedIntC3fooyyF [override]
#DerivedInt.deinit!deallocator: @$s5test110DerivedIntCfD
}