Files
swift-mirror/test/IRGen/open_boxed_existential.sil
Alex Lorenz 4858cb6225 [IRGen][interop] do not add 'nocapture' to not bitwise takable types
The use of 'nocapture' for parameters and return values is incorrect for C++ types, as they can actually capture a pointer into its own value (e.g. std::string in libstdc++)

rdar://115062687
2023-09-25 17:43:34 -07:00

22 lines
1.6 KiB
Plaintext

// 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(ptr %0)
sil @open_boxed_existential : $@convention(thin) (@owned Error) -> Int {
entry(%b : $Error):
// CHECK: call void @swift_getErrorValue(ptr %0, ptr {{%.*}}, ptr [[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) Self
%m = witness_method $@opened("01234567-89AB-CDEF-0123-000000000000", Error) Self, #Error._code!getter, %o : $*@opened("01234567-89AB-CDEF-0123-000000000000", Error) Self : $@convention(witness_method: Error) <Self: Error> (@in_guaranteed Self) -> Int
// CHECK: [[RESULT:%.*]] = call swiftcc [[INT:i[0-9]+]] @"$ss5ErrorP5_codeSivgTj"(ptr noalias swiftself [[ADDR]], ptr [[TYPE]], ptr [[WITNESS]])
%c = apply %m<@opened("01234567-89AB-CDEF-0123-000000000000", Error) Self>(%o) : $@convention(witness_method: Error) <Self: Error> (@in_guaranteed Self) -> Int
// CHECK: ret [[INT]] [[RESULT]]
return %c : $Int
}