mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[ConstraintSystem] NFC: Add test-cases for interactions between Swift and C pointers
This commit is contained in:
116
test/Constraints/swift_to_c_pointer_conversions.swift.gyb
Normal file
116
test/Constraints/swift_to_c_pointer_conversions.swift.gyb
Normal file
@@ -0,0 +1,116 @@
|
||||
// %target-swift-frontend(mock-sdk: %clang-importer-sdk-nosource -I %t) -import-objc-header %S/Inputs/overloaded_async_method.h %s -typecheck -verify
|
||||
|
||||
// RUN: %empty-directory(%t)
|
||||
|
||||
// RUN: %gyb %s -o %t/swift_to_c_pointer_conversions.swift
|
||||
|
||||
// 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
|
||||
|
||||
func test_raw_ptr(ptr: UnsafeRawPointer) {
|
||||
char_ptr_func(ptr) // expected-error {{}}
|
||||
unsigned_char_ptr_func(ptr) // expected-error {{}}
|
||||
|
||||
const_char_ptr_func(ptr) // Ok
|
||||
const_unsigned_char_ptr_func(ptr) // Ok
|
||||
|
||||
% for Size in ['16', '32', '64']:
|
||||
int_${Size}_ptr_func(ptr) // expected-error {{}}
|
||||
uint_${Size}_ptr_func(ptr) // expected-error {{}}
|
||||
|
||||
const_int_${Size}_ptr_func(ptr) // expected-error {{}}
|
||||
const_uint_${Size}_ptr_func(ptr) // expected-error {{}}
|
||||
% end
|
||||
}
|
||||
|
||||
func test_mutable_raw_pointer(ptr: UnsafeMutableRawPointer) {
|
||||
char_ptr_func(ptr) // Ok
|
||||
unsigned_char_ptr_func(ptr) // Ok
|
||||
|
||||
const_char_ptr_func(ptr) // Ok
|
||||
const_unsigned_char_ptr_func(ptr) // Ok
|
||||
|
||||
% for Size in ['16', '32', '64']:
|
||||
int_${Size}_ptr_func(ptr) // expected-error {{}}
|
||||
uint_${Size}_ptr_func(ptr) // expected-error {{}}
|
||||
|
||||
const_int_${Size}_ptr_func(ptr) // expected-error {{}}
|
||||
const_uint_${Size}_ptr_func(ptr) // expected-error {{}}
|
||||
% end
|
||||
}
|
||||
|
||||
%for TestPtrSize in ['16', '32', '64']:
|
||||
// Immutable pointers can be converted only to their immutable (regardless of sign) counterparts.
|
||||
func test_${TestPtrSize}_bit_ptrs(sptr: UnsafePointer<Int${TestPtrSize}>,
|
||||
uptr: UnsafePointer<UInt${TestPtrSize}>) {
|
||||
char_ptr_func(sptr) // expected-error {{}}
|
||||
char_ptr_func(uptr) // expected-error {{}}
|
||||
|
||||
const_char_ptr_func(sptr) // Ok
|
||||
const_char_ptr_func(uptr) // Ok
|
||||
|
||||
unsigned_char_ptr_func(sptr) // expected-error {{}}
|
||||
unsigned_char_ptr_func(uptr) // expected-error {{}}
|
||||
|
||||
const_unsigned_char_ptr_func(sptr) // Ok
|
||||
const_unsigned_char_ptr_func(uptr) // Ok
|
||||
|
||||
% for pointer in ['sptr', 'uptr']:
|
||||
% for Size in ['16', '32', '64']:
|
||||
|
||||
% if Size == TestPtrSize:
|
||||
int_${TestPtrSize}_ptr_func(${pointer}) // expected-error {{}}
|
||||
uint_${TestPtrSize}_ptr_func(${pointer}) // expected-error {{}}
|
||||
|
||||
const_int_${TestPtrSize}_ptr_func(${pointer}) // Ok
|
||||
const_uint_${TestPtrSize}_ptr_func(${pointer}) // Ok
|
||||
% else:
|
||||
int_${Size}_ptr_func(${pointer}) // expected-error {{}}
|
||||
uint_${Size}_ptr_func(${pointer}) // expected-error {{}}
|
||||
|
||||
const_int_${Size}_ptr_func(${pointer}) // expected-error {{}} expected-note {{}}
|
||||
const_uint_${Size}_ptr_func(${pointer}) // expected-error {{}} expected-note {{}}
|
||||
% end
|
||||
% end
|
||||
% end
|
||||
}
|
||||
|
||||
% end
|
||||
|
||||
%for TestPtrSize in ['16', '32', '64']:
|
||||
// Mutable pointers can be converted to both immutable and mutable pointers when
|
||||
// passed to C/ObjC imported functions.
|
||||
func test_mutable_${TestPtrSize}_bit_ptrs(sptr: UnsafeMutablePointer<Int${TestPtrSize}>,
|
||||
uptr: UnsafeMutablePointer<UInt${TestPtrSize}>) {
|
||||
char_ptr_func(sptr) // Ok
|
||||
char_ptr_func(uptr) // Ok
|
||||
|
||||
const_char_ptr_func(sptr) // Ok
|
||||
const_char_ptr_func(uptr) // Ok
|
||||
|
||||
unsigned_char_ptr_func(sptr) // Ok
|
||||
unsigned_char_ptr_func(uptr) // Ok
|
||||
|
||||
const_unsigned_char_ptr_func(sptr) // Ok
|
||||
const_unsigned_char_ptr_func(uptr) // Ok
|
||||
|
||||
% for pointer in ['sptr', 'uptr']:
|
||||
% for Size in ['16', '32', '64']:
|
||||
|
||||
% if Size == TestPtrSize:
|
||||
int_${TestPtrSize}_ptr_func(${pointer}) // Ok
|
||||
uint_${TestPtrSize}_ptr_func(${pointer}) // Ok
|
||||
|
||||
const_int_${TestPtrSize}_ptr_func(${pointer}) // Ok
|
||||
const_uint_${TestPtrSize}_ptr_func(${pointer}) // Ok
|
||||
% else:
|
||||
int_${Size}_ptr_func(${pointer}) // expected-error {{}} expected-note {{}}
|
||||
uint_${Size}_ptr_func(${pointer}) // expected-error {{}} expected-note {{}}
|
||||
|
||||
const_int_${Size}_ptr_func(${pointer}) // expected-error {{}} expected-note {{}}
|
||||
const_uint_${Size}_ptr_func(${pointer}) // expected-error {{}} expected-note {{}}
|
||||
% end
|
||||
% end
|
||||
% end
|
||||
}
|
||||
|
||||
% end
|
||||
Reference in New Issue
Block a user