From 949d1f9592d86290e0c0dd2ce8485c347f40d65d Mon Sep 17 00:00:00 2001 From: ltdk Date: Wed, 1 Nov 2023 14:28:55 -0400 Subject: [PATCH] Add debug_assert_nounwrap to unchecked_{add,sub,neg,mul,shl,shr} methods --- library/core/src/num/int_macros.rs | 79 +++++++++++++------ library/core/src/num/mod.rs | 1 + library/core/src/num/uint_macros.rs | 68 +++++++++++----- library/core/src/ops/index_range.rs | 11 ++- library/core/src/panic.rs | 2 +- library/core/src/ptr/const_ptr.rs | 7 +- library/core/src/ptr/mut_ptr.rs | 7 +- library/core/src/ptr/non_null.rs | 7 +- library/core/src/slice/index.rs | 5 +- .../pass/shims/time-with-isolation2.stdout | 2 +- ...hl_unsigned_bigger.Inline.panic-abort.diff | 36 +++++++-- ...l_unsigned_bigger.Inline.panic-unwind.diff | 36 +++++++-- ...ed_bigger.PreCodegen.after.panic-abort.mir | 31 +++++++- ...d_bigger.PreCodegen.after.panic-unwind.mir | 31 +++++++- ...l_unsigned_smaller.Inline.panic-abort.diff | 40 ++++++++-- ..._unsigned_smaller.Inline.panic-unwind.diff | 40 ++++++++-- ...d_smaller.PreCodegen.after.panic-abort.mir | 39 +++++++-- ..._smaller.PreCodegen.after.panic-unwind.mir | 39 +++++++-- ..._shr_signed_bigger.Inline.panic-abort.diff | 36 +++++++-- ...shr_signed_bigger.Inline.panic-unwind.diff | 36 +++++++-- ...ed_bigger.PreCodegen.after.panic-abort.mir | 31 +++++++- ...d_bigger.PreCodegen.after.panic-unwind.mir | 31 +++++++- ...shr_signed_smaller.Inline.panic-abort.diff | 40 ++++++++-- ...hr_signed_smaller.Inline.panic-unwind.diff | 40 ++++++++-- ...d_smaller.PreCodegen.after.panic-abort.mir | 39 +++++++-- ..._smaller.PreCodegen.after.panic-unwind.mir | 39 +++++++-- ...ecked_ops.checked_shl.PreCodegen.after.mir | 8 +- 27 files changed, 620 insertions(+), 161 deletions(-) diff --git a/library/core/src/num/int_macros.rs b/library/core/src/num/int_macros.rs index fa37ee4ffb204..8bae9f1e1a4f2 100644 --- a/library/core/src/num/int_macros.rs +++ b/library/core/src/num/int_macros.rs @@ -510,9 +510,14 @@ macro_rules! int_impl { #[inline(always)] #[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces pub const unsafe fn unchecked_add(self, rhs: Self) -> Self { - // SAFETY: the caller must uphold the safety contract for - // `unchecked_add`. - unsafe { intrinsics::unchecked_add(self, rhs) } + debug_assert_nounwind!( + !self.overflowing_add(rhs).1, + concat!(stringify!($SelfT), "::unchecked_add cannot overflow"), + ); + // SAFETY: this is guaranteed to be safe by the caller. + unsafe { + intrinsics::unchecked_add(self, rhs) + } } /// Checked addition with an unsigned integer. Computes `self + rhs`, @@ -648,9 +653,14 @@ macro_rules! int_impl { #[inline(always)] #[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces pub const unsafe fn unchecked_sub(self, rhs: Self) -> Self { - // SAFETY: the caller must uphold the safety contract for - // `unchecked_sub`. - unsafe { intrinsics::unchecked_sub(self, rhs) } + debug_assert_nounwind!( + !self.overflowing_sub(rhs).1, + concat!(stringify!($SelfT), "::unchecked_sub cannot overflow"), + ); + // SAFETY: this is guaranteed to be safe by the caller. + unsafe { + intrinsics::unchecked_sub(self, rhs) + } } /// Checked subtraction with an unsigned integer. Computes `self - rhs`, @@ -786,9 +796,14 @@ macro_rules! int_impl { #[inline(always)] #[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces pub const unsafe fn unchecked_mul(self, rhs: Self) -> Self { - // SAFETY: the caller must uphold the safety contract for - // `unchecked_mul`. - unsafe { intrinsics::unchecked_mul(self, rhs) } + debug_assert_nounwind!( + !self.overflowing_mul(rhs).1, + concat!(stringify!($SelfT), "::unchecked_mul cannot overflow"), + ); + // SAFETY: this is guaranteed to be safe by the caller. + unsafe { + intrinsics::unchecked_mul(self, rhs) + } } /// Checked integer division. Computes `self / rhs`, returning `None` if `rhs == 0` @@ -1125,9 +1140,15 @@ macro_rules! int_impl { #[inline(always)] #[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces pub const unsafe fn unchecked_neg(self) -> Self { - // SAFETY: the caller must uphold the safety contract for - // `unchecked_neg`. - unsafe { intrinsics::unchecked_sub(0, self) } + debug_assert_nounwind!( + !self.overflowing_neg().1, + concat!(stringify!($SelfT), "::unchecked_neg cannot overflow"), + ); + // SAFETY: this is guaranteed to be safe by the caller. + unsafe { + let n = self; + intrinsics::unchecked_sub(0, n) + } } /// Strict negation. Computes `-self`, panicking if `self == MIN`. @@ -1179,7 +1200,7 @@ macro_rules! int_impl { #[rustc_const_stable(feature = "const_checked_int_methods", since = "1.47.0")] #[must_use = "this returns the result of the operation, \ without modifying the original"] - #[inline] + #[inline(always)] pub const fn checked_shl(self, rhs: u32) -> Option { let (a, b) = self.overflowing_shl(rhs); if unlikely!(b) { None } else { Some(a) } @@ -1241,10 +1262,15 @@ macro_rules! int_impl { #[inline(always)] #[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces pub const unsafe fn unchecked_shl(self, rhs: u32) -> Self { - // SAFETY: the caller must uphold the safety contract for - // `unchecked_shl`. + debug_assert_nounwind!( + rhs < Self::BITS, + concat!(stringify!($SelfT), "::unchecked_shl cannot overflow"), + ); + // SAFETY: this is guaranteed to be safe by the caller. // Any legal shift amount is losslessly representable in the self type. - unsafe { intrinsics::unchecked_shl(self, conv_rhs_for_unchecked_shift!($SelfT, rhs)) } + unsafe { + intrinsics::unchecked_shl(self, conv_rhs_for_unchecked_shift!($SelfT, rhs)) + } } /// Checked shift right. Computes `self >> rhs`, returning `None` if `rhs` is @@ -1262,7 +1288,7 @@ macro_rules! int_impl { #[rustc_const_stable(feature = "const_checked_int_methods", since = "1.47.0")] #[must_use = "this returns the result of the operation, \ without modifying the original"] - #[inline] + #[inline(always)] pub const fn checked_shr(self, rhs: u32) -> Option { let (a, b) = self.overflowing_shr(rhs); if unlikely!(b) { None } else { Some(a) } @@ -1324,10 +1350,15 @@ macro_rules! int_impl { #[inline(always)] #[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces pub const unsafe fn unchecked_shr(self, rhs: u32) -> Self { - // SAFETY: the caller must uphold the safety contract for - // `unchecked_shr`. + debug_assert_nounwind!( + rhs < Self::BITS, + concat!(stringify!($SelfT), "::unchecked_shr cannot overflow"), + ); + // SAFETY: this is guaranteed to be safe by the caller. // Any legal shift amount is losslessly representable in the self type. - unsafe { intrinsics::unchecked_shr(self, conv_rhs_for_unchecked_shift!($SelfT, rhs)) } + unsafe { + intrinsics::unchecked_shr(self, conv_rhs_for_unchecked_shift!($SelfT, rhs)) + } } /// Checked absolute value. Computes `self.abs()`, returning `None` if @@ -1991,7 +2022,9 @@ macro_rules! int_impl { // SAFETY: the masking by the bitsize of the type ensures that we do not shift // out of bounds unsafe { - self.unchecked_shl(rhs & (Self::BITS - 1)) + // FIXME: we can't optimize out the extra check here, + // so, we can't just call the method for now + intrinsics::unchecked_shl(self, conv_rhs_for_unchecked_shift!($SelfT, rhs & (Self::BITS - 1))) } } @@ -2021,7 +2054,9 @@ macro_rules! int_impl { // SAFETY: the masking by the bitsize of the type ensures that we do not shift // out of bounds unsafe { - self.unchecked_shr(rhs & (Self::BITS - 1)) + // FIXME: we can't optimize out the extra check here, + // so, we can't just call the method for now + intrinsics::unchecked_shr(self, conv_rhs_for_unchecked_shift!($SelfT, rhs & (Self::BITS - 1))) } } diff --git a/library/core/src/num/mod.rs b/library/core/src/num/mod.rs index 03c977abbbb42..9c5cab4f26a71 100644 --- a/library/core/src/num/mod.rs +++ b/library/core/src/num/mod.rs @@ -7,6 +7,7 @@ use crate::hint; use crate::intrinsics; use crate::mem; use crate::ops::{Add, Mul, Sub}; +use crate::panic::debug_assert_nounwind; use crate::str::FromStr; // Used because the `?` operator is not allowed in a const context. diff --git a/library/core/src/num/uint_macros.rs b/library/core/src/num/uint_macros.rs index f2f29e4ad8194..984e5ef801515 100644 --- a/library/core/src/num/uint_macros.rs +++ b/library/core/src/num/uint_macros.rs @@ -518,9 +518,15 @@ macro_rules! uint_impl { #[inline(always)] #[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces pub const unsafe fn unchecked_add(self, rhs: Self) -> Self { - // SAFETY: the caller must uphold the safety contract for - // `unchecked_add`. - unsafe { intrinsics::unchecked_add(self, rhs) } + debug_assert_nounwind!( + !self.overflowing_add(rhs).1, + concat!(stringify!($SelfT), "::unchecked_add cannot overflow"), + ); + + // SAFETY: this is guaranteed to be safe by the caller. + unsafe { + intrinsics::unchecked_add(self, rhs) + } } /// Checked addition with a signed integer. Computes `self + rhs`, @@ -662,9 +668,14 @@ macro_rules! uint_impl { #[inline(always)] #[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces pub const unsafe fn unchecked_sub(self, rhs: Self) -> Self { - // SAFETY: the caller must uphold the safety contract for - // `unchecked_sub`. - unsafe { intrinsics::unchecked_sub(self, rhs) } + debug_assert_nounwind!( + !self.overflowing_sub(rhs).1, + concat!(stringify!($SelfT), "::unchecked_sub cannot overflow"), + ); + // SAFETY: this is guaranteed to be safe by the caller. + unsafe { + intrinsics::unchecked_sub(self, rhs) + } } /// Checked integer multiplication. Computes `self * rhs`, returning @@ -744,9 +755,14 @@ macro_rules! uint_impl { #[inline(always)] #[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces pub const unsafe fn unchecked_mul(self, rhs: Self) -> Self { - // SAFETY: the caller must uphold the safety contract for - // `unchecked_mul`. - unsafe { intrinsics::unchecked_mul(self, rhs) } + debug_assert_nounwind!( + !self.overflowing_mul(rhs).1, + concat!(stringify!($SelfT), "::unchecked_mul cannot overflow"), + ); + // SAFETY: this is guaranteed to be safe by the caller. + unsafe { + intrinsics::unchecked_mul(self, rhs) + } } /// Checked integer division. Computes `self / rhs`, returning `None` @@ -1239,7 +1255,7 @@ macro_rules! uint_impl { #[rustc_const_stable(feature = "const_checked_int_methods", since = "1.47.0")] #[must_use = "this returns the result of the operation, \ without modifying the original"] - #[inline] + #[inline(always)] pub const fn checked_shl(self, rhs: u32) -> Option { let (a, b) = self.overflowing_shl(rhs); if unlikely!(b) { None } else { Some(a) } @@ -1301,10 +1317,15 @@ macro_rules! uint_impl { #[inline(always)] #[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces pub const unsafe fn unchecked_shl(self, rhs: u32) -> Self { - // SAFETY: the caller must uphold the safety contract for - // `unchecked_shl`. + debug_assert_nounwind!( + rhs < Self::BITS, + concat!(stringify!($SelfT), "::unchecked_shl cannot overflow"), + ); + // SAFETY: this is guaranteed to be safe by the caller. // Any legal shift amount is losslessly representable in the self type. - unsafe { intrinsics::unchecked_shl(self, conv_rhs_for_unchecked_shift!($SelfT, rhs)) } + unsafe { + intrinsics::unchecked_shl(self, conv_rhs_for_unchecked_shift!($SelfT, rhs)) + } } /// Checked shift right. Computes `self >> rhs`, returning `None` @@ -1322,7 +1343,7 @@ macro_rules! uint_impl { #[rustc_const_stable(feature = "const_checked_int_methods", since = "1.47.0")] #[must_use = "this returns the result of the operation, \ without modifying the original"] - #[inline] + #[inline(always)] pub const fn checked_shr(self, rhs: u32) -> Option { let (a, b) = self.overflowing_shr(rhs); if unlikely!(b) { None } else { Some(a) } @@ -1384,10 +1405,15 @@ macro_rules! uint_impl { #[inline(always)] #[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces pub const unsafe fn unchecked_shr(self, rhs: u32) -> Self { - // SAFETY: the caller must uphold the safety contract for - // `unchecked_shr`. + debug_assert_nounwind!( + rhs < Self::BITS, + concat!(stringify!($SelfT), "::unchecked_shr cannot overflow"), + ); + // SAFETY: this is guaranteed to be safe by the caller. // Any legal shift amount is losslessly representable in the self type. - unsafe { intrinsics::unchecked_shr(self, conv_rhs_for_unchecked_shift!($SelfT, rhs)) } + unsafe { + intrinsics::unchecked_shr(self, conv_rhs_for_unchecked_shift!($SelfT, rhs)) + } } /// Checked exponentiation. Computes `self.pow(exp)`, returning `None` if @@ -1878,7 +1904,9 @@ macro_rules! uint_impl { // SAFETY: the masking by the bitsize of the type ensures that we do not shift // out of bounds unsafe { - self.unchecked_shl(rhs & (Self::BITS - 1)) + // FIXME: we can't optimize out the extra check here, + // so, we can't just call the method for now + intrinsics::unchecked_shl(self, conv_rhs_for_unchecked_shift!($SelfT, rhs & (Self::BITS - 1))) } } @@ -1911,7 +1939,9 @@ macro_rules! uint_impl { // SAFETY: the masking by the bitsize of the type ensures that we do not shift // out of bounds unsafe { - self.unchecked_shr(rhs & (Self::BITS - 1)) + // FIXME: we can't optimize out the extra check here, + // so, we can't just call the method for now + intrinsics::unchecked_shr(self, conv_rhs_for_unchecked_shift!($SelfT, rhs & (Self::BITS - 1))) } } diff --git a/library/core/src/ops/index_range.rs b/library/core/src/ops/index_range.rs index 07ea2e930d57a..229f238439b30 100644 --- a/library/core/src/ops/index_range.rs +++ b/library/core/src/ops/index_range.rs @@ -1,4 +1,3 @@ -use crate::intrinsics::{unchecked_add, unchecked_sub}; use crate::iter::{FusedIterator, TrustedLen}; use crate::num::NonZero; @@ -44,7 +43,7 @@ impl IndexRange { #[inline] pub const fn len(&self) -> usize { // SAFETY: By invariant, this cannot wrap - unsafe { unchecked_sub(self.end, self.start) } + unsafe { self.end.unchecked_sub(self.start) } } /// # Safety @@ -55,7 +54,7 @@ impl IndexRange { let value = self.start; // SAFETY: The range isn't empty, so this cannot overflow - self.start = unsafe { unchecked_add(value, 1) }; + self.start = unsafe { value.unchecked_add(1) }; value } @@ -66,7 +65,7 @@ impl IndexRange { debug_assert!(self.start < self.end); // SAFETY: The range isn't empty, so this cannot overflow - let value = unsafe { unchecked_sub(self.end, 1) }; + let value = unsafe { self.end.unchecked_sub(1) }; self.end = value; value } @@ -81,7 +80,7 @@ impl IndexRange { let mid = if n <= self.len() { // SAFETY: We just checked that this will be between start and end, // and thus the addition cannot overflow. - unsafe { unchecked_add(self.start, n) } + unsafe { self.start.unchecked_add(n) } } else { self.end }; @@ -100,7 +99,7 @@ impl IndexRange { let mid = if n <= self.len() { // SAFETY: We just checked that this will be between start and end, // and thus the addition cannot overflow. - unsafe { unchecked_sub(self.end, n) } + unsafe { self.end.unchecked_sub(n) } } else { self.start }; diff --git a/library/core/src/panic.rs b/library/core/src/panic.rs index 2bd42a4a8cadc..f6aec472a922a 100644 --- a/library/core/src/panic.rs +++ b/library/core/src/panic.rs @@ -167,7 +167,7 @@ pub macro debug_assert_nounwind { } } }, - ($cond:expr, $message:expr) => { + ($cond:expr, $message:expr $(,)?) => { if $crate::intrinsics::debug_assertions() { if !$cond { $crate::panicking::panic_nounwind($message); diff --git a/library/core/src/ptr/const_ptr.rs b/library/core/src/ptr/const_ptr.rs index 85a56d37ab75c..2ad502fde2e33 100644 --- a/library/core/src/ptr/const_ptr.rs +++ b/library/core/src/ptr/const_ptr.rs @@ -1021,8 +1021,8 @@ impl *const T { #[must_use = "returns a new pointer rather than modifying its argument"] #[rustc_const_stable(feature = "const_ptr_offset", since = "1.61.0")] // We could always go back to wrapping if unchecked becomes unacceptable - #[rustc_allow_const_fn_unstable(const_int_unchecked_arith)] #[inline(always)] + #[rustc_allow_const_fn_unstable(unchecked_math)] #[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces pub const unsafe fn sub(self, count: usize) -> Self where @@ -1035,7 +1035,10 @@ impl *const T { // SAFETY: the caller must uphold the safety contract for `offset`. // Because the pointee is *not* a ZST, that means that `count` is // at most `isize::MAX`, and thus the negation cannot overflow. - unsafe { self.offset(intrinsics::unchecked_sub(0, count as isize)) } + // FIXME: replacing unchecked_sub with unchecked_neg and replacing the + // unchecked_math flag with unchecked_neg will anger the UnstableInStable lint + // and I cannot for the life of me understand why + unsafe { self.offset(0isize.unchecked_sub(count as isize)) } } } diff --git a/library/core/src/ptr/mut_ptr.rs b/library/core/src/ptr/mut_ptr.rs index 28ba26f5c16c4..4cf1203885cd8 100644 --- a/library/core/src/ptr/mut_ptr.rs +++ b/library/core/src/ptr/mut_ptr.rs @@ -1121,7 +1121,7 @@ impl *mut T { #[must_use = "returns a new pointer rather than modifying its argument"] #[rustc_const_stable(feature = "const_ptr_offset", since = "1.61.0")] // We could always go back to wrapping if unchecked becomes unacceptable - #[rustc_allow_const_fn_unstable(const_int_unchecked_arith)] + #[rustc_allow_const_fn_unstable(unchecked_math)] #[inline(always)] #[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces pub const unsafe fn sub(self, count: usize) -> Self @@ -1135,7 +1135,10 @@ impl *mut T { // SAFETY: the caller must uphold the safety contract for `offset`. // Because the pointee is *not* a ZST, that means that `count` is // at most `isize::MAX`, and thus the negation cannot overflow. - unsafe { self.offset(intrinsics::unchecked_sub(0, count as isize)) } + // FIXME: replacing unchecked_sub with unchecked_neg and replacing the + // unchecked_math flag with unchecked_neg will anger the UnstableInStable lint + // and I cannot for the life of me understand why + unsafe { self.offset(0isize.unchecked_sub(count as isize)) } } } diff --git a/library/core/src/ptr/non_null.rs b/library/core/src/ptr/non_null.rs index acb8c552a6338..1e7a363851c6d 100644 --- a/library/core/src/ptr/non_null.rs +++ b/library/core/src/ptr/non_null.rs @@ -702,7 +702,7 @@ impl NonNull { #[rustc_const_unstable(feature = "non_null_convenience", issue = "117691")] #[must_use = "returns a new pointer rather than modifying its argument"] // We could always go back to wrapping if unchecked becomes unacceptable - #[rustc_allow_const_fn_unstable(const_int_unchecked_arith)] + #[rustc_allow_const_fn_unstable(unchecked_math)] #[inline(always)] #[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces pub const unsafe fn sub(self, count: usize) -> Self @@ -716,7 +716,10 @@ impl NonNull { // SAFETY: the caller must uphold the safety contract for `offset`. // Because the pointee is *not* a ZST, that means that `count` is // at most `isize::MAX`, and thus the negation cannot overflow. - unsafe { self.offset(intrinsics::unchecked_sub(0, count as isize)) } + // FIXME: replacing unchecked_sub with unchecked_neg and replacing the + // unchecked_math flag with unchecked_neg will anger the UnstableInStable lint + // and I cannot for the life of me understand why + unsafe { self.offset(0isize.unchecked_sub(count as isize)) } } } diff --git a/library/core/src/slice/index.rs b/library/core/src/slice/index.rs index 0e2d45c4ada6d..e258a2de4780c 100644 --- a/library/core/src/slice/index.rs +++ b/library/core/src/slice/index.rs @@ -1,7 +1,6 @@ //! Indexing implementations for `[T]`. use crate::intrinsics::const_eval_select; -use crate::intrinsics::unchecked_sub; use crate::ops; use crate::panic::debug_assert_nounwind; use crate::ptr; @@ -372,7 +371,7 @@ unsafe impl SliceIndex<[T]> for ops::Range { // `self` is in bounds of `slice` so `self` cannot overflow an `isize`, // so the call to `add` is safe and the length calculation cannot overflow. unsafe { - let new_len = unchecked_sub(self.end, self.start); + let new_len = self.end.unchecked_sub(self.start); ptr::slice_from_raw_parts(slice.as_ptr().add(self.start), new_len) } } @@ -385,7 +384,7 @@ unsafe impl SliceIndex<[T]> for ops::Range { ); // SAFETY: see comments for `get_unchecked` above. unsafe { - let new_len = unchecked_sub(self.end, self.start); + let new_len = self.end.unchecked_sub(self.start); ptr::slice_from_raw_parts_mut(slice.as_mut_ptr().add(self.start), new_len) } } diff --git a/src/tools/miri/tests/pass/shims/time-with-isolation2.stdout b/src/tools/miri/tests/pass/shims/time-with-isolation2.stdout index c68b40b744bf2..68cd00889f03a 100644 --- a/src/tools/miri/tests/pass/shims/time-with-isolation2.stdout +++ b/src/tools/miri/tests/pass/shims/time-with-isolation2.stdout @@ -1 +1 @@ -The loop took around 7s +The loop took around 8s diff --git a/tests/mir-opt/inline/unchecked_shifts.unchecked_shl_unsigned_bigger.Inline.panic-abort.diff b/tests/mir-opt/inline/unchecked_shifts.unchecked_shl_unsigned_bigger.Inline.panic-abort.diff index 1ab1d01e5faca..51ca1187d917f 100644 --- a/tests/mir-opt/inline/unchecked_shifts.unchecked_shl_unsigned_bigger.Inline.panic-abort.diff +++ b/tests/mir-opt/inline/unchecked_shifts.unchecked_shl_unsigned_bigger.Inline.panic-abort.diff @@ -10,7 +10,10 @@ + scope 1 (inlined core::num::::unchecked_shl) { + debug self => _3; + debug rhs => _4; -+ let mut _5: u64; ++ let mut _5: bool; ++ let mut _6: bool; ++ let _7: !; ++ let mut _8: u64; + scope 2 { + } + } @@ -21,13 +24,34 @@ StorageLive(_4); _4 = _2; - _0 = core::num::::unchecked_shl(move _3, move _4) -> [return: bb1, unwind unreachable]; -- } -- -- bb1: { ++ StorageLive(_7); + StorageLive(_5); -+ _5 = _4 as u64 (IntToInt); -+ _0 = ShlUnchecked(_3, move _5); ++ _5 = cfg!(debug_assertions); ++ switchInt(move _5) -> [0: bb4, otherwise: bb1]; + } + + bb1: { ++ StorageLive(_6); ++ _6 = Lt(_4, const _); ++ switchInt(move _6) -> [0: bb3, otherwise: bb2]; ++ } ++ ++ bb2: { ++ StorageDead(_6); ++ goto -> bb4; ++ } ++ ++ bb3: { ++ _7 = core::panicking::panic_nounwind(const "u64::unchecked_shl cannot overflow") -> unwind unreachable; ++ } ++ ++ bb4: { + StorageDead(_5); ++ StorageLive(_8); ++ _8 = _4 as u64 (IntToInt); ++ _0 = ShlUnchecked(_3, move _8); ++ StorageDead(_8); ++ StorageDead(_7); StorageDead(_4); StorageDead(_3); return; diff --git a/tests/mir-opt/inline/unchecked_shifts.unchecked_shl_unsigned_bigger.Inline.panic-unwind.diff b/tests/mir-opt/inline/unchecked_shifts.unchecked_shl_unsigned_bigger.Inline.panic-unwind.diff index d71b5c4a626ef..688fe5565bf69 100644 --- a/tests/mir-opt/inline/unchecked_shifts.unchecked_shl_unsigned_bigger.Inline.panic-unwind.diff +++ b/tests/mir-opt/inline/unchecked_shifts.unchecked_shl_unsigned_bigger.Inline.panic-unwind.diff @@ -10,7 +10,10 @@ + scope 1 (inlined core::num::::unchecked_shl) { + debug self => _3; + debug rhs => _4; -+ let mut _5: u64; ++ let mut _5: bool; ++ let mut _6: bool; ++ let _7: !; ++ let mut _8: u64; + scope 2 { + } + } @@ -21,13 +24,34 @@ StorageLive(_4); _4 = _2; - _0 = core::num::::unchecked_shl(move _3, move _4) -> [return: bb1, unwind continue]; -- } -- -- bb1: { ++ StorageLive(_7); + StorageLive(_5); -+ _5 = _4 as u64 (IntToInt); -+ _0 = ShlUnchecked(_3, move _5); ++ _5 = cfg!(debug_assertions); ++ switchInt(move _5) -> [0: bb4, otherwise: bb1]; + } + + bb1: { ++ StorageLive(_6); ++ _6 = Lt(_4, const _); ++ switchInt(move _6) -> [0: bb3, otherwise: bb2]; ++ } ++ ++ bb2: { ++ StorageDead(_6); ++ goto -> bb4; ++ } ++ ++ bb3: { ++ _7 = core::panicking::panic_nounwind(const "u64::unchecked_shl cannot overflow") -> unwind unreachable; ++ } ++ ++ bb4: { + StorageDead(_5); ++ StorageLive(_8); ++ _8 = _4 as u64 (IntToInt); ++ _0 = ShlUnchecked(_3, move _8); ++ StorageDead(_8); ++ StorageDead(_7); StorageDead(_4); StorageDead(_3); return; diff --git a/tests/mir-opt/inline/unchecked_shifts.unchecked_shl_unsigned_bigger.PreCodegen.after.panic-abort.mir b/tests/mir-opt/inline/unchecked_shifts.unchecked_shl_unsigned_bigger.PreCodegen.after.panic-abort.mir index 65b832497f9d5..7ded764e2bcb3 100644 --- a/tests/mir-opt/inline/unchecked_shifts.unchecked_shl_unsigned_bigger.PreCodegen.after.panic-abort.mir +++ b/tests/mir-opt/inline/unchecked_shifts.unchecked_shl_unsigned_bigger.PreCodegen.after.panic-abort.mir @@ -7,16 +7,41 @@ fn unchecked_shl_unsigned_bigger(_1: u64, _2: u32) -> u64 { scope 1 (inlined core::num::::unchecked_shl) { debug self => _1; debug rhs => _2; - let mut _3: u64; + let mut _3: bool; + let mut _4: bool; + let _5: !; + let mut _6: u64; scope 2 { } } bb0: { StorageLive(_3); - _3 = _2 as u64 (IntToInt); - _0 = ShlUnchecked(_1, move _3); + _3 = cfg!(debug_assertions); + switchInt(move _3) -> [0: bb4, otherwise: bb1]; + } + + bb1: { + StorageLive(_4); + _4 = Lt(_2, const _); + switchInt(move _4) -> [0: bb2, otherwise: bb3]; + } + + bb2: { + _5 = core::panicking::panic_nounwind(const "u64::unchecked_shl cannot overflow") -> unwind unreachable; + } + + bb3: { + StorageDead(_4); + goto -> bb4; + } + + bb4: { StorageDead(_3); + StorageLive(_6); + _6 = _2 as u64 (IntToInt); + _0 = ShlUnchecked(_1, move _6); + StorageDead(_6); return; } } diff --git a/tests/mir-opt/inline/unchecked_shifts.unchecked_shl_unsigned_bigger.PreCodegen.after.panic-unwind.mir b/tests/mir-opt/inline/unchecked_shifts.unchecked_shl_unsigned_bigger.PreCodegen.after.panic-unwind.mir index 65b832497f9d5..7ded764e2bcb3 100644 --- a/tests/mir-opt/inline/unchecked_shifts.unchecked_shl_unsigned_bigger.PreCodegen.after.panic-unwind.mir +++ b/tests/mir-opt/inline/unchecked_shifts.unchecked_shl_unsigned_bigger.PreCodegen.after.panic-unwind.mir @@ -7,16 +7,41 @@ fn unchecked_shl_unsigned_bigger(_1: u64, _2: u32) -> u64 { scope 1 (inlined core::num::::unchecked_shl) { debug self => _1; debug rhs => _2; - let mut _3: u64; + let mut _3: bool; + let mut _4: bool; + let _5: !; + let mut _6: u64; scope 2 { } } bb0: { StorageLive(_3); - _3 = _2 as u64 (IntToInt); - _0 = ShlUnchecked(_1, move _3); + _3 = cfg!(debug_assertions); + switchInt(move _3) -> [0: bb4, otherwise: bb1]; + } + + bb1: { + StorageLive(_4); + _4 = Lt(_2, const _); + switchInt(move _4) -> [0: bb2, otherwise: bb3]; + } + + bb2: { + _5 = core::panicking::panic_nounwind(const "u64::unchecked_shl cannot overflow") -> unwind unreachable; + } + + bb3: { + StorageDead(_4); + goto -> bb4; + } + + bb4: { StorageDead(_3); + StorageLive(_6); + _6 = _2 as u64 (IntToInt); + _0 = ShlUnchecked(_1, move _6); + StorageDead(_6); return; } } diff --git a/tests/mir-opt/inline/unchecked_shifts.unchecked_shl_unsigned_smaller.Inline.panic-abort.diff b/tests/mir-opt/inline/unchecked_shifts.unchecked_shl_unsigned_smaller.Inline.panic-abort.diff index d052219661b38..58269f4174a5d 100644 --- a/tests/mir-opt/inline/unchecked_shifts.unchecked_shl_unsigned_smaller.Inline.panic-abort.diff +++ b/tests/mir-opt/inline/unchecked_shifts.unchecked_shl_unsigned_smaller.Inline.panic-abort.diff @@ -10,8 +10,11 @@ + scope 1 (inlined core::num::::unchecked_shl) { + debug self => _3; + debug rhs => _4; -+ let mut _5: u16; ++ let mut _5: bool; + let mut _6: bool; ++ let _7: !; ++ let mut _8: u16; ++ let mut _9: bool; + scope 2 { + } + } @@ -22,17 +25,38 @@ StorageLive(_4); _4 = _2; - _0 = core::num::::unchecked_shl(move _3, move _4) -> [return: bb1, unwind unreachable]; -- } -- -- bb1: { ++ StorageLive(_7); + StorageLive(_5); ++ _5 = cfg!(debug_assertions); ++ switchInt(move _5) -> [0: bb4, otherwise: bb1]; + } + + bb1: { + StorageLive(_6); -+ _6 = Le(_4, const 65535_u32); -+ assume(move _6); ++ _6 = Lt(_4, const _); ++ switchInt(move _6) -> [0: bb3, otherwise: bb2]; ++ } ++ ++ bb2: { + StorageDead(_6); -+ _5 = _4 as u16 (IntToInt); -+ _0 = ShlUnchecked(_3, move _5); ++ goto -> bb4; ++ } ++ ++ bb3: { ++ _7 = core::panicking::panic_nounwind(const "u16::unchecked_shl cannot overflow") -> unwind unreachable; ++ } ++ ++ bb4: { + StorageDead(_5); ++ StorageLive(_8); ++ StorageLive(_9); ++ _9 = Le(_4, const 65535_u32); ++ assume(move _9); ++ StorageDead(_9); ++ _8 = _4 as u16 (IntToInt); ++ _0 = ShlUnchecked(_3, move _8); ++ StorageDead(_8); ++ StorageDead(_7); StorageDead(_4); StorageDead(_3); return; diff --git a/tests/mir-opt/inline/unchecked_shifts.unchecked_shl_unsigned_smaller.Inline.panic-unwind.diff b/tests/mir-opt/inline/unchecked_shifts.unchecked_shl_unsigned_smaller.Inline.panic-unwind.diff index 67a5ac2483b64..047bd521da2a4 100644 --- a/tests/mir-opt/inline/unchecked_shifts.unchecked_shl_unsigned_smaller.Inline.panic-unwind.diff +++ b/tests/mir-opt/inline/unchecked_shifts.unchecked_shl_unsigned_smaller.Inline.panic-unwind.diff @@ -10,8 +10,11 @@ + scope 1 (inlined core::num::::unchecked_shl) { + debug self => _3; + debug rhs => _4; -+ let mut _5: u16; ++ let mut _5: bool; + let mut _6: bool; ++ let _7: !; ++ let mut _8: u16; ++ let mut _9: bool; + scope 2 { + } + } @@ -22,17 +25,38 @@ StorageLive(_4); _4 = _2; - _0 = core::num::::unchecked_shl(move _3, move _4) -> [return: bb1, unwind continue]; -- } -- -- bb1: { ++ StorageLive(_7); + StorageLive(_5); ++ _5 = cfg!(debug_assertions); ++ switchInt(move _5) -> [0: bb4, otherwise: bb1]; + } + + bb1: { + StorageLive(_6); -+ _6 = Le(_4, const 65535_u32); -+ assume(move _6); ++ _6 = Lt(_4, const _); ++ switchInt(move _6) -> [0: bb3, otherwise: bb2]; ++ } ++ ++ bb2: { + StorageDead(_6); -+ _5 = _4 as u16 (IntToInt); -+ _0 = ShlUnchecked(_3, move _5); ++ goto -> bb4; ++ } ++ ++ bb3: { ++ _7 = core::panicking::panic_nounwind(const "u16::unchecked_shl cannot overflow") -> unwind unreachable; ++ } ++ ++ bb4: { + StorageDead(_5); ++ StorageLive(_8); ++ StorageLive(_9); ++ _9 = Le(_4, const 65535_u32); ++ assume(move _9); ++ StorageDead(_9); ++ _8 = _4 as u16 (IntToInt); ++ _0 = ShlUnchecked(_3, move _8); ++ StorageDead(_8); ++ StorageDead(_7); StorageDead(_4); StorageDead(_3); return; diff --git a/tests/mir-opt/inline/unchecked_shifts.unchecked_shl_unsigned_smaller.PreCodegen.after.panic-abort.mir b/tests/mir-opt/inline/unchecked_shifts.unchecked_shl_unsigned_smaller.PreCodegen.after.panic-abort.mir index f9dff62e0c8a8..87b4cb2459256 100644 --- a/tests/mir-opt/inline/unchecked_shifts.unchecked_shl_unsigned_smaller.PreCodegen.after.panic-abort.mir +++ b/tests/mir-opt/inline/unchecked_shifts.unchecked_shl_unsigned_smaller.PreCodegen.after.panic-abort.mir @@ -8,20 +8,45 @@ fn unchecked_shl_unsigned_smaller(_1: u16, _2: u32) -> u16 { debug self => _1; debug rhs => _2; let mut _3: bool; - let mut _4: u16; + let mut _4: bool; + let _5: !; + let mut _6: bool; + let mut _7: u16; scope 2 { } } bb0: { - StorageLive(_4); StorageLive(_3); - _3 = Le(_2, const 65535_u32); - assume(move _3); - StorageDead(_3); - _4 = _2 as u16 (IntToInt); - _0 = ShlUnchecked(_1, move _4); + _3 = cfg!(debug_assertions); + switchInt(move _3) -> [0: bb4, otherwise: bb1]; + } + + bb1: { + StorageLive(_4); + _4 = Lt(_2, const _); + switchInt(move _4) -> [0: bb2, otherwise: bb3]; + } + + bb2: { + _5 = core::panicking::panic_nounwind(const "u16::unchecked_shl cannot overflow") -> unwind unreachable; + } + + bb3: { StorageDead(_4); + goto -> bb4; + } + + bb4: { + StorageDead(_3); + StorageLive(_7); + StorageLive(_6); + _6 = Le(_2, const 65535_u32); + assume(move _6); + StorageDead(_6); + _7 = _2 as u16 (IntToInt); + _0 = ShlUnchecked(_1, move _7); + StorageDead(_7); return; } } diff --git a/tests/mir-opt/inline/unchecked_shifts.unchecked_shl_unsigned_smaller.PreCodegen.after.panic-unwind.mir b/tests/mir-opt/inline/unchecked_shifts.unchecked_shl_unsigned_smaller.PreCodegen.after.panic-unwind.mir index f9dff62e0c8a8..87b4cb2459256 100644 --- a/tests/mir-opt/inline/unchecked_shifts.unchecked_shl_unsigned_smaller.PreCodegen.after.panic-unwind.mir +++ b/tests/mir-opt/inline/unchecked_shifts.unchecked_shl_unsigned_smaller.PreCodegen.after.panic-unwind.mir @@ -8,20 +8,45 @@ fn unchecked_shl_unsigned_smaller(_1: u16, _2: u32) -> u16 { debug self => _1; debug rhs => _2; let mut _3: bool; - let mut _4: u16; + let mut _4: bool; + let _5: !; + let mut _6: bool; + let mut _7: u16; scope 2 { } } bb0: { - StorageLive(_4); StorageLive(_3); - _3 = Le(_2, const 65535_u32); - assume(move _3); - StorageDead(_3); - _4 = _2 as u16 (IntToInt); - _0 = ShlUnchecked(_1, move _4); + _3 = cfg!(debug_assertions); + switchInt(move _3) -> [0: bb4, otherwise: bb1]; + } + + bb1: { + StorageLive(_4); + _4 = Lt(_2, const _); + switchInt(move _4) -> [0: bb2, otherwise: bb3]; + } + + bb2: { + _5 = core::panicking::panic_nounwind(const "u16::unchecked_shl cannot overflow") -> unwind unreachable; + } + + bb3: { StorageDead(_4); + goto -> bb4; + } + + bb4: { + StorageDead(_3); + StorageLive(_7); + StorageLive(_6); + _6 = Le(_2, const 65535_u32); + assume(move _6); + StorageDead(_6); + _7 = _2 as u16 (IntToInt); + _0 = ShlUnchecked(_1, move _7); + StorageDead(_7); return; } } diff --git a/tests/mir-opt/inline/unchecked_shifts.unchecked_shr_signed_bigger.Inline.panic-abort.diff b/tests/mir-opt/inline/unchecked_shifts.unchecked_shr_signed_bigger.Inline.panic-abort.diff index 1e83fec4f3d00..24e3ba5446d4d 100644 --- a/tests/mir-opt/inline/unchecked_shifts.unchecked_shr_signed_bigger.Inline.panic-abort.diff +++ b/tests/mir-opt/inline/unchecked_shifts.unchecked_shr_signed_bigger.Inline.panic-abort.diff @@ -10,7 +10,10 @@ + scope 1 (inlined core::num::::unchecked_shr) { + debug self => _3; + debug rhs => _4; -+ let mut _5: i64; ++ let mut _5: bool; ++ let mut _6: bool; ++ let _7: !; ++ let mut _8: i64; + scope 2 { + } + } @@ -21,13 +24,34 @@ StorageLive(_4); _4 = _2; - _0 = core::num::::unchecked_shr(move _3, move _4) -> [return: bb1, unwind unreachable]; -- } -- -- bb1: { ++ StorageLive(_7); + StorageLive(_5); -+ _5 = _4 as i64 (IntToInt); -+ _0 = ShrUnchecked(_3, move _5); ++ _5 = cfg!(debug_assertions); ++ switchInt(move _5) -> [0: bb4, otherwise: bb1]; + } + + bb1: { ++ StorageLive(_6); ++ _6 = Lt(_4, const _); ++ switchInt(move _6) -> [0: bb3, otherwise: bb2]; ++ } ++ ++ bb2: { ++ StorageDead(_6); ++ goto -> bb4; ++ } ++ ++ bb3: { ++ _7 = core::panicking::panic_nounwind(const "i64::unchecked_shr cannot overflow") -> unwind unreachable; ++ } ++ ++ bb4: { + StorageDead(_5); ++ StorageLive(_8); ++ _8 = _4 as i64 (IntToInt); ++ _0 = ShlUnchecked(_3, move _8); ++ StorageDead(_8); ++ StorageDead(_7); StorageDead(_4); StorageDead(_3); return; diff --git a/tests/mir-opt/inline/unchecked_shifts.unchecked_shr_signed_bigger.Inline.panic-unwind.diff b/tests/mir-opt/inline/unchecked_shifts.unchecked_shr_signed_bigger.Inline.panic-unwind.diff index 6aafb61dc557d..a7b0d85d66372 100644 --- a/tests/mir-opt/inline/unchecked_shifts.unchecked_shr_signed_bigger.Inline.panic-unwind.diff +++ b/tests/mir-opt/inline/unchecked_shifts.unchecked_shr_signed_bigger.Inline.panic-unwind.diff @@ -10,7 +10,10 @@ + scope 1 (inlined core::num::::unchecked_shr) { + debug self => _3; + debug rhs => _4; -+ let mut _5: i64; ++ let mut _5: bool; ++ let mut _6: bool; ++ let _7: !; ++ let mut _8: i64; + scope 2 { + } + } @@ -21,13 +24,34 @@ StorageLive(_4); _4 = _2; - _0 = core::num::::unchecked_shr(move _3, move _4) -> [return: bb1, unwind continue]; -- } -- -- bb1: { ++ StorageLive(_7); + StorageLive(_5); -+ _5 = _4 as i64 (IntToInt); -+ _0 = ShrUnchecked(_3, move _5); ++ _5 = cfg!(debug_assertions); ++ switchInt(move _5) -> [0: bb4, otherwise: bb1]; + } + + bb1: { ++ StorageLive(_6); ++ _6 = Lt(_4, const _); ++ switchInt(move _6) -> [0: bb3, otherwise: bb2]; ++ } ++ ++ bb2: { ++ StorageDead(_6); ++ goto -> bb4; ++ } ++ ++ bb3: { ++ _7 = core::panicking::panic_nounwind(const "i64::unchecked_shr cannot overflow") -> unwind unreachable; ++ } ++ ++ bb4: { + StorageDead(_5); ++ StorageLive(_8); ++ _8 = _4 as i64 (IntToInt); ++ _0 = ShlUnchecked(_3, move _8); ++ StorageDead(_8); ++ StorageDead(_7); StorageDead(_4); StorageDead(_3); return; diff --git a/tests/mir-opt/inline/unchecked_shifts.unchecked_shr_signed_bigger.PreCodegen.after.panic-abort.mir b/tests/mir-opt/inline/unchecked_shifts.unchecked_shr_signed_bigger.PreCodegen.after.panic-abort.mir index 7524ec4970e4b..72d386c066232 100644 --- a/tests/mir-opt/inline/unchecked_shifts.unchecked_shr_signed_bigger.PreCodegen.after.panic-abort.mir +++ b/tests/mir-opt/inline/unchecked_shifts.unchecked_shr_signed_bigger.PreCodegen.after.panic-abort.mir @@ -7,16 +7,41 @@ fn unchecked_shr_signed_bigger(_1: i64, _2: u32) -> i64 { scope 1 (inlined core::num::::unchecked_shr) { debug self => _1; debug rhs => _2; - let mut _3: i64; + let mut _3: bool; + let mut _4: bool; + let _5: !; + let mut _6: i64; scope 2 { } } bb0: { StorageLive(_3); - _3 = _2 as i64 (IntToInt); - _0 = ShrUnchecked(_1, move _3); + _3 = cfg!(debug_assertions); + switchInt(move _3) -> [0: bb4, otherwise: bb1]; + } + + bb1: { + StorageLive(_4); + _4 = Lt(_2, const _); + switchInt(move _4) -> [0: bb2, otherwise: bb3]; + } + + bb2: { + _5 = core::panicking::panic_nounwind(const "i64::unchecked_shr cannot overflow") -> unwind unreachable; + } + + bb3: { + StorageDead(_4); + goto -> bb4; + } + + bb4: { StorageDead(_3); + StorageLive(_6); + _6 = _2 as i64 (IntToInt); + _0 = ShlUnchecked(_1, move _6); + StorageDead(_6); return; } } diff --git a/tests/mir-opt/inline/unchecked_shifts.unchecked_shr_signed_bigger.PreCodegen.after.panic-unwind.mir b/tests/mir-opt/inline/unchecked_shifts.unchecked_shr_signed_bigger.PreCodegen.after.panic-unwind.mir index 7524ec4970e4b..72d386c066232 100644 --- a/tests/mir-opt/inline/unchecked_shifts.unchecked_shr_signed_bigger.PreCodegen.after.panic-unwind.mir +++ b/tests/mir-opt/inline/unchecked_shifts.unchecked_shr_signed_bigger.PreCodegen.after.panic-unwind.mir @@ -7,16 +7,41 @@ fn unchecked_shr_signed_bigger(_1: i64, _2: u32) -> i64 { scope 1 (inlined core::num::::unchecked_shr) { debug self => _1; debug rhs => _2; - let mut _3: i64; + let mut _3: bool; + let mut _4: bool; + let _5: !; + let mut _6: i64; scope 2 { } } bb0: { StorageLive(_3); - _3 = _2 as i64 (IntToInt); - _0 = ShrUnchecked(_1, move _3); + _3 = cfg!(debug_assertions); + switchInt(move _3) -> [0: bb4, otherwise: bb1]; + } + + bb1: { + StorageLive(_4); + _4 = Lt(_2, const _); + switchInt(move _4) -> [0: bb2, otherwise: bb3]; + } + + bb2: { + _5 = core::panicking::panic_nounwind(const "i64::unchecked_shr cannot overflow") -> unwind unreachable; + } + + bb3: { + StorageDead(_4); + goto -> bb4; + } + + bb4: { StorageDead(_3); + StorageLive(_6); + _6 = _2 as i64 (IntToInt); + _0 = ShlUnchecked(_1, move _6); + StorageDead(_6); return; } } diff --git a/tests/mir-opt/inline/unchecked_shifts.unchecked_shr_signed_smaller.Inline.panic-abort.diff b/tests/mir-opt/inline/unchecked_shifts.unchecked_shr_signed_smaller.Inline.panic-abort.diff index 15b36b284de52..666b2dd005809 100644 --- a/tests/mir-opt/inline/unchecked_shifts.unchecked_shr_signed_smaller.Inline.panic-abort.diff +++ b/tests/mir-opt/inline/unchecked_shifts.unchecked_shr_signed_smaller.Inline.panic-abort.diff @@ -10,8 +10,11 @@ + scope 1 (inlined core::num::::unchecked_shr) { + debug self => _3; + debug rhs => _4; -+ let mut _5: i16; ++ let mut _5: bool; + let mut _6: bool; ++ let _7: !; ++ let mut _8: i16; ++ let mut _9: bool; + scope 2 { + } + } @@ -22,17 +25,38 @@ StorageLive(_4); _4 = _2; - _0 = core::num::::unchecked_shr(move _3, move _4) -> [return: bb1, unwind unreachable]; -- } -- -- bb1: { ++ StorageLive(_7); + StorageLive(_5); ++ _5 = cfg!(debug_assertions); ++ switchInt(move _5) -> [0: bb4, otherwise: bb1]; + } + + bb1: { + StorageLive(_6); -+ _6 = Le(_4, const 32767_u32); -+ assume(move _6); ++ _6 = Lt(_4, const _); ++ switchInt(move _6) -> [0: bb3, otherwise: bb2]; ++ } ++ ++ bb2: { + StorageDead(_6); -+ _5 = _4 as i16 (IntToInt); -+ _0 = ShrUnchecked(_3, move _5); ++ goto -> bb4; ++ } ++ ++ bb3: { ++ _7 = core::panicking::panic_nounwind(const "i16::unchecked_shr cannot overflow") -> unwind unreachable; ++ } ++ ++ bb4: { + StorageDead(_5); ++ StorageLive(_8); ++ StorageLive(_9); ++ _9 = Le(_4, const 32767_u32); ++ assume(move _9); ++ StorageDead(_9); ++ _8 = _4 as i16 (IntToInt); ++ _0 = ShlUnchecked(_3, move _8); ++ StorageDead(_8); ++ StorageDead(_7); StorageDead(_4); StorageDead(_3); return; diff --git a/tests/mir-opt/inline/unchecked_shifts.unchecked_shr_signed_smaller.Inline.panic-unwind.diff b/tests/mir-opt/inline/unchecked_shifts.unchecked_shr_signed_smaller.Inline.panic-unwind.diff index 8629f92dbad4a..f791c7d024e09 100644 --- a/tests/mir-opt/inline/unchecked_shifts.unchecked_shr_signed_smaller.Inline.panic-unwind.diff +++ b/tests/mir-opt/inline/unchecked_shifts.unchecked_shr_signed_smaller.Inline.panic-unwind.diff @@ -10,8 +10,11 @@ + scope 1 (inlined core::num::::unchecked_shr) { + debug self => _3; + debug rhs => _4; -+ let mut _5: i16; ++ let mut _5: bool; + let mut _6: bool; ++ let _7: !; ++ let mut _8: i16; ++ let mut _9: bool; + scope 2 { + } + } @@ -22,17 +25,38 @@ StorageLive(_4); _4 = _2; - _0 = core::num::::unchecked_shr(move _3, move _4) -> [return: bb1, unwind continue]; -- } -- -- bb1: { ++ StorageLive(_7); + StorageLive(_5); ++ _5 = cfg!(debug_assertions); ++ switchInt(move _5) -> [0: bb4, otherwise: bb1]; + } + + bb1: { + StorageLive(_6); -+ _6 = Le(_4, const 32767_u32); -+ assume(move _6); ++ _6 = Lt(_4, const _); ++ switchInt(move _6) -> [0: bb3, otherwise: bb2]; ++ } ++ ++ bb2: { + StorageDead(_6); -+ _5 = _4 as i16 (IntToInt); -+ _0 = ShrUnchecked(_3, move _5); ++ goto -> bb4; ++ } ++ ++ bb3: { ++ _7 = core::panicking::panic_nounwind(const "i16::unchecked_shr cannot overflow") -> unwind unreachable; ++ } ++ ++ bb4: { + StorageDead(_5); ++ StorageLive(_8); ++ StorageLive(_9); ++ _9 = Le(_4, const 32767_u32); ++ assume(move _9); ++ StorageDead(_9); ++ _8 = _4 as i16 (IntToInt); ++ _0 = ShlUnchecked(_3, move _8); ++ StorageDead(_8); ++ StorageDead(_7); StorageDead(_4); StorageDead(_3); return; diff --git a/tests/mir-opt/inline/unchecked_shifts.unchecked_shr_signed_smaller.PreCodegen.after.panic-abort.mir b/tests/mir-opt/inline/unchecked_shifts.unchecked_shr_signed_smaller.PreCodegen.after.panic-abort.mir index 65fa0d956c063..91277c7156fad 100644 --- a/tests/mir-opt/inline/unchecked_shifts.unchecked_shr_signed_smaller.PreCodegen.after.panic-abort.mir +++ b/tests/mir-opt/inline/unchecked_shifts.unchecked_shr_signed_smaller.PreCodegen.after.panic-abort.mir @@ -8,20 +8,45 @@ fn unchecked_shr_signed_smaller(_1: i16, _2: u32) -> i16 { debug self => _1; debug rhs => _2; let mut _3: bool; - let mut _4: i16; + let mut _4: bool; + let _5: !; + let mut _6: bool; + let mut _7: i16; scope 2 { } } bb0: { - StorageLive(_4); StorageLive(_3); - _3 = Le(_2, const 32767_u32); - assume(move _3); - StorageDead(_3); - _4 = _2 as i16 (IntToInt); - _0 = ShrUnchecked(_1, move _4); + _3 = cfg!(debug_assertions); + switchInt(move _3) -> [0: bb4, otherwise: bb1]; + } + + bb1: { + StorageLive(_4); + _4 = Lt(_2, const _); + switchInt(move _4) -> [0: bb2, otherwise: bb3]; + } + + bb2: { + _5 = core::panicking::panic_nounwind(const "i16::unchecked_shr cannot overflow") -> unwind unreachable; + } + + bb3: { StorageDead(_4); + goto -> bb4; + } + + bb4: { + StorageDead(_3); + StorageLive(_7); + StorageLive(_6); + _6 = Le(_2, const 32767_u32); + assume(move _6); + StorageDead(_6); + _7 = _2 as i16 (IntToInt); + _0 = ShlUnchecked(_1, move _7); + StorageDead(_7); return; } } diff --git a/tests/mir-opt/inline/unchecked_shifts.unchecked_shr_signed_smaller.PreCodegen.after.panic-unwind.mir b/tests/mir-opt/inline/unchecked_shifts.unchecked_shr_signed_smaller.PreCodegen.after.panic-unwind.mir index 65fa0d956c063..91277c7156fad 100644 --- a/tests/mir-opt/inline/unchecked_shifts.unchecked_shr_signed_smaller.PreCodegen.after.panic-unwind.mir +++ b/tests/mir-opt/inline/unchecked_shifts.unchecked_shr_signed_smaller.PreCodegen.after.panic-unwind.mir @@ -8,20 +8,45 @@ fn unchecked_shr_signed_smaller(_1: i16, _2: u32) -> i16 { debug self => _1; debug rhs => _2; let mut _3: bool; - let mut _4: i16; + let mut _4: bool; + let _5: !; + let mut _6: bool; + let mut _7: i16; scope 2 { } } bb0: { - StorageLive(_4); StorageLive(_3); - _3 = Le(_2, const 32767_u32); - assume(move _3); - StorageDead(_3); - _4 = _2 as i16 (IntToInt); - _0 = ShrUnchecked(_1, move _4); + _3 = cfg!(debug_assertions); + switchInt(move _3) -> [0: bb4, otherwise: bb1]; + } + + bb1: { + StorageLive(_4); + _4 = Lt(_2, const _); + switchInt(move _4) -> [0: bb2, otherwise: bb3]; + } + + bb2: { + _5 = core::panicking::panic_nounwind(const "i16::unchecked_shr cannot overflow") -> unwind unreachable; + } + + bb3: { StorageDead(_4); + goto -> bb4; + } + + bb4: { + StorageDead(_3); + StorageLive(_7); + StorageLive(_6); + _6 = Le(_2, const 32767_u32); + assume(move _6); + StorageDead(_6); + _7 = _2 as i16 (IntToInt); + _0 = ShlUnchecked(_1, move _7); + StorageDead(_7); return; } } diff --git a/tests/mir-opt/pre-codegen/checked_ops.checked_shl.PreCodegen.after.mir b/tests/mir-opt/pre-codegen/checked_ops.checked_shl.PreCodegen.after.mir index 9c6c30214aa2a..fe99b36696cf8 100644 --- a/tests/mir-opt/pre-codegen/checked_ops.checked_shl.PreCodegen.after.mir +++ b/tests/mir-opt/pre-codegen/checked_ops.checked_shl.PreCodegen.after.mir @@ -22,12 +22,6 @@ fn checked_shl(_1: u32, _2: u32) -> Option { debug rhs => _2; let mut _3: u32; scope 5 { - scope 6 (inlined core::num::::unchecked_shl) { - debug self => _1; - debug rhs => _3; - scope 7 { - } - } } } } @@ -38,7 +32,7 @@ fn checked_shl(_1: u32, _2: u32) -> Option { StorageLive(_5); StorageLive(_3); _3 = BitAnd(_2, const 31_u32); - _4 = ShlUnchecked(_1, _3); + _4 = ShlUnchecked(_1, move _3); StorageDead(_3); _5 = Ge(_2, const _); StorageLive(_6);