Skip to content

Commit

Permalink
Auto merge of #2002 - RalfJung:negative-shifts, r=RalfJung
Browse files Browse the repository at this point in the history
add extra tests for shifts with negative offsets

Cc rust-lang/rust#94659
  • Loading branch information
bors committed Mar 6, 2022
2 parents 54b14b7 + 9810a14 commit 176f070
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion tests/run-pass/integer-ops.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down

0 comments on commit 176f070

Please sign in to comment.