1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
|
// RUN: %target-swift-frontend %s -enable-objc-interop -emit-ir | %FileCheck %s -DINT=i%target-ptrsize -check-prefix CHECK -check-prefix CHECK-%target-import-type
// REQUIRES: CPU=i386 || CPU=x86_64
// TODO: missing `-enable-objc-interop` results in an assertion
import Swift
// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swiftcc void @archetype_metatype_cast
// CHECK: %0 = call ptr @swift_dynamicCastMetatype(ptr %T, ptr %U)
// CHECK: %1 = icmp ne ptr %0, null
sil @archetype_metatype_cast : $@convention(thin) <T, U> () -> () {
entry:
%0 = metatype $@thick T.Type
checked_cast_br T.Type in %0 : $@thick T.Type to @thick U.Type, yes, no
yes(%1 : $@thick U.Type):
br end
no:
br end
end:
return undef : $()
}
protocol P {}
// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swiftcc void @existential_archetype_metatype_cast(ptr %0, ptr %1, ptr %T)
// CHECK: [[T0:%.*]] = call ptr @swift_dynamicCastMetatype(ptr %0, ptr %T)
// CHECK: [[T1:%.*]] = icmp ne ptr [[T0]], null
sil @existential_archetype_metatype_cast : $@convention(thin) <T> (@thick P.Type) -> () {
entry(%0 : $@thick P.Type):
checked_cast_br P.Type in %0 : $@thick P.Type to @thick T.Type, yes, no
yes(%1 : $@thick T.Type):
br end
no:
br end
end:
return undef : $()
}
class SomeClass {}
sil_vtable SomeClass {}
// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swiftcc ptr @metatype_object_conversion(ptr %0) {{.*}} {
// CHECK: ret ptr %0
// CHECK: }
sil @metatype_object_conversion : $@convention(thin) (@objc_metatype SomeClass.Type) -> @owned AnyObject {
entry(%m : $@objc_metatype SomeClass.Type):
%o = objc_metatype_to_object %m : $@objc_metatype SomeClass.Type to $AnyObject
return %o : $AnyObject
}
protocol SomeClassProtocol : class {}
// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swiftcc ptr @existential_metatype_object_conversion(ptr %0, ptr %1) {{.*}} {
// CHECK: ret ptr %0
// CHECK: }
sil @existential_metatype_object_conversion : $@convention(thin) (@objc_metatype SomeClassProtocol.Type) -> @owned AnyObject {
entry(%m : $@objc_metatype SomeClassProtocol.Type):
%o = objc_existential_metatype_to_object %m : $@objc_metatype SomeClassProtocol.Type to $AnyObject
return %o : $AnyObject
}
class OtherClass : SomeClass {}
sil_vtable OtherClass {}
// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swiftcc void @value_metatype_cast(ptr %0)
// CHECK: [[T1:%.*]] = load ptr, ptr %0
// CHECK-DIRECT: [[T2:%.*]] = icmp eq ptr [[T1]], {{.*}} @"$s14metatype_casts10OtherClassCMf"
// CHECK-INDIRECT:[[T2:%.*]] = icmp eq ptr
sil @value_metatype_cast : $@convention(thin) (SomeClass) -> () {
entry(%0 : $SomeClass):
%1 = value_metatype $@thick SomeClass.Type, %0 : $SomeClass
checked_cast_br [exact] @thick SomeClass.Type in %1 : $@thick SomeClass.Type to @thick OtherClass.Type, yes, no
yes(%2 : $@thick OtherClass.Type):
br end
no:
br end
end:
return undef : $()
}
// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swiftcc ptr @checked_cast_to_anyobject_type
// CHECK: [[CAST:%.*]] = call { ptr } @dynamic_cast_existential_0_class_unconditional(ptr %0, ptr %0)
// CHECK: [[RESULT0:%.*]] = extractvalue { ptr } [[CAST]], 0
// CHECK: ret ptr [[RESULT0]]
sil @checked_cast_to_anyobject_type : $@convention(thin) (@thick Any.Type) -> @thick AnyObject.Type {
entry(%0 : $@thick Any.Type):
%2 = unconditional_checked_cast %0 : $@thick Any.Type to @thick AnyObject.Type
return %2 : $@thick AnyObject.Type
}
// Trivial case -- we know the source is a class metatype, so there's nothing
// to check.
// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swiftcc ptr @checked_cast_class_to_anyobject_type
// CHECK: [[TMP:%.*]] = call swiftcc %swift.metadata_response @"$s14metatype_casts9SomeClassCMa"([[INT]] 0)
// CHECK: [[METATYPE:%.*]] = extractvalue %swift.metadata_response [[TMP]], 0
// CHECK: ret ptr [[METATYPE]]
sil @checked_cast_class_to_anyobject_type : $@convention(thin) () -> @thick AnyObject.Type {
entry:
%1 = metatype $@thick SomeClass.Type
%2 = unconditional_checked_cast %1 : $@thick SomeClass.Type to @thick AnyObject.Type
return %2 : $@thick AnyObject.Type
}
|