Skip to content

Commit bac2b13

Browse files
committed
Auto merge of #30085 - oli-obk:fix/pnkfelix_test, r=pnkfelix
for discussion see https://github.com/rust-lang/rust/pull/26848/files#r43151926 r? @pnkfelix
2 parents 5dc91a7 + 5951418 commit bac2b13

File tree

1 file changed

+32
-20
lines changed

1 file changed

+32
-20
lines changed

src/test/run-pass/shift-near-oflo.rs

+32-20
Original file line numberDiff line numberDiff line change
@@ -18,39 +18,51 @@ fn main() {
1818
test_right_shift();
1919
}
2020

21+
pub static mut HACK: i32 = 0;
22+
23+
// Work around constant-evaluation
24+
// The point of this test is to exercise the code generated for execution at runtime,
25+
// `id` can never be flagged as a const fn by future aggressive analyses...
26+
// due to the modification of the static
27+
#[inline(never)]
28+
fn id<T>(x: T) -> T {
29+
unsafe { HACK += 1; }
30+
x
31+
}
32+
2133
fn test_left_shift() {
2234
// negative rhs can panic, but values in [0,N-1] are okay for iN
2335

2436
macro_rules! tests {
2537
($iN:ty, $uN:ty, $max_rhs:expr, $expect_i:expr, $expect_u:expr) => { {
26-
let x = (1 as $iN) << 0;
38+
let x = (1 as $iN) << id(0);
2739
assert_eq!(x, 1);
28-
let x = (1 as $uN) << 0;
40+
let x = (1 as $uN) << id(0);
2941
assert_eq!(x, 1);
30-
let x = (1 as $iN) << $max_rhs;
42+
let x = (1 as $iN) << id($max_rhs);
3143
assert_eq!(x, $expect_i);
32-
let x = (1 as $uN) << $max_rhs;
44+
let x = (1 as $uN) << id($max_rhs);
3345
assert_eq!(x, $expect_u);
3446
// high-order bits on LHS are silently discarded without panic.
35-
let x = (3 as $iN) << $max_rhs;
47+
let x = (3 as $iN) << id($max_rhs);
3648
assert_eq!(x, $expect_i);
37-
let x = (3 as $uN) << $max_rhs;
49+
let x = (3 as $uN) << id($max_rhs);
3850
assert_eq!(x, $expect_u);
3951
} }
4052
}
4153

42-
let x = 1_i8 << 0;
54+
let x = 1_i8 << id(0);
4355
assert_eq!(x, 1);
44-
let x = 1_u8 << 0;
56+
let x = 1_u8 << id(0);
4557
assert_eq!(x, 1);
46-
let x = 1_i8 << 7;
58+
let x = 1_i8 << id(7);
4759
assert_eq!(x, std::i8::MIN);
48-
let x = 1_u8 << 7;
60+
let x = 1_u8 << id(7);
4961
assert_eq!(x, 0x80);
5062
// high-order bits on LHS are silently discarded without panic.
51-
let x = 3_i8 << 7;
63+
let x = 3_i8 << id(7);
5264
assert_eq!(x, std::i8::MIN);
53-
let x = 3_u8 << 7;
65+
let x = 3_u8 << id(7);
5466
assert_eq!(x, 0x80);
5567

5668
// above is (approximately) expanded from:
@@ -68,23 +80,23 @@ fn test_right_shift() {
6880
($iN:ty, $uN:ty, $max_rhs:expr,
6981
$signbit_i:expr, $highbit_i:expr, $highbit_u:expr) =>
7082
{ {
71-
let x = (1 as $iN) >> 0;
83+
let x = (1 as $iN) >> id(0);
7284
assert_eq!(x, 1);
73-
let x = (1 as $uN) >> 0;
85+
let x = (1 as $uN) >> id(0);
7486
assert_eq!(x, 1);
75-
let x = ($highbit_i) >> $max_rhs-1;
87+
let x = ($highbit_i) >> id($max_rhs-1);
7688
assert_eq!(x, 1);
77-
let x = ($highbit_u) >> $max_rhs;
89+
let x = ($highbit_u) >> id($max_rhs);
7890
assert_eq!(x, 1);
7991
// sign-bit is carried by arithmetic right shift
80-
let x = ($signbit_i) >> $max_rhs;
92+
let x = ($signbit_i) >> id($max_rhs);
8193
assert_eq!(x, -1);
8294
// low-order bits on LHS are silently discarded without panic.
83-
let x = ($highbit_i + 1) >> $max_rhs-1;
95+
let x = ($highbit_i + 1) >> id($max_rhs-1);
8496
assert_eq!(x, 1);
85-
let x = ($highbit_u + 1) >> $max_rhs;
97+
let x = ($highbit_u + 1) >> id($max_rhs);
8698
assert_eq!(x, 1);
87-
let x = ($signbit_i + 1) >> $max_rhs;
99+
let x = ($signbit_i + 1) >> id($max_rhs);
88100
assert_eq!(x, -1);
89101
} }
90102
}

0 commit comments

Comments
 (0)