about summary refs log tree commit diff
path: root/tests/ui/codegen/shift-right-operand-mutation.rs
diff options
context:
space:
mode:
Diffstat (limited to 'tests/ui/codegen/shift-right-operand-mutation.rs')
-rw-r--r--tests/ui/codegen/shift-right-operand-mutation.rs19
1 files changed, 19 insertions, 0 deletions
diff --git a/tests/ui/codegen/shift-right-operand-mutation.rs b/tests/ui/codegen/shift-right-operand-mutation.rs
new file mode 100644
index 00000000000..b37a0baa6f8
--- /dev/null
+++ b/tests/ui/codegen/shift-right-operand-mutation.rs
@@ -0,0 +1,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);
+}