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 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
|
// RUN: %target-swift-frontend %s -gnone -emit-ir -disable-objc-attr-requires-foundation-module -enable-objc-interop | %FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-%target-ptrsize --check-prefix=CHECK-%target-ptrsize-simulator-%target-is-simulator
// REQUIRES: CPU=i386 || CPU=x86_64
// We have to claim this is raw SIL because there are critical edges from non
// cond_br instructions.
sil_stage raw
import Builtin
import Swift
@objc class OC {}
sil_vtable OC {}
sil hidden @$s9enum_objc2OCCACycfcTo : $@convention(thin) (OC) -> OC {
entry(%x : $OC):
return %x : $OC
}
protocol PC : class {}
@objc protocol PO {}
enum SinglePayloadClassProtocol {
case x(PC)
case y, z, w
}
enum SinglePayloadObjCProtocol {
case x(PO)
case y, z, w
}
// CHECK-64: define{{( dllexport)?}}{{( protected)?}} swiftcc void @single_payload_class_protocol_switch(i64 %0, i64 %1) {{.*}} {
// CHECK-64: switch i64 %0, label {{%.*}} [
// CHECK-64: i64 0, label {{%.*}}
// CHECK-64-simulator-false: i64 2, label {{%.*}}
// CHECK-64-simulator-false: i64 4, label {{%.*}}
// CHECK-64-simulator-true: i64 1, label {{%.*}}
// CHECK-64-simulator-true: i64 2, label {{%.*}}
// CHECK-64: ]
// CHECK-64: inttoptr i64 %0 to ptr
// CHECK-64: inttoptr i64 %1 to ptr
// CHECK-32: define{{( dllexport)?}}{{( protected)?}} swiftcc void @single_payload_class_protocol_switch(i32 %0, i32 %1) {{.*}} {
// CHECK-32: switch i32 %0, label {{%.*}} [
// CHECK-32: i32 0, label {{%.*}}
// CHECK-32: i32 1, label {{%.*}}
// CHECK-32: i32 2, label {{%.*}}
// CHECK-32: ]
// CHECK-32: inttoptr i32 %0 to ptr
// CHECK-32: inttoptr i32 %1 to ptr
sil @single_payload_class_protocol_switch : $(SinglePayloadClassProtocol) -> () {
entry(%c : $SinglePayloadClassProtocol):
switch_enum %c : $SinglePayloadClassProtocol, case #SinglePayloadClassProtocol.x!enumelt: x_dest, case #SinglePayloadClassProtocol.y!enumelt: y_dest, case #SinglePayloadClassProtocol.z!enumelt: z_dest, case #SinglePayloadClassProtocol.w!enumelt: w_dest
x_dest(%d : $PC):
br end
y_dest:
br end
z_dest:
br end
w_dest:
br end
end:
return undef : $()
}
// CHECK-64: define{{( dllexport)?}}{{( protected)?}} swiftcc void @single_payload_objc_protocol_switch(i64 %0) {{.*}} {
// CHECK-64: switch i64 %0, label {{%.*}}
// CHECK-64: i64 0, label {{%.*}}
// CHECK-64-simulator-false: i64 2, label {{%.*}}
// CHECK-64-simulator-false: i64 4, label {{%.*}}
// CHECK-64-simulator-true: i64 1, label {{%.*}}
// CHECK-64-simulator-true: i64 2, label {{%.*}}
// CHECK-64: ]
// CHECK-64: inttoptr i64 %0 to ptr
// CHECK-32: define{{( dllexport)?}}{{( protected)?}} swiftcc void @single_payload_objc_protocol_switch(i32 %0) {{.*}} {
// CHECK-32: switch i32 %0, label {{%.*}}
// CHECK-32: i32 0, label {{%.*}}
// CHECK-32: i32 1, label {{%.*}}
// CHECK-32: i32 2, label {{%.*}}
// CHECK-32: ]
// CHECK-32: inttoptr i32 %0 to ptr
sil @single_payload_objc_protocol_switch : $(SinglePayloadObjCProtocol) -> () {
entry(%c : $SinglePayloadObjCProtocol):
switch_enum %c : $SinglePayloadObjCProtocol, case #SinglePayloadObjCProtocol.x!enumelt: x_dest, case #SinglePayloadObjCProtocol.y!enumelt: y_dest, case #SinglePayloadObjCProtocol.z!enumelt: z_dest, case #SinglePayloadObjCProtocol.w!enumelt: w_dest
x_dest(%d : $PO):
br end
y_dest:
br end
z_dest:
br end
w_dest:
br end
end:
return undef : $()
}
protocol delegateProtocol : AnyObject { }
struct StructWithWeakVar {
weak var delegate: delegateProtocol?
}
// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swiftcc void @weak_optional(ptr noalias dereferenceable({{.*}}) %0)
sil @weak_optional : $@convention(thin) (@in StructWithWeakVar?) -> () {
entry(%x : $*StructWithWeakVar?):
// CHECK: icmp eq [[WORD:i32|i64]] {{%.*}}, 0
switch_enum_addr %x : $*StructWithWeakVar?,
case #Optional.some!enumelt: a,
case #Optional.none!enumelt: b
a:
br x
b:
// CHECK: store [[WORD]] 0
// CHECK: store [[WORD]] 1
inject_enum_addr %x : $*StructWithWeakVar?, #Optional.none!enumelt
br x
x:
return undef : $()
}
|