Auto merge of #1206 - RalfJung:int_asooc, r=RalfJung
finally stop using min/max_value and the integer modules https://github.com/rust-lang/rust/pull/68952 landed, so we can finally do this :)
This commit is contained in:
commit
63925169c1
@ -1 +1 @@
|
||||
4d71c164a89b705df6affd31a5262c832d1bc48d
|
||||
7a3700c37132385e8e965c18e73d0a09f9146335
|
||||
|
@ -443,10 +443,10 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
|
||||
|
||||
// Saturating cast to i16. Even those are outside the valid exponent range to
|
||||
// `scalbn` below will do its over/underflow handling.
|
||||
let exp = if exp > i16::max_value() as i32 {
|
||||
i16::max_value()
|
||||
} else if exp < i16::min_value() as i32 {
|
||||
i16::min_value()
|
||||
let exp = if exp > i16::MAX as i32 {
|
||||
i16::MAX
|
||||
} else if exp < i16::MIN as i32 {
|
||||
i16::MIN
|
||||
} else {
|
||||
exp.try_into().unwrap()
|
||||
};
|
||||
|
@ -427,15 +427,15 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
|
||||
|
||||
// We cap the number of read bytes to the largest value that we are able to fit in both the
|
||||
// host's and target's `isize`. This saves us from having to handle overflows later.
|
||||
let count = count.min(this.isize_max() as u64).min(isize::max_value() as u64);
|
||||
let count = count.min(this.isize_max() as u64).min(isize::MAX as u64);
|
||||
|
||||
if let Some(FileHandle { file, writable: _ }) = this.machine.file_handler.handles.get_mut(&fd) {
|
||||
// This can never fail because `count` was capped to be smaller than
|
||||
// `isize::max_value()`.
|
||||
// `isize::MAX`.
|
||||
let count = isize::try_from(count).unwrap();
|
||||
// We want to read at most `count` bytes. We are sure that `count` is not negative
|
||||
// because it was a target's `usize`. Also we are sure that its smaller than
|
||||
// `usize::max_value()` because it is a host's `isize`.
|
||||
// `usize::MAX` because it is a host's `isize`.
|
||||
let mut bytes = vec![0; count as usize];
|
||||
let result = file
|
||||
.read(&mut bytes)
|
||||
@ -481,7 +481,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
|
||||
|
||||
// We cap the number of written bytes to the largest value that we are able to fit in both the
|
||||
// host's and target's `isize`. This saves us from having to handle overflows later.
|
||||
let count = count.min(this.isize_max() as u64).min(isize::max_value() as u64);
|
||||
let count = count.min(this.isize_max() as u64).min(isize::MAX as u64);
|
||||
|
||||
if let Some(FileHandle { file, writable: _ }) = this.machine.file_handler.handles.get_mut(&fd) {
|
||||
let bytes = this.memory.read_bytes(buf, Size::from_bytes(count))?;
|
||||
|
@ -27,7 +27,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
|
||||
let (dest, ret) = ret.unwrap();
|
||||
let n = this
|
||||
.align_offset(args[0], args[1])?
|
||||
.unwrap_or_else(|| this.truncate(u128::max_value(), dest.layout));
|
||||
.unwrap_or_else(|| this.truncate(u128::MAX, dest.layout));
|
||||
this.write_scalar(Scalar::from_uint(n, dest.layout.size), dest)?;
|
||||
this.go_to_block(ret);
|
||||
return Ok(None);
|
||||
|
@ -1,5 +1,5 @@
|
||||
#![feature(core_intrinsics)]
|
||||
fn main() {
|
||||
// divison of min_value by -1
|
||||
unsafe { std::intrinsics::exact_div(i64::min_value(), -1); } //~ ERROR result of dividing MIN by -1 cannot be represented
|
||||
// divison of MIN by -1
|
||||
unsafe { std::intrinsics::exact_div(i64::MIN, -1); } //~ ERROR result of dividing MIN by -1 cannot be represented
|
||||
}
|
||||
|
@ -2,5 +2,5 @@
|
||||
fn main() {
|
||||
let v = [1i8, 2];
|
||||
let x = &v[1] as *const i8;
|
||||
let _val = unsafe { x.offset(isize::min_value()) };
|
||||
let _val = unsafe { x.offset(isize::MIN) };
|
||||
}
|
||||
|
@ -1,5 +1,4 @@
|
||||
use std::mem;
|
||||
use std::usize;
|
||||
|
||||
fn main() { unsafe {
|
||||
let ptr = Box::into_raw(Box::new(0u8));
|
||||
|
@ -1,5 +1,5 @@
|
||||
#![feature(core_intrinsics)]
|
||||
fn main() {
|
||||
// MIN/-1 cannot be represented
|
||||
unsafe { std::intrinsics::unchecked_div(i16::min_value(), -1); } //~ ERROR Overflow executing `unchecked_div`
|
||||
unsafe { std::intrinsics::unchecked_div(i16::MIN, -1); } //~ ERROR Overflow executing `unchecked_div`
|
||||
}
|
||||
|
@ -5,15 +5,15 @@ fn test_align_offset() {
|
||||
|
||||
assert_eq!(raw.align_offset(2), 0);
|
||||
assert_eq!(raw.align_offset(4), 0);
|
||||
assert_eq!(raw.align_offset(8), usize::max_value()); // requested alignment higher than allocation alignment
|
||||
assert_eq!(raw.align_offset(8), usize::MAX); // requested alignment higher than allocation alignment
|
||||
|
||||
assert_eq!(raw.wrapping_offset(1).align_offset(2), 1);
|
||||
assert_eq!(raw.wrapping_offset(1).align_offset(4), 3);
|
||||
assert_eq!(raw.wrapping_offset(1).align_offset(8), usize::max_value()); // requested alignment higher than allocation alignment
|
||||
assert_eq!(raw.wrapping_offset(1).align_offset(8), usize::MAX); // requested alignment higher than allocation alignment
|
||||
|
||||
assert_eq!(raw.wrapping_offset(2).align_offset(2), 0);
|
||||
assert_eq!(raw.wrapping_offset(2).align_offset(4), 2);
|
||||
assert_eq!(raw.wrapping_offset(2).align_offset(8), usize::max_value()); // requested alignment higher than allocation alignment
|
||||
assert_eq!(raw.wrapping_offset(2).align_offset(8), usize::MAX); // requested alignment higher than allocation alignment
|
||||
}
|
||||
|
||||
fn test_align_to() {
|
||||
|
@ -8,16 +8,13 @@
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
use std::i32;
|
||||
|
||||
pub fn main() {
|
||||
// This tests that do (not) do sign extension properly when loading integers
|
||||
assert_eq!(u32::max_value() as i64, 4294967295);
|
||||
assert_eq!(i32::min_value() as i64, -2147483648);
|
||||
assert_eq!(u32::MAX as i64, 4294967295);
|
||||
assert_eq!(i32::MIN as i64, -2147483648);
|
||||
|
||||
assert_eq!(i8::min_value(), -128);
|
||||
|
||||
assert_eq!(i8::max_value(), 127);
|
||||
assert_eq!(i8::MAX, 127);
|
||||
assert_eq!(i8::MIN, -128);
|
||||
|
||||
assert_eq!(i32::from_str_radix("A", 16), Ok(10));
|
||||
|
||||
|
@ -51,8 +51,8 @@ fn main() {
|
||||
assert_eq!(arith(), 5*5);
|
||||
assert_eq!(match_int(), 20);
|
||||
assert_eq!(match_int_range(), 4);
|
||||
assert_eq!(i64::min_value().overflowing_mul(-1), (i64::min_value(), true));
|
||||
assert_eq!(i32::min_value().overflowing_mul(-1), (i32::min_value(), true));
|
||||
assert_eq!(i16::min_value().overflowing_mul(-1), (i16::min_value(), true));
|
||||
assert_eq!(i8::min_value().overflowing_mul(-1), (i8::min_value(), true));
|
||||
assert_eq!(i64::MIN.overflowing_mul(-1), (i64::MIN, true));
|
||||
assert_eq!(i32::MIN.overflowing_mul(-1), (i32::MIN, true));
|
||||
assert_eq!(i16::MIN.overflowing_mul(-1), (i16::MIN, true));
|
||||
assert_eq!(i8::MIN.overflowing_mul(-1), (i8::MIN, true));
|
||||
}
|
||||
|
@ -3,5 +3,5 @@
|
||||
|
||||
fn main() {
|
||||
// Make sure we catch overflows that would be hidden by first casting the RHS to u32
|
||||
let _n = 1i64 >> (u32::max_value() as i64 + 1);
|
||||
let _n = 1i64 >> (u32::MAX as i64 + 1);
|
||||
}
|
||||
|
@ -1,5 +1,3 @@
|
||||
use std::usize;
|
||||
|
||||
fn one_line_ref() -> i16 {
|
||||
*&1
|
||||
}
|
||||
|
@ -5,8 +5,8 @@ fn main() {
|
||||
let x = &mut ptr::null(); // going through memory as there are more sanity checks along that path
|
||||
*x = v.as_ptr().wrapping_offset(1); // ptr to the 2nd element
|
||||
// Adding 2*isize::max and then 1 is like substracting 1
|
||||
*x = x.wrapping_offset(isize::max_value());
|
||||
*x = x.wrapping_offset(isize::max_value());
|
||||
*x = x.wrapping_offset(isize::MAX);
|
||||
*x = x.wrapping_offset(isize::MAX);
|
||||
*x = x.wrapping_offset(1);
|
||||
assert_eq!(unsafe { **x }, 1);
|
||||
}
|
||||
|
@ -16,7 +16,7 @@ fn main() {
|
||||
// this used to trigger an ICE on 32bit)
|
||||
let val = &mut ptr::null();
|
||||
*val = (1 as *const u8).wrapping_offset(-4);
|
||||
assert_eq!(*val as usize, usize::max_value() - 2);
|
||||
assert_eq!(*val as usize, usize::MAX - 2);
|
||||
|
||||
{ // ptr-int-ptr
|
||||
let x = 13;
|
||||
|
@ -48,14 +48,14 @@ fn main() {
|
||||
assert_eq!("10000000000000000000000000000000000000000000000000000000000000000000",
|
||||
format!("{:b}", j));
|
||||
assert_eq!("340282366920938463463374607431768211455",
|
||||
format!("{}", u128::max_value()));
|
||||
format!("{}", u128::MAX));
|
||||
assert_eq!("147573952589676412928", format!("{:?}", j));
|
||||
// common traits
|
||||
assert_eq!(x, b(x.clone()));
|
||||
// overflow checks
|
||||
assert_eq!((z).checked_mul(z), Some(0x734C_C2F2_A521));
|
||||
assert_eq!((k).checked_mul(k), None);
|
||||
let l: u128 = b(u128::max_value() - 10);
|
||||
let l: u128 = b(u128::MAX - 10);
|
||||
let o: u128 = b(17);
|
||||
assert_eq!(l.checked_add(b(11)), None);
|
||||
assert_eq!(l.checked_sub(l), Some(0));
|
||||
|
Loading…
x
Reference in New Issue
Block a user