From 9ca739e65a6f8269898d178c6371b1d6b96948ee Mon Sep 17 00:00:00 2001 From: Ben Kimock Date: Sun, 6 Oct 2024 23:36:22 -0400 Subject: [PATCH] cfg out checks in add and sub but not offset ...because the checks in offset found bugs in a crater run. --- core/src/ptr/const_ptr.rs | 4 ++++ core/src/ptr/mut_ptr.rs | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/core/src/ptr/const_ptr.rs b/core/src/ptr/const_ptr.rs index 4727dc77d18d4..c9af7f13e46c4 100644 --- a/core/src/ptr/const_ptr.rs +++ b/core/src/ptr/const_ptr.rs @@ -887,6 +887,7 @@ impl *const T { where T: Sized, { + #[cfg(debug_assertions)] #[inline] const fn runtime_add_nowrap(this: *const (), count: usize, size: usize) -> bool { #[inline] @@ -905,6 +906,7 @@ impl *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", @@ -993,6 +995,7 @@ impl *const T { where T: Sized, { + #[cfg(debug_assertions)] #[inline] const fn runtime_sub_nowrap(this: *const (), count: usize, size: usize) -> bool { #[inline] @@ -1010,6 +1013,7 @@ impl *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", diff --git a/core/src/ptr/mut_ptr.rs b/core/src/ptr/mut_ptr.rs index 8dbce1fdb984e..e458bb4642fc6 100644 --- a/core/src/ptr/mut_ptr.rs +++ b/core/src/ptr/mut_ptr.rs @@ -971,6 +971,7 @@ impl *mut T { where T: Sized, { + #[cfg(debug_assertions)] #[inline] const fn runtime_add_nowrap(this: *const (), count: usize, size: usize) -> bool { #[inline] @@ -989,6 +990,7 @@ impl *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", @@ -1077,6 +1079,7 @@ impl *mut T { where T: Sized, { + #[cfg(debug_assertions)] #[inline] const fn runtime_sub_nowrap(this: *const (), count: usize, size: usize) -> bool { #[inline] @@ -1094,6 +1097,7 @@ impl *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",