Skip to content

Commit 01b5430

Browse files
committed
merge two integer tests
1 parent 5d76ec9 commit 01b5430

File tree

2 files changed

+61
-58
lines changed

2 files changed

+61
-58
lines changed

src/tools/miri/tests/pass/integer-ops.rs

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,64 @@
11
//@compile-flags: -Coverflow-checks=off
22
#![allow(arithmetic_overflow)]
33

4+
fn basic() {
5+
fn ret() -> i64 {
6+
1
7+
}
8+
9+
fn neg() -> i64 {
10+
-1
11+
}
12+
13+
fn add() -> i64 {
14+
1 + 2
15+
}
16+
17+
fn indirect_add() -> i64 {
18+
let x = 1;
19+
let y = 2;
20+
x + y
21+
}
22+
23+
fn arith() -> i32 {
24+
3 * 3 + 4 * 4
25+
}
26+
27+
fn match_int() -> i16 {
28+
let n = 2;
29+
match n {
30+
0 => 0,
31+
1 => 10,
32+
2 => 20,
33+
3 => 30,
34+
_ => 100,
35+
}
36+
}
37+
38+
fn match_int_range() -> i64 {
39+
let n = 42;
40+
match n {
41+
0..=9 => 0,
42+
10..=19 => 1,
43+
20..=29 => 2,
44+
30..=39 => 3,
45+
40..=42 => 4,
46+
_ => 5,
47+
}
48+
}
49+
50+
assert_eq!(ret(), 1);
51+
assert_eq!(neg(), -1);
52+
assert_eq!(add(), 3);
53+
assert_eq!(indirect_add(), 3);
54+
assert_eq!(arith(), 5 * 5);
55+
assert_eq!(match_int(), 20);
56+
assert_eq!(match_int_range(), 4);
57+
}
58+
459
pub fn main() {
60+
basic();
61+
562
// This tests that we do (not) do sign extension properly when loading integers
663
assert_eq!(u32::MAX as i64, 4294967295);
764
assert_eq!(i32::MIN as i64, -2147483648);
@@ -152,6 +209,10 @@ pub fn main() {
152209

153210
assert_eq!(5i32.overflowing_mul(2), (10, false));
154211
assert_eq!(1_000_000_000i32.overflowing_mul(10), (1410065408, true));
212+
assert_eq!(i64::MIN.overflowing_mul(-1), (i64::MIN, true));
213+
assert_eq!(i32::MIN.overflowing_mul(-1), (i32::MIN, true));
214+
assert_eq!(i16::MIN.overflowing_mul(-1), (i16::MIN, true));
215+
assert_eq!(i8::MIN.overflowing_mul(-1), (i8::MIN, true));
155216

156217
assert_eq!(5i32.overflowing_div(2), (2, false));
157218
assert_eq!(i32::MIN.overflowing_div(-1), (i32::MIN, true));

src/tools/miri/tests/pass/integers.rs

Lines changed: 0 additions & 58 deletions
This file was deleted.

0 commit comments

Comments
 (0)