mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
We have enough flag bits on function types now to warrant stashing an extra word in the metadata key alongside the arguments and results, so add one, and pack the number of arguments, function convention, and 'throws' bit in there. This lets us merge the separate metadata caches for thick/thin/block/C functions into one, saving a bit of runtime memory, and simplifying a bunch of repetitive code in the runtime and IRGen. This also fixes a subtle bug we had where the runtime getFunctionTypeMetadata function expected the result argument to be passed in the arguments array, but IRGen was passing it as a separate argument, which would have caused function type metadata to fail to be uniqued by result type. Swift SVN r27651
46 lines
1.9 KiB
Plaintext
46 lines
1.9 KiB
Plaintext
// RUN: %target-swift-frontend -emit-ir %s | FileCheck %s
|
|
|
|
import Swift
|
|
|
|
// CHECK-LABEL: define void @c_function_pointer(void ()*)
|
|
sil @c_function_pointer : $@convention(c) (CFunctionPointer<() -> ()>) -> () {
|
|
entry(%f : $CFunctionPointer<() -> ()>):
|
|
return undef : $()
|
|
}
|
|
|
|
// CHECK-LABEL: define void @c_native_function_pointer(void ()*)
|
|
sil @c_native_function_pointer : $@convention(c) (@convention(c) () -> ()) -> () {
|
|
entry(%f : $@convention(c) () -> ()):
|
|
return undef : $()
|
|
}
|
|
|
|
// CHECK-LABEL: define void @call_with_c_function_pointer(i8*)
|
|
sil @call_with_c_function_pointer : $@convention(thin) (CFunctionPointer<() -> ()>) -> () {
|
|
entry(%f : $CFunctionPointer<() -> ()>):
|
|
%c = function_ref @c_function_pointer : $@convention(c) (CFunctionPointer<() -> ()>) -> ()
|
|
%z = apply %c(%f) : $@convention(c) (CFunctionPointer<() -> ()>) -> ()
|
|
return %z : $()
|
|
}
|
|
|
|
// CHECK-LABEL: define void @call_with_native_c_function_pointer(i8*)
|
|
sil @call_with_native_c_function_pointer : $@convention(thin) (@convention(c) () -> ()) -> () {
|
|
entry(%f : $@convention(c) () -> ()):
|
|
%c = function_ref @c_native_function_pointer : $@convention(c) (@convention(c) () -> ()) -> ()
|
|
%z = apply %c(%f) : $@convention(c) (@convention(c) () -> ()) -> ()
|
|
return %z : $()
|
|
}
|
|
|
|
// CHECK-LABEL: define %swift.type* @c_function_pointer_metadata()
|
|
sil @c_function_pointer_metadata : $@convention(thin) () -> @thick Any.Type {
|
|
entry:
|
|
// CHECK: call %swift.type* @_TMacT_T_()
|
|
%m = metatype $@thick (@convention(c) () -> ()).Type
|
|
%a = init_existential_metatype %m : $@thick (@convention(c) () -> ()).Type, $@thick Any.Type
|
|
return %a : $@thick Any.Type
|
|
}
|
|
|
|
// CHECK-LABEL: define linkonce_odr hidden %swift.type* @_TMacT_T_()
|
|
// -- 0x3000001 -- C convention, 1 argument
|
|
// CHECK: call %swift.type* @swift_getFunctionTypeMetadata1([[WORD:i(32|64)]] 50331649
|
|
|