Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 1a427d7

Browse files
committed
implemented checks for size_t, ssize_t, ptrdiff_t, & schar_t
1 parent 98ae709 commit 1a427d7

File tree

2 files changed

+77
-1
lines changed

2 files changed

+77
-1
lines changed

tests/run-make/core-ffi-typecheck-clang/rmake.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
//@ needs-force-clang-based-tests
21
// This test checks that the clang defines for each target allign with the core ffi types defined in
32
// mod.rs. Therefore each rust target is queried and the clang defines for each target are read and
43
// compared to the core sizes to verify all types and sizes allign at buildtime.
@@ -101,6 +100,8 @@ fn main() {
101100
const CLANG_C_LONGLONG_SIZE: usize = {};
102101
const CLANG_C_FLOAT_SIZE: usize = {};
103102
const CLANG_C_DOUBLE_SIZE: usize = {};
103+
const CLANG_C_SIZE_T_SIZE: usize = {};
104+
const CLANG_C_PTRDIFF_T_SIZE: usize = {};
104105
",
105106
parse_size(&defines, "CHAR"),
106107
char_is_signed(&defines),
@@ -110,6 +111,8 @@ fn main() {
110111
parse_size(&defines, "LONG_LONG"),
111112
parse_size(&defines, "FLOAT"),
112113
parse_size(&defines, "DOUBLE"),
114+
parse_size(&defines, "SIZE_T"),
115+
parse_size(&defines, "PTRDIFF_T"),
113116
));
114117

115118
// Generate a target-specific rmake file.

tests/run-make/core-ffi-typecheck-clang/tests.rs

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,54 @@ cfg_if! {
6363
}
6464
}
6565

66+
// Verify Rust's 'c_size_t' is correct
67+
cfg_if! {
68+
if #[cfg(all(target_arch = "aarch64", target_abi = "ilp32"))] {
69+
// FIXME: size_t is not short enough on aarch64 ilp32, should be 4, defaulting to 8
70+
const XFAIL_C_SIZE_T_SIZE: usize = 4;
71+
pub const TEST_C_SIZE_T_SIZE: () = if size_of::<ffi::c_size_t>() != XFAIL_C_SIZE_T_SIZE {
72+
panic!("wrong c_size_t size, target_arch: aarch64, target_abi: ilp32");
73+
};
74+
}
75+
else {
76+
pub const TEST_C_SIZE_T_SIZE: () = if size_of::<ffi::c_size_t>() != CLANG_C_SIZE_T_SIZE {
77+
panic!("wrong c_size_t size");
78+
};
79+
}
80+
}
81+
82+
// Verify Rust's 'c_ssize_t' is correct
83+
cfg_if! {
84+
if #[cfg(all(target_arch = "aarch64", target_abi = "ilp32"))] {
85+
// FIXME: ssize_t is not short enough on aarch64 ilp32, should be 4, defaulting to 8
86+
const XFAIL_C_SSIZE_T_SIZE: usize = 4;
87+
pub const TEST_C_SSIZE_T_SIZE: () = if size_of::<ffi::c_ssize_t>() != XFAIL_C_SSIZE_T_SIZE {
88+
panic!("wrong c_ssize_t size, target_arch: aarch64, target_abi: ilp32");
89+
};
90+
}
91+
else {
92+
pub const TEST_C_SSIZE_T_SIZE: () = if size_of::<ffi::c_ssize_t>() != CLANG_C_SIZE_T_SIZE {
93+
panic!("wrong c_size_t size");
94+
};
95+
}
96+
}
97+
98+
// Verify Rust's 'c_ptrdiff_t' is correct
99+
cfg_if! {
100+
if #[cfg(all(target_arch = "aarch64", target_abi = "ilp32"))] {
101+
// FIXME: c_ptrdiff_t is not short enough on aarch64 ilp32, should be 4, defaulting to 8
102+
const XFAIL_C_PTRDIFF_T_SIZE: usize = 4;
103+
pub const TEST_C_PTRDIFF_T_SIZE: () = if size_of::<ffi::c_ptrdiff_t>() != XFAIL_C_PTRDIFF_T_SIZE {
104+
panic!("wrong c_ssize_t size, target_arch: aarch64, target_abi: ilp32");
105+
};
106+
}
107+
else {
108+
pub const TEST_C_PTRDIFF_T_SIZE: () = if size_of::<ffi::c_ptrdiff_t>() != CLANG_C_PTRDIFF_T_SIZE {
109+
panic!("wrong c_size_t size");
110+
};
111+
}
112+
}
113+
66114
impl Signed for i8 {
67115
const SIGNED: bool = true;
68116
}
@@ -95,3 +143,28 @@ pub const TEST_C_LONGLONG_SIZE: () = if size_of::<ffi::c_longlong>() != CLANG_C_
95143
pub const TEST_C_FLOAT_SIZE: () = if size_of::<ffi::c_float>() != CLANG_C_FLOAT_SIZE {
96144
panic!("wrong c_float size");
97145
};
146+
147+
//c_schar size
148+
pub const TEST_C_SCHAR_SIZE: () = if size_of::<ffi::c_schar>() != CLANG_C_CHAR_SIZE {
149+
panic!("wrong c_schar size");
150+
};
151+
152+
//c_uchar size
153+
pub const TEST_C_UCHAR_SIZE: () = if size_of::<ffi::c_uchar>() != CLANG_C_CHAR_SIZE {
154+
panic!("wrong c_uchar size");
155+
};
156+
157+
//c_uint size
158+
pub const TEST_C_UINT_SIZE: () = if size_of::<ffi::c_int>() != CLANG_C_INT_SIZE {
159+
panic!("mismatched c_uint size");
160+
};
161+
162+
//c_ushort size
163+
pub const TEST_C_USHORT_SIZE: () = if size_of::<ffi::c_short>() != CLANG_C_SHORT_SIZE {
164+
panic!("wrong c_ushort size");
165+
};
166+
167+
//c_ulonglong size
168+
pub const TEST_C_ULONGLONG_SIZE: () = if size_of::<ffi::c_ulonglong>() != CLANG_C_LONGLONG_SIZE {
169+
panic!("wrong c_ulonglong size");
170+
};

0 commit comments

Comments
 (0)