blob: c1be95c0dff22fe0d91e5d5e79829c667a6dc3af [file] [log] [blame]
// RUN: %target-swift-frontend %s -enable-objc-interop -emit-ir | %FileCheck %s
// REQUIRES: CPU=x86_64
import Builtin
// ObjC payloads can be nullable too.
enum NullableObjCRefcounted {
case Ref(Builtin.UnknownObject)
case None
}
// CHECK-LABEL: define internal void @"$s39enum_value_semantics_special_cases_objc22NullableObjCRefcountedOwxx"(%swift.opaque* noalias %object, %swift.type* %NullableObjCRefcounted) {{.*}} {
// CHECK: entry:
// CHECK: %0 = bitcast %swift.opaque* %object to %T39enum_value_semantics_special_cases_objc22NullableObjCRefcountedO*
// CHECK: %1 = bitcast %T39enum_value_semantics_special_cases_objc22NullableObjCRefcountedO* %0 to %objc_object**
// CHECK: %2 = load %objc_object*, %objc_object** %1, align 8
// CHECK: call void @swift_unknownObjectRelease(%objc_object* %2) {{#[0-9]+}}
// CHECK: ret void
// CHECK: }
class C {}
sil_vtable C {}
sil @$s39enum_value_semantics_special_cases_objc1CCfD : $@convention(method) (C) -> ()
enum AllMixedRefcounted {
case Ref(Builtin.NativeObject)
case CRef(C)
case ORef(Builtin.UnknownObject)
case None
}
// CHECK-LABEL: define internal void @"$s39enum_value_semantics_special_cases_objc18AllMixedRefcountedOwxx"(%swift.opaque* noalias %object, %swift.type* %AllMixedRefcounted) {{.*}} {
// CHECK: entry:
// CHECK: %0 = bitcast %swift.opaque* %object to %T39enum_value_semantics_special_cases_objc18AllMixedRefcountedO*
// CHECK: %1 = bitcast %T39enum_value_semantics_special_cases_objc18AllMixedRefcountedO* %0 to i64*
// CHECK: %2 = load i64, i64* %1, align 8
// CHECK: %3 = lshr i64 %2, 62
// CHECK: %4 = trunc i64 %3 to i8
// CHECK: %5 = and i8 %4, 3
// CHECK: call void @"$s39enum_value_semantics_special_cases_objc18AllMixedRefcountedOWOe"(i64 %2)
// CHECK: ret void
// CHECK: }
enum AllMixedRefcountedTwoSimple {
case Ref(Builtin.NativeObject)
case CRef(C)
case ORef(Builtin.UnknownObject)
case None
case Nothing
}
// CHECK-LABEL: define internal void @"$s39enum_value_semantics_special_cases_objc27AllMixedRefcountedTwoSimpleOwxx"
// CHECK: call void @"$s39enum_value_semantics_special_cases_objc27AllMixedRefcountedTwoSimpleOWOy"
struct Val {
}
// Currently, swift_unknownObjectRelease does not support the indirect heap object.
enum MixedRefcountedWithIndirect {
indirect case Indirect(Builtin.Int64)
case Ref(Builtin.UnknownObject)
case None
}
// CHECK-LABEL: define internal void @"$s39enum_value_semantics_special_cases_objc27MixedRefcountedWithIndirectOwxx"(%swift.opaque* noalias %object, %swift.type* %MixedRefcountedWithIndirect)
// CHECK: entry:
// CHECK: %0 = bitcast %swift.opaque* %object to %T39enum_value_semantics_special_cases_objc27MixedRefcountedWithIndirectO*
// CHECK: %1 = bitcast %T39enum_value_semantics_special_cases_objc27MixedRefcountedWithIndirectO* %0 to i64*
// CHECK: %2 = load i64, i64* %1, align 8
// CHECK: %3 = lshr i64 %2, 62
// CHECK: %4 = trunc i64 %3 to i8
// CHECK: %5 = and i8 %4, 3
// CHECK: call void @"$s39enum_value_semantics_special_cases_objc27MixedRefcountedWithIndirectOWOe"(i64 %2)
// CHECK: ret void
// CHECK: }
// CHECK-LABEL: define linkonce_odr hidden void @"$s39enum_value_semantics_special_cases_objc27MixedRefcountedWithIndirectOWOe"(i64)
// CHECK: entry:
// CHECK: %1 = lshr i64 %0, 62
// CHECK: %2 = trunc i64 %1 to i8
// CHECK: %3 = and i8 %2, 3
// CHECK: switch i8 %3, label %9 [
// CHECK: i8 0, label %4
// CHECK: i8 1, label %6
// CHECK: ]
// CHECK: ; <label>:4:
// CHECK: %5 = inttoptr i64 %0 to %swift.refcounted*
// CHECK: call void @swift_release(%swift.refcounted* %5) #1
// CHECK: br label %9
// CHECK: ; <label>:6:
// CHECK: %7 = and i64 %0, 4611686018427387903
// CHECK: %8 = inttoptr i64 %7 to %objc_object*
// CHECK: call void @swift_unknownObjectRelease(%objc_object* %8) #1
// CHECK: br label %9
// CHECK: ; <label>:9:
// CHECK: ret void