blob: 309937a94f5b53d706bd182d22df5da01aa409c5 [file] [log] [blame]
// RUN: %swift -target x86_64-apple-macosx10.9 -module-name function_types %s -emit-ir -o - | FileCheck %s
// RUN: %swift -target i386-apple-ios7.1 %s -module-name function_types -emit-ir -o - | FileCheck %s
// RUN: %swift -target x86_64-apple-ios7.1 %s -module-name function_types -emit-ir -o - | FileCheck %s
// RUN: %swift -target armv7-apple-ios7.1 %s -module-name function_types -emit-ir -o - | FileCheck %s
// RUN: %swift -target arm64-apple-ios7.1 %s -module-name function_types -emit-ir -o - | FileCheck %s
// RUN: %swift -target x86_64-unknown-linux-gnu -disable-objc-interop %s -module-name function_types -emit-ir -o - | FileCheck %s
// REQUIRES: X86
// REQUIRES: ARM
import Builtin
sil_stage canonical
// CHECK-LABEL: define{{( protected)?}} i8* @thin_func_value(i8*) {{.*}} {
// CHECK-NEXT: entry:
// CHECK-NEXT: ret i8* %0
// CHECK-NEXT: }
sil @thin_func_value : $@convention(thin) (@convention(thin) () -> ()) -> @convention(thin) () -> () {
entry(%x : $@convention(thin) () -> ()):
return %x : $@convention(thin) () -> ()
}
// CHECK-LABEL: define{{( protected)?}} { i8*, %swift.refcounted* } @thick_func_value(i8*, %swift.refcounted*) {{.*}} {
// CHECK-NEXT: entry:
// CHECK-NEXT: call void @rt_swift_retain(%swift.refcounted* %1) {{#[0-9]+}}
// CHECK-NEXT: call void @rt_swift_release(%swift.refcounted* %1) {{#[0-9]+}}
// CHECK-NEXT: %2 = insertvalue { i8*, %swift.refcounted* } undef, i8* %0, 0
// CHECK-NEXT: %3 = insertvalue { i8*, %swift.refcounted* } %2, %swift.refcounted* %1, 1
// CHECK-NEXT: ret { i8*, %swift.refcounted* } %3
// CHECK-NEXT: }
sil @thick_func_value : $@convention(thin) (@owned () -> ()) -> @owned () -> () {
entry(%x : $() -> ()):
strong_retain %x : $() -> ()
strong_release %x : $() -> ()
return %x : $() -> ()
}
// CHECK-LABEL: define{{( protected)?}} { i8*, i8** } @thin_witness_value(i8*, i8**) {{.*}} {
// CHECK-NEXT: entry:
// CHECK-NEXT: [[T0:%.*]] = insertvalue { i8*, i8** } undef, i8* %0, 0
// CHECK-NEXT: [[T1:%.*]] = insertvalue { i8*, i8** } [[T0]], i8** %1, 1
// CHECK-NEXT: ret { i8*, i8** } [[T1]]
// CHECK-NEXT: }
sil @thin_witness_value : $@convention(thin) (@convention(witness_method) () -> ()) -> @convention(witness_method) () -> () {
entry(%x : $@convention(witness_method) () -> ()):
return %x : $@convention(witness_method) () -> ()
}
struct X {}
sil @out_void_return : $@convention(thin) () -> @out X
// CHECK-LABEL: define{{( protected)?}} void @use_void_return_value(%V14function_types1X* noalias nocapture sret) {{.*}} {
// CHECK-NEXT: entry:
// CHECK-NEXT: call void @out_void_return(%V14function_types1X* noalias nocapture sret %0)
// CHECK-NEXT: ret void
// CHECK-NEXT: }
sil @use_void_return_value : $@convention(thin) () -> @out X {
entry(%x : $*X):
%f = function_ref @out_void_return : $@convention(thin) () -> @out X
%z = apply %f(%x) : $@convention(thin) () -> @out X
return %z : $()
}
// CHECK-LABEL: define{{( protected)?}} i1 @test_is_nonnull_function(i8*, %swift.refcounted*) {{.*}} {
// CHECK-NEXT: entry:
// CHECK-NEXT: %2 = icmp ne i8* %0, null
// CHECK-NEXT: ret i1 %2
// CHECK-NEXT: }
sil @test_is_nonnull_function : $@convention(thin) (() -> ()) -> Builtin.Int1 {
bb0(%0 : $() -> ()):
%3 = is_nonnull %0 : $() -> ()
return %3 : $Builtin.Int1 // id: %5
}
// CHECK-LABEL: define{{( protected)?}} i8* @test_function_to_pointer(i8*)
// CHECK-NEXT: entry:
// CHECK-NEXT: ret i8* %0
sil @test_function_to_pointer : $@convention(thin) (@convention(thin) () -> ()) -> Builtin.RawPointer {
bb0(%0 : $@convention(thin) () -> ()):
%1 = thin_function_to_pointer %0 : $@convention(thin) () -> () to $Builtin.RawPointer
return %1 : $Builtin.RawPointer
}
// CHECK-LABEL: define{{( protected)?}} i8* @test_pointer_to_function(i8*)
// CHECK-NEXT: entry:
// CHECK-NEXT: ret i8* %0
sil @test_pointer_to_function : $@convention(thin) (Builtin.RawPointer) -> @convention(thin) () -> () {
bb0(%0 : $Builtin.RawPointer):
%1 = pointer_to_thin_function %0 : $Builtin.RawPointer to $@convention(thin) () -> ()
return %1 : $@convention(thin) () -> ()
}