From 9810a147a777e1cea91dd01a946fa6a0baf97e62 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sat, 5 Mar 2022 22:59:23 -0500 Subject: [PATCH] add extra tests for shifts with negative offsets --- tests/run-pass/integer-ops.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/tests/run-pass/integer-ops.rs b/tests/run-pass/integer-ops.rs index fde220d8f35..f5c1a7a5ff2 100644 --- a/tests/run-pass/integer-ops.rs +++ b/tests/run-pass/integer-ops.rs @@ -1,13 +1,24 @@ +// compile-flags: -Coverflow-checks=off #![allow(arithmetic_overflow)] pub fn main() { - // This tests that do (not) do sign extension properly when loading integers + // This tests that we do (not) do sign extension properly when loading integers assert_eq!(u32::MAX as i64, 4294967295); assert_eq!(i32::MIN as i64, -2147483648); assert_eq!(i8::MAX, 127); assert_eq!(i8::MIN, -128); + // Shifts with negative offsets are subtle. + assert_eq!(13 << -2i8, 13 << 254); + assert_eq!(13 << i8::MIN, 13); + assert_eq!(13 << -1i16, 13 << u16::MAX); + assert_eq!(13 << i16::MIN, 13); + assert_eq!(13i128 << -2i8, 13i128 << 254); + assert_eq!(13i128 << i8::MIN, 13); + assert_eq!(13i128 << -1i16, 13i128 << u16::MAX); + assert_eq!(13i128 << i16::MIN, 13); + assert_eq!(i32::from_str_radix("A", 16), Ok(10)); let n = -0b1000_0000i8;