blob: c154ab2df24d21cf480ecb0de4c1ee3632568346 [file] [log] [blame]
// RUN: %target-swift-frontend %s -emit-ir | %FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-%target-ptrsize --check-prefix=CHECK-%target-runtime
import Swift
// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swiftcc {{i[0-9]+}} @open_boxed_existential(%swift.error*)
sil @open_boxed_existential : $@convention(thin) (@owned Error) -> Int {
entry(%b : $Error):
// CHECK: call void @swift_getErrorValue(%swift.error* %0, i8** {{%.*}}, [[TRIPLE:{ %swift.opaque\*, %swift.type\*, i8\*\* }]]* [[OUT:%.*]])
// CHECK: [[OUT_ADDR:%.*]] = getelementptr inbounds {{.*}} [[OUT]], i32 0, i32 0
// CHECK: [[ADDR:%.*]] = load {{.*}} [[OUT_ADDR]]
// CHECK: [[OUT_TYPE:%.*]] = getelementptr inbounds {{.*}} [[OUT]], i32 0, i32 1
// CHECK: [[TYPE:%.*]] = load {{.*}} [[OUT_TYPE]]
// CHECK: [[OUT_WITNESS:%.*]] = getelementptr inbounds {{.*}} [[OUT]], i32 0, i32 2
// CHECK: [[WITNESS:%.*]] = load {{.*}} [[OUT_WITNESS]]
%o = open_existential_box %b : $Error to $*@opened("01234567-89AB-CDEF-0123-000000000000") Error
%m = witness_method $@opened("01234567-89AB-CDEF-0123-000000000000") Error, #Error._code!getter.1, %o : $*@opened("01234567-89AB-CDEF-0123-000000000000") Error : $@convention(witness_method: Error) <Self: Error> (@in_guaranteed Self) -> Int
// CHECK: [[RESULT:%.*]] = call swiftcc [[INT:i[0-9]+]] @"$ss5ErrorP5_codeSivgTj"(%swift.opaque* noalias nocapture swiftself [[ADDR]], %swift.type* [[TYPE]], i8** [[WITNESS]])
%c = apply %m<@opened("01234567-89AB-CDEF-0123-000000000000") Error>(%o) : $@convention(witness_method: Error) <Self: Error> (@in_guaranteed Self) -> Int
// CHECK: ret [[INT]] [[RESULT]]
return %c : $Int
}