about summary refs log tree commit diff
path: root/tests/ui/codegen/shift-right-operand-mutation.rs
blob: b37a0baa6f8e77edd26c7cb486bf01aedb2a1f77 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
//! 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>.

//@ run-pass

pub fn main() {
    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);
    }
    assert_eq!(size_of::<usize>(), b);
}