diff options
| author | Julien THILLARD <54775010+supersurviveur@users.noreply.github.com> | 2025-07-18 20:19:13 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-07-18 18:19:13 +0000 |
| commit | 6b87978169d260ac4512e66c81e9298055b902c2 (patch) | |
| tree | 7ed0604457ca53507552b7d8c5d1d64c09447924 /library/compiler-builtins | |
| parent | 7dacaef5d3c252ea47287ce34234a89e3c5ff57e (diff) | |
| download | rust-6b87978169d260ac4512e66c81e9298055b902c2.tar.gz rust-6b87978169d260ac4512e66c81e9298055b902c2.zip | |
Change the `memcmp` and `bcmp` return type to `c_int`
Fix the return type of `memcmp` and `bcmp` builtin functions on targets with a `c_int` other than `i32`. Linked issue: https://github.com/rust-lang/rust/issues/144076
Diffstat (limited to 'library/compiler-builtins')
| -rw-r--r-- | library/compiler-builtins/compiler-builtins/src/mem/impls.rs | 5 | ||||
| -rw-r--r-- | library/compiler-builtins/compiler-builtins/src/mem/mod.rs | 4 |
2 files changed, 5 insertions, 4 deletions
diff --git a/library/compiler-builtins/compiler-builtins/src/mem/impls.rs b/library/compiler-builtins/compiler-builtins/src/mem/impls.rs index 14a4787485d..da16dee25ce 100644 --- a/library/compiler-builtins/compiler-builtins/src/mem/impls.rs +++ b/library/compiler-builtins/compiler-builtins/src/mem/impls.rs @@ -15,6 +15,7 @@ // this use. Of course this is not a guarantee that such use will work, it just means that this // crate doing wrapping pointer arithmetic with a method that must not wrap won't be the problem if // something does go wrong at runtime. +use core::ffi::c_int; use core::intrinsics::likely; const WORD_SIZE: usize = core::mem::size_of::<usize>(); @@ -384,13 +385,13 @@ pub unsafe fn set_bytes(mut s: *mut u8, c: u8, mut n: usize) { } #[inline(always)] -pub unsafe fn compare_bytes(s1: *const u8, s2: *const u8, n: usize) -> i32 { +pub unsafe fn compare_bytes(s1: *const u8, s2: *const u8, n: usize) -> c_int { let mut i = 0; while i < n { let a = *s1.wrapping_add(i); let b = *s2.wrapping_add(i); if a != b { - return a as i32 - b as i32; + return c_int::from(a) - c_int::from(b); } i += 1; } diff --git a/library/compiler-builtins/compiler-builtins/src/mem/mod.rs b/library/compiler-builtins/compiler-builtins/src/mem/mod.rs index a6f533cb725..a227f60a294 100644 --- a/library/compiler-builtins/compiler-builtins/src/mem/mod.rs +++ b/library/compiler-builtins/compiler-builtins/src/mem/mod.rs @@ -37,12 +37,12 @@ intrinsics! { } #[mem_builtin] - pub unsafe extern "C" fn memcmp(s1: *const u8, s2: *const u8, n: usize) -> i32 { + pub unsafe extern "C" fn memcmp(s1: *const u8, s2: *const u8, n: usize) -> core::ffi::c_int { impls::compare_bytes(s1, s2, n) } #[mem_builtin] - pub unsafe extern "C" fn bcmp(s1: *const u8, s2: *const u8, n: usize) -> i32 { + pub unsafe extern "C" fn bcmp(s1: *const u8, s2: *const u8, n: usize) -> core::ffi::c_int { memcmp(s1, s2, n) } |
