Skip to content

Commit f6dd432

Browse files
committed
PrintAsObjC Test: Test pointer types with @cdecl
1 parent 0f98021 commit f6dd432

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

test/PrintAsObjC/cdecl-official.swift

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121

2222
//--- Lib.swift
2323

24+
// CHECK-NOT: assume_nonnull
25+
2426
// CHECK: #if defined(__cplusplus)
2527
// CHECK: extern "C" {
2628
// CHECK: #endif
@@ -43,6 +45,23 @@ func c_keywordArgNames(auto: Int, union: Int) {}
4345
func d_returnNever() -> Never { fatalError() }
4446
// CHECK-LABEL: SWIFT_EXTERN void return_never(void) SWIFT_NOEXCEPT SWIFT_NORETURN;
4547

48+
/// Pointer types
49+
// CHECK: /// Pointer types
50+
51+
@cdecl("pointers")
52+
func f_pointers(_ x: UnsafeMutablePointer<Int>,
53+
y: UnsafePointer<Int>,
54+
z: UnsafeMutableRawPointer,
55+
w: UnsafeRawPointer,
56+
u: OpaquePointer) {}
57+
// CHECK: SWIFT_EXTERN void pointers(ptrdiff_t * _Nonnull x, ptrdiff_t const * _Nonnull y, void * _Nonnull z, void const * _Nonnull w, void * _Nonnull u) SWIFT_NOEXCEPT;
58+
59+
@cdecl("nullable_pointers")
60+
func g_nullablePointers(_ x: UnsafeMutableRawPointer,
61+
y: UnsafeMutableRawPointer?,
62+
z: UnsafeMutableRawPointer!) {}
63+
// CHECK: SWIFT_EXTERN void nullable_pointers(void * _Nonnull x, void * _Nullable y, void * _Null_unspecified z) SWIFT_NOEXCEPT;
64+
4665
// CHECK: #if defined(__cplusplus)
4766
// CHECK-NEXT: }
4867
// CHECK-NEXT: #endif

test/attr/attr_cdecl_official.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,19 @@ class Foo {
5555

5656
@cdecl("throwing") // expected-error{{raising errors from @cdecl functions is not supported}}
5757
func throwing() throws { }
58+
59+
@cdecl("acceptedPointers")
60+
func acceptedPointers(_ x: UnsafeMutablePointer<Int>,
61+
y: UnsafePointer<Int>,
62+
z: UnsafeMutableRawPointer,
63+
w: UnsafeRawPointer,
64+
u: OpaquePointer) {}
65+
66+
@cdecl("rejectedPointers")
67+
func rejectedPointers( // expected-error 6 {{global function cannot be marked '@cdecl' because the type of the parameter}}
68+
x: UnsafePointer<String>, // expected-note {{Swift structs cannot be represented in Objective-C}} // FIXME: Should reference C.
69+
y: CVaListPointer, // expected-note {{Swift structs cannot be represented in Objective-C}}
70+
z: UnsafeBufferPointer<Int>, // expected-note {{Swift structs cannot be represented in Objective-C}}
71+
u: UnsafeMutableBufferPointer<Int>, // expected-note {{Swift structs cannot be represented in Objective-C}}
72+
v: UnsafeRawBufferPointer, // expected-note {{Swift structs cannot be represented in Objective-C}}
73+
t: UnsafeMutableRawBufferPointer) {} // expected-note {{Swift structs cannot be represented in Objective-C}}

0 commit comments

Comments
 (0)