Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions compiler-builtins/src/mem/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>();
Expand Down Expand Up @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions compiler-builtins/src/mem/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down