Use unsigned_abs throughout repository
This commit is contained in:
parent
85394252e6
commit
edf2e3725e
5 changed files with 6 additions and 15 deletions
|
@ -588,12 +588,3 @@ pub fn read_target_uint(endianness: Endian, mut source: &[u8]) -> Result<u128, i
|
||||||
debug_assert!(source.len() == 0); // We should have consumed the source buffer.
|
debug_assert!(source.len() == 0); // We should have consumed the source buffer.
|
||||||
uint
|
uint
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Computes the unsigned absolute value without wrapping or panicking.
|
|
||||||
#[inline]
|
|
||||||
pub fn uabs(value: i64) -> u64 {
|
|
||||||
// The only tricky part here is if value == i64::MIN. In that case,
|
|
||||||
// wrapping_abs() returns i64::MIN == -2^63. Casting this value to a u64
|
|
||||||
// gives 2^63, the correct value.
|
|
||||||
value.wrapping_abs() as u64
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use super::{uabs, AllocId, InterpResult};
|
use super::{AllocId, InterpResult};
|
||||||
|
|
||||||
use rustc_macros::HashStable;
|
use rustc_macros::HashStable;
|
||||||
use rustc_target::abi::{HasDataLayout, Size};
|
use rustc_target::abi::{HasDataLayout, Size};
|
||||||
|
@ -57,7 +57,7 @@ pub trait PointerArithmetic: HasDataLayout {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn overflowing_signed_offset(&self, val: u64, i: i64) -> (u64, bool) {
|
fn overflowing_signed_offset(&self, val: u64, i: i64) -> (u64, bool) {
|
||||||
// We need to make sure that i fits in a machine isize.
|
// We need to make sure that i fits in a machine isize.
|
||||||
let n = uabs(i);
|
let n = i.unsigned_abs();
|
||||||
if i >= 0 {
|
if i >= 0 {
|
||||||
let (val, over) = self.overflowing_offset(val, n);
|
let (val, over) = self.overflowing_offset(val, n);
|
||||||
(val, over || i > self.machine_isize_max())
|
(val, over || i > self.machine_isize_max())
|
||||||
|
|
|
@ -7,7 +7,7 @@ use std::convert::TryFrom;
|
||||||
use rustc_hir::def_id::DefId;
|
use rustc_hir::def_id::DefId;
|
||||||
use rustc_middle::mir::{
|
use rustc_middle::mir::{
|
||||||
self,
|
self,
|
||||||
interpret::{uabs, ConstValue, GlobalId, InterpResult, Scalar},
|
interpret::{ConstValue, GlobalId, InterpResult, Scalar},
|
||||||
BinOp,
|
BinOp,
|
||||||
};
|
};
|
||||||
use rustc_middle::ty;
|
use rustc_middle::ty;
|
||||||
|
@ -542,7 +542,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
||||||
// memory between these pointers must be accessible. Note that we do not require the
|
// memory between these pointers must be accessible. Note that we do not require the
|
||||||
// pointers to be properly aligned (unlike a read/write operation).
|
// pointers to be properly aligned (unlike a read/write operation).
|
||||||
let min_ptr = if offset_bytes >= 0 { ptr } else { offset_ptr };
|
let min_ptr = if offset_bytes >= 0 { ptr } else { offset_ptr };
|
||||||
let size: u64 = uabs(offset_bytes);
|
let size = offset_bytes.unsigned_abs();
|
||||||
// This call handles checking for integer/NULL pointers.
|
// This call handles checking for integer/NULL pointers.
|
||||||
self.memory.check_ptr_access_align(
|
self.memory.check_ptr_access_align(
|
||||||
min_ptr,
|
min_ptr,
|
||||||
|
|
|
@ -531,7 +531,7 @@ impl Printer<'tcx> for SymbolMangler<'tcx> {
|
||||||
if val < 0 {
|
if val < 0 {
|
||||||
neg = true;
|
neg = true;
|
||||||
}
|
}
|
||||||
Some(val.wrapping_abs() as u128)
|
Some(val.unsigned_abs())
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
|
|
|
@ -332,7 +332,7 @@ fn bound_intermediate_digits(decimal: &Decimal<'_>, e: i64) -> u64 {
|
||||||
// It tries to find a positive number k such that `f << k / 10^e` is an in-range
|
// It tries to find a positive number k such that `f << k / 10^e` is an in-range
|
||||||
// significand. This will result in about `2^53 * f * 10^e` < `10^17 * f * 10^e`.
|
// significand. This will result in about `2^53 * f * 10^e` < `10^17 * f * 10^e`.
|
||||||
// One input that triggers this is 0.33...33 (375 x 3).
|
// One input that triggers this is 0.33...33 (375 x 3).
|
||||||
f_len + (e.abs() as u64) + 17
|
f_len + e.unsigned_abs() + 17
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue