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 c6ec1dd commit ee9b057
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions library/core/src/ptr/const_ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -884,6 +884,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 @@ -902,6 +903,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 @@ -987,6 +989,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 @@ -1004,6 +1007,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 library/core/src/ptr/mut_ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -967,6 +967,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 @@ -985,6 +986,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 @@ -1070,6 +1072,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 @@ -1087,6 +1090,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 ee9b057

Please sign in to comment.