Skip to content

Commit

Permalink
cfg out checks in add and sub but not offset
Browse files Browse the repository at this point in the history
...because the checks in offset found bugs in a crater run.
  • Loading branch information
saethlin committed Oct 7, 2024
1 parent 8293e74 commit 9ca739e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions core/src/ptr/const_ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -887,6 +887,7 @@ impl<T: ?Sized> *const T {
where
T: Sized,
{
#[cfg(debug_assertions)]
#[inline]
const fn runtime_add_nowrap(this: *const (), count: usize, size: usize) -> bool {
#[inline]
Expand All @@ -905,6 +906,7 @@ impl<T: ?Sized> *const T {
intrinsics::const_eval_select((this, count, size), comptime, runtime)
}

#[cfg(debug_assertions)] // Expensive, and doesn't catch much in the wild.
ub_checks::assert_unsafe_precondition!(
check_language_ub,
"ptr::add requires that the address calculation does not overflow",
Expand Down Expand Up @@ -993,6 +995,7 @@ impl<T: ?Sized> *const T {
where
T: Sized,
{
#[cfg(debug_assertions)]
#[inline]
const fn runtime_sub_nowrap(this: *const (), count: usize, size: usize) -> bool {
#[inline]
Expand All @@ -1010,6 +1013,7 @@ impl<T: ?Sized> *const T {
intrinsics::const_eval_select((this, count, size), comptime, runtime)
}

#[cfg(debug_assertions)] // Expensive, and doesn't catch much in the wild.
ub_checks::assert_unsafe_precondition!(
check_language_ub,
"ptr::sub requires that the address calculation does not overflow",
Expand Down
4 changes: 4 additions & 0 deletions core/src/ptr/mut_ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -971,6 +971,7 @@ impl<T: ?Sized> *mut T {
where
T: Sized,
{
#[cfg(debug_assertions)]
#[inline]
const fn runtime_add_nowrap(this: *const (), count: usize, size: usize) -> bool {
#[inline]
Expand All @@ -989,6 +990,7 @@ impl<T: ?Sized> *mut T {
intrinsics::const_eval_select((this, count, size), comptime, runtime)
}

#[cfg(debug_assertions)] // Expensive, and doesn't catch much in the wild.
ub_checks::assert_unsafe_precondition!(
check_language_ub,
"ptr::add requires that the address calculation does not overflow",
Expand Down Expand Up @@ -1077,6 +1079,7 @@ impl<T: ?Sized> *mut T {
where
T: Sized,
{
#[cfg(debug_assertions)]
#[inline]
const fn runtime_sub_nowrap(this: *const (), count: usize, size: usize) -> bool {
#[inline]
Expand All @@ -1094,6 +1097,7 @@ impl<T: ?Sized> *mut T {
intrinsics::const_eval_select((this, count, size), comptime, runtime)
}

#[cfg(debug_assertions)] // Expensive, and doesn't catch much in the wild.
ub_checks::assert_unsafe_precondition!(
check_language_ub,
"ptr::sub requires that the address calculation does not overflow",
Expand Down

0 comments on commit 9ca739e

Please sign in to comment.