2025-07-01 02:46:47 +05:00
|
|
|
//! Ensure shift operations don't mutate their right operand.
|
|
|
|
|
//!
|
|
|
|
|
//! This test checks that expressions like `0 << b` don't accidentally
|
|
|
|
|
//! modify the variable `b` due to codegen issues with virtual registers.
|
|
|
|
|
//!
|
|
|
|
|
//! Regression test for <https://github.com/rust-lang/rust/issues/152>.
|
|
|
|
|
|
2024-02-16 20:02:50 +00:00
|
|
|
//@ run-pass
|
2019-07-27 00:54:25 +03:00
|
|
|
|
2013-02-01 19:43:17 -08:00
|
|
|
pub fn main() {
|
2025-07-01 02:46:47 +05:00
|
|
|
let mut b: usize = 1;
|
|
|
|
|
while b < size_of::<usize>() {
|
|
|
|
|
// This shift operation should not mutate `b`
|
|
|
|
|
let _ = 0_usize << b;
|
|
|
|
|
b <<= 1;
|
|
|
|
|
std::hint::black_box(b);
|
2011-12-22 14:42:52 -08:00
|
|
|
}
|
2025-07-01 02:46:47 +05:00
|
|
|
assert_eq!(size_of::<usize>(), b);
|
2011-12-22 14:42:52 -08:00
|
|
|
}
|