|
| 1 | +// %target-swift-frontend(mock-sdk: %clang-importer-sdk-nosource -I %t) -import-objc-header %S/Inputs/overloaded_async_method.h %s -typecheck -verify |
| 2 | + |
| 3 | +// RUN: %empty-directory(%t) |
| 4 | + |
| 5 | +// RUN: %gyb %s -o %t/swift_to_c_pointer_conversions.swift |
| 6 | + |
| 7 | +// RUN: %line-directive %t/swift_to_c_pointer_conversions.swift -- %target-swift-frontend(mock-sdk: %clang-importer-sdk-nosource -I %t) -import-objc-header %S/Inputs/c_pointer_conversions.h %t/swift_to_c_pointer_conversions.swift -typecheck -verify |
| 8 | + |
| 9 | +func test_raw_ptr(ptr: UnsafeRawPointer) { |
| 10 | + char_ptr_func(ptr) // expected-error {{}} |
| 11 | + unsigned_char_ptr_func(ptr) // expected-error {{}} |
| 12 | + |
| 13 | + const_char_ptr_func(ptr) // Ok |
| 14 | + const_unsigned_char_ptr_func(ptr) // Ok |
| 15 | + |
| 16 | + % for Size in ['16', '32', '64']: |
| 17 | + int_${Size}_ptr_func(ptr) // expected-error {{}} |
| 18 | + uint_${Size}_ptr_func(ptr) // expected-error {{}} |
| 19 | + |
| 20 | + const_int_${Size}_ptr_func(ptr) // expected-error {{}} |
| 21 | + const_uint_${Size}_ptr_func(ptr) // expected-error {{}} |
| 22 | + % end |
| 23 | +} |
| 24 | + |
| 25 | +func test_mutable_raw_pointer(ptr: UnsafeMutableRawPointer) { |
| 26 | + char_ptr_func(ptr) // Ok |
| 27 | + unsigned_char_ptr_func(ptr) // Ok |
| 28 | + |
| 29 | + const_char_ptr_func(ptr) // Ok |
| 30 | + const_unsigned_char_ptr_func(ptr) // Ok |
| 31 | + |
| 32 | + % for Size in ['16', '32', '64']: |
| 33 | + int_${Size}_ptr_func(ptr) // expected-error {{}} |
| 34 | + uint_${Size}_ptr_func(ptr) // expected-error {{}} |
| 35 | + |
| 36 | + const_int_${Size}_ptr_func(ptr) // expected-error {{}} |
| 37 | + const_uint_${Size}_ptr_func(ptr) // expected-error {{}} |
| 38 | + % end |
| 39 | +} |
| 40 | + |
| 41 | +%for TestPtrSize in ['16', '32', '64']: |
| 42 | +// Immutable pointers can be converted only to their immutable (regardless of sign) counterparts. |
| 43 | +func test_${TestPtrSize}_bit_ptrs(sptr: UnsafePointer<Int${TestPtrSize}>, |
| 44 | + uptr: UnsafePointer<UInt${TestPtrSize}>) { |
| 45 | + char_ptr_func(sptr) // expected-error {{}} |
| 46 | + char_ptr_func(uptr) // expected-error {{}} |
| 47 | + |
| 48 | + const_char_ptr_func(sptr) // Ok |
| 49 | + const_char_ptr_func(uptr) // Ok |
| 50 | + |
| 51 | + unsigned_char_ptr_func(sptr) // expected-error {{}} |
| 52 | + unsigned_char_ptr_func(uptr) // expected-error {{}} |
| 53 | + |
| 54 | + const_unsigned_char_ptr_func(sptr) // Ok |
| 55 | + const_unsigned_char_ptr_func(uptr) // Ok |
| 56 | + |
| 57 | +% for pointer in ['sptr', 'uptr']: |
| 58 | + % for Size in ['16', '32', '64']: |
| 59 | + |
| 60 | + % if Size == TestPtrSize: |
| 61 | + int_${TestPtrSize}_ptr_func(${pointer}) // expected-error {{}} |
| 62 | + uint_${TestPtrSize}_ptr_func(${pointer}) // expected-error {{}} |
| 63 | + |
| 64 | + const_int_${TestPtrSize}_ptr_func(${pointer}) // Ok |
| 65 | + const_uint_${TestPtrSize}_ptr_func(${pointer}) // Ok |
| 66 | + % else: |
| 67 | + int_${Size}_ptr_func(${pointer}) // expected-error {{}} |
| 68 | + uint_${Size}_ptr_func(${pointer}) // expected-error {{}} |
| 69 | + |
| 70 | + const_int_${Size}_ptr_func(${pointer}) // expected-error {{}} expected-note {{}} |
| 71 | + const_uint_${Size}_ptr_func(${pointer}) // expected-error {{}} expected-note {{}} |
| 72 | + % end |
| 73 | + % end |
| 74 | +% end |
| 75 | +} |
| 76 | + |
| 77 | +% end |
| 78 | + |
| 79 | +%for TestPtrSize in ['16', '32', '64']: |
| 80 | +// Mutable pointers can be converted to both immutable and mutable pointers when |
| 81 | +// passed to C/ObjC imported functions. |
| 82 | +func test_mutable_${TestPtrSize}_bit_ptrs(sptr: UnsafeMutablePointer<Int${TestPtrSize}>, |
| 83 | + uptr: UnsafeMutablePointer<UInt${TestPtrSize}>) { |
| 84 | + char_ptr_func(sptr) // Ok |
| 85 | + char_ptr_func(uptr) // Ok |
| 86 | + |
| 87 | + const_char_ptr_func(sptr) // Ok |
| 88 | + const_char_ptr_func(uptr) // Ok |
| 89 | + |
| 90 | + unsigned_char_ptr_func(sptr) // Ok |
| 91 | + unsigned_char_ptr_func(uptr) // Ok |
| 92 | + |
| 93 | + const_unsigned_char_ptr_func(sptr) // Ok |
| 94 | + const_unsigned_char_ptr_func(uptr) // Ok |
| 95 | + |
| 96 | +% for pointer in ['sptr', 'uptr']: |
| 97 | + % for Size in ['16', '32', '64']: |
| 98 | + |
| 99 | + % if Size == TestPtrSize: |
| 100 | + int_${TestPtrSize}_ptr_func(${pointer}) // Ok |
| 101 | + uint_${TestPtrSize}_ptr_func(${pointer}) // Ok |
| 102 | + |
| 103 | + const_int_${TestPtrSize}_ptr_func(${pointer}) // Ok |
| 104 | + const_uint_${TestPtrSize}_ptr_func(${pointer}) // Ok |
| 105 | + % else: |
| 106 | + int_${Size}_ptr_func(${pointer}) // expected-error {{}} expected-note {{}} |
| 107 | + uint_${Size}_ptr_func(${pointer}) // expected-error {{}} expected-note {{}} |
| 108 | + |
| 109 | + const_int_${Size}_ptr_func(${pointer}) // expected-error {{}} expected-note {{}} |
| 110 | + const_uint_${Size}_ptr_func(${pointer}) // expected-error {{}} expected-note {{}} |
| 111 | + % end |
| 112 | + % end |
| 113 | +% end |
| 114 | +} |
| 115 | + |
| 116 | +% end |
0 commit comments