From 148269dd4b64c21c8dfa66d5d67a48443b1aea94 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Wed, 4 Mar 2020 13:01:06 +0100 Subject: [PATCH] finally stop using min/max_value and the integer modules --- rust-version | 2 +- src/shims/foreign_items.rs | 8 ++++---- src/shims/fs.rs | 8 ++++---- src/shims/mod.rs | 2 +- tests/compile-fail/exact_div4.rs | 4 ++-- tests/compile-fail/ptr_offset_overflow.rs | 2 +- tests/compile-fail/slice-too-big.rs | 1 - tests/compile-fail/unchecked_div1.rs | 2 +- tests/run-pass/align_offset.rs | 6 +++--- tests/run-pass/integer-ops.rs | 11 ++++------- tests/run-pass/ints.rs | 8 ++++---- tests/run-pass/panic/overflowing-rsh-2.rs | 2 +- tests/run-pass/pointers.rs | 2 -- tests/run-pass/ptr_arith_offset_overflow.rs | 4 ++-- tests/run-pass/ptr_int_casts.rs | 2 +- tests/run-pass/u128.rs | 4 ++-- 16 files changed, 31 insertions(+), 37 deletions(-) diff --git a/rust-version b/rust-version index 838ec0e9a7..62e7b6845d 100644 --- a/rust-version +++ b/rust-version @@ -1 +1 @@ -4d71c164a89b705df6affd31a5262c832d1bc48d +7a3700c37132385e8e965c18e73d0a09f9146335 diff --git a/src/shims/foreign_items.rs b/src/shims/foreign_items.rs index f8b42e5091..88ebc269cf 100644 --- a/src/shims/foreign_items.rs +++ b/src/shims/foreign_items.rs @@ -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() }; diff --git a/src/shims/fs.rs b/src/shims/fs.rs index 8a48518fa9..0ea53b16fd 100644 --- a/src/shims/fs.rs +++ b/src/shims/fs.rs @@ -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))?; diff --git a/src/shims/mod.rs b/src/shims/mod.rs index 2889807bf7..0437955358 100644 --- a/src/shims/mod.rs +++ b/src/shims/mod.rs @@ -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); diff --git a/tests/compile-fail/exact_div4.rs b/tests/compile-fail/exact_div4.rs index 736d4f2516..c241b2df66 100644 --- a/tests/compile-fail/exact_div4.rs +++ b/tests/compile-fail/exact_div4.rs @@ -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 } diff --git a/tests/compile-fail/ptr_offset_overflow.rs b/tests/compile-fail/ptr_offset_overflow.rs index e52384e919..452bf341c9 100644 --- a/tests/compile-fail/ptr_offset_overflow.rs +++ b/tests/compile-fail/ptr_offset_overflow.rs @@ -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) }; } diff --git a/tests/compile-fail/slice-too-big.rs b/tests/compile-fail/slice-too-big.rs index 08ab48175a..157ea03bc9 100644 --- a/tests/compile-fail/slice-too-big.rs +++ b/tests/compile-fail/slice-too-big.rs @@ -1,5 +1,4 @@ use std::mem; -use std::usize; fn main() { unsafe { let ptr = Box::into_raw(Box::new(0u8)); diff --git a/tests/compile-fail/unchecked_div1.rs b/tests/compile-fail/unchecked_div1.rs index 1d1bbb09aa..b42b34ff46 100644 --- a/tests/compile-fail/unchecked_div1.rs +++ b/tests/compile-fail/unchecked_div1.rs @@ -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` } diff --git a/tests/run-pass/align_offset.rs b/tests/run-pass/align_offset.rs index 1202fd00be..f921634647 100644 --- a/tests/run-pass/align_offset.rs +++ b/tests/run-pass/align_offset.rs @@ -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() { diff --git a/tests/run-pass/integer-ops.rs b/tests/run-pass/integer-ops.rs index 0264099eb6..4ae42df592 100644 --- a/tests/run-pass/integer-ops.rs +++ b/tests/run-pass/integer-ops.rs @@ -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!(i8::min_value(), -128); + assert_eq!(u32::MAX as i64, 4294967295); + assert_eq!(i32::MIN as i64, -2147483648); - 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)); diff --git a/tests/run-pass/ints.rs b/tests/run-pass/ints.rs index 00ca2aa41d..5d7c383088 100644 --- a/tests/run-pass/ints.rs +++ b/tests/run-pass/ints.rs @@ -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)); } diff --git a/tests/run-pass/panic/overflowing-rsh-2.rs b/tests/run-pass/panic/overflowing-rsh-2.rs index da77a46a80..27cc65fa76 100644 --- a/tests/run-pass/panic/overflowing-rsh-2.rs +++ b/tests/run-pass/panic/overflowing-rsh-2.rs @@ -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); } diff --git a/tests/run-pass/pointers.rs b/tests/run-pass/pointers.rs index e0847de97b..5bf60c3254 100644 --- a/tests/run-pass/pointers.rs +++ b/tests/run-pass/pointers.rs @@ -1,5 +1,3 @@ -use std::usize; - fn one_line_ref() -> i16 { *&1 } diff --git a/tests/run-pass/ptr_arith_offset_overflow.rs b/tests/run-pass/ptr_arith_offset_overflow.rs index 56fd448b0c..fdd980e217 100644 --- a/tests/run-pass/ptr_arith_offset_overflow.rs +++ b/tests/run-pass/ptr_arith_offset_overflow.rs @@ -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); } diff --git a/tests/run-pass/ptr_int_casts.rs b/tests/run-pass/ptr_int_casts.rs index c279024f35..468b37af5b 100644 --- a/tests/run-pass/ptr_int_casts.rs +++ b/tests/run-pass/ptr_int_casts.rs @@ -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; diff --git a/tests/run-pass/u128.rs b/tests/run-pass/u128.rs index 5a5d7c1f94..a2ca7746b1 100644 --- a/tests/run-pass/u128.rs +++ b/tests/run-pass/u128.rs @@ -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));