From d5775d7a811139cd0fb8aa942b1bfa879cc895de Mon Sep 17 00:00:00 2001 From: supersurviveur Date: Fri, 18 Jul 2025 19:12:42 +0200 Subject: [PATCH 1/4] Change memcmp and bcmp return type to c_int --- compiler-builtins/src/mem/impls.rs | 4 ++-- compiler-builtins/src/mem/mod.rs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/compiler-builtins/src/mem/impls.rs b/compiler-builtins/src/mem/impls.rs index 14a478748..eedfcdc9a 100644 --- a/compiler-builtins/src/mem/impls.rs +++ b/compiler-builtins/src/mem/impls.rs @@ -384,13 +384,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) -> crate::mem::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 a as crate::mem::c_int - b as crate::mem::c_int; } i += 1; } diff --git a/compiler-builtins/src/mem/mod.rs b/compiler-builtins/src/mem/mod.rs index a6f533cb7..330f349d4 100644 --- a/compiler-builtins/src/mem/mod.rs +++ b/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) -> crate::mem::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) -> crate::mem::c_int { memcmp(s1, s2, n) } From 0963b7cd4a3e9cca6d3a30ce7815e5217bd1183a Mon Sep 17 00:00:00 2001 From: supersurviveur Date: Fri, 18 Jul 2025 19:41:40 +0200 Subject: [PATCH 2/4] Use core::ffi::c_int instead of crate::mem::c_int --- compiler-builtins/src/mem/impls.rs | 4 ++-- compiler-builtins/src/mem/mod.rs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/compiler-builtins/src/mem/impls.rs b/compiler-builtins/src/mem/impls.rs index eedfcdc9a..dd093b701 100644 --- a/compiler-builtins/src/mem/impls.rs +++ b/compiler-builtins/src/mem/impls.rs @@ -384,13 +384,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) -> crate::mem::c_int { +pub unsafe fn compare_bytes(s1: *const u8, s2: *const u8, n: usize) -> core::ffi::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 crate::mem::c_int - b as crate::mem::c_int; + return a as core::ffi::c_int - b as core::ffi::c_int; } i += 1; } diff --git a/compiler-builtins/src/mem/mod.rs b/compiler-builtins/src/mem/mod.rs index 330f349d4..a227f60a2 100644 --- a/compiler-builtins/src/mem/mod.rs +++ b/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) -> crate::mem::c_int { + 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) -> crate::mem::c_int { + pub unsafe extern "C" fn bcmp(s1: *const u8, s2: *const u8, n: usize) -> core::ffi::c_int { memcmp(s1, s2, n) } From c6af92d0e8578cccc9b55b4e448209e399376b03 Mon Sep 17 00:00:00 2001 From: supersurviveur Date: Fri, 18 Jul 2025 19:51:16 +0200 Subject: [PATCH 3/4] Change as cast to From since the conversion is lossless --- compiler-builtins/src/mem/impls.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler-builtins/src/mem/impls.rs b/compiler-builtins/src/mem/impls.rs index dd093b701..e3166c72c 100644 --- a/compiler-builtins/src/mem/impls.rs +++ b/compiler-builtins/src/mem/impls.rs @@ -390,7 +390,7 @@ pub unsafe fn compare_bytes(s1: *const u8, s2: *const u8, n: usize) -> core::ffi let a = *s1.wrapping_add(i); let b = *s2.wrapping_add(i); if a != b { - return a as core::ffi::c_int - b as core::ffi::c_int; + return core::ffi::c_int::from(a) - core::ffi::c_int::from(b); } i += 1; } From afae610d796f47cccdd065f44af49660a480b282 Mon Sep 17 00:00:00 2001 From: supersurviveur Date: Fri, 18 Jul 2025 19:58:14 +0200 Subject: [PATCH 4/4] Import core::ffi::c_int --- compiler-builtins/src/mem/impls.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/compiler-builtins/src/mem/impls.rs b/compiler-builtins/src/mem/impls.rs index e3166c72c..da16dee25 100644 --- a/compiler-builtins/src/mem/impls.rs +++ b/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::(); @@ -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) -> core::ffi::c_int { +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 core::ffi::c_int::from(a) - core::ffi::c_int::from(b); + return c_int::from(a) - c_int::from(b); } i += 1; }