Skip to content

Commit 176f070

Browse files
committed
Auto merge of #2002 - RalfJung:negative-shifts, r=RalfJung
add extra tests for shifts with negative offsets Cc rust-lang/rust#94659
2 parents 54b14b7 + 9810a14 commit 176f070

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

tests/run-pass/integer-ops.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,24 @@
1+
// compile-flags: -Coverflow-checks=off
12
#![allow(arithmetic_overflow)]
23

34
pub fn main() {
4-
// This tests that do (not) do sign extension properly when loading integers
5+
// This tests that we do (not) do sign extension properly when loading integers
56
assert_eq!(u32::MAX as i64, 4294967295);
67
assert_eq!(i32::MIN as i64, -2147483648);
78

89
assert_eq!(i8::MAX, 127);
910
assert_eq!(i8::MIN, -128);
1011

12+
// Shifts with negative offsets are subtle.
13+
assert_eq!(13 << -2i8, 13 << 254);
14+
assert_eq!(13 << i8::MIN, 13);
15+
assert_eq!(13 << -1i16, 13 << u16::MAX);
16+
assert_eq!(13 << i16::MIN, 13);
17+
assert_eq!(13i128 << -2i8, 13i128 << 254);
18+
assert_eq!(13i128 << i8::MIN, 13);
19+
assert_eq!(13i128 << -1i16, 13i128 << u16::MAX);
20+
assert_eq!(13i128 << i16::MIN, 13);
21+
1122
assert_eq!(i32::from_str_radix("A", 16), Ok(10));
1223

1324
let n = -0b1000_0000i8;

0 commit comments

Comments
 (0)