Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit ee9b057

Browse files
committedOct 7, 2024·
cfg out checks in add and sub but not offset
...because the checks in offset found bugs in a crater run.
1 parent c6ec1dd commit ee9b057

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed
 

‎library/core/src/ptr/const_ptr.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -884,6 +884,7 @@ impl<T: ?Sized> *const T {
884884
where
885885
T: Sized,
886886
{
887+
#[cfg(debug_assertions)]
887888
#[inline]
888889
const fn runtime_add_nowrap(this: *const (), count: usize, size: usize) -> bool {
889890
#[inline]
@@ -902,6 +903,7 @@ impl<T: ?Sized> *const T {
902903
intrinsics::const_eval_select((this, count, size), comptime, runtime)
903904
}
904905

906+
#[cfg(debug_assertions)] // Expensive, and doesn't catch much in the wild.
905907
ub_checks::assert_unsafe_precondition!(
906908
check_language_ub,
907909
"ptr::add requires that the address calculation does not overflow",
@@ -987,6 +989,7 @@ impl<T: ?Sized> *const T {
987989
where
988990
T: Sized,
989991
{
992+
#[cfg(debug_assertions)]
990993
#[inline]
991994
const fn runtime_sub_nowrap(this: *const (), count: usize, size: usize) -> bool {
992995
#[inline]
@@ -1004,6 +1007,7 @@ impl<T: ?Sized> *const T {
10041007
intrinsics::const_eval_select((this, count, size), comptime, runtime)
10051008
}
10061009

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

‎library/core/src/ptr/mut_ptr.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -967,6 +967,7 @@ impl<T: ?Sized> *mut T {
967967
where
968968
T: Sized,
969969
{
970+
#[cfg(debug_assertions)]
970971
#[inline]
971972
const fn runtime_add_nowrap(this: *const (), count: usize, size: usize) -> bool {
972973
#[inline]
@@ -985,6 +986,7 @@ impl<T: ?Sized> *mut T {
985986
intrinsics::const_eval_select((this, count, size), comptime, runtime)
986987
}
987988

989+
#[cfg(debug_assertions)] // Expensive, and doesn't catch much in the wild.
988990
ub_checks::assert_unsafe_precondition!(
989991
check_language_ub,
990992
"ptr::add requires that the address calculation does not overflow",
@@ -1070,6 +1072,7 @@ impl<T: ?Sized> *mut T {
10701072
where
10711073
T: Sized,
10721074
{
1075+
#[cfg(debug_assertions)]
10731076
#[inline]
10741077
const fn runtime_sub_nowrap(this: *const (), count: usize, size: usize) -> bool {
10751078
#[inline]
@@ -1087,6 +1090,7 @@ impl<T: ?Sized> *mut T {
10871090
intrinsics::const_eval_select((this, count, size), comptime, runtime)
10881091
}
10891092

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

0 commit comments

Comments
 (0)
Please sign in to comment.