about summary refs log tree commit diff
diff options
context:
space:
mode:
authorTomasz Miąsko <tomasz.miasko@gmail.com>2020-09-20 00:00:00 +0000
committerTomasz Miąsko <tomasz.miasko@gmail.com>2020-09-20 00:00:00 +0000
commit65edf54c256e5369fdf9c0a972cd83d2414d5bb5 (patch)
tree3ac2788f1f7c15259ff5ae45baed4af68a20a9d2
parentb873fa6d42cf305131d2583d03b84686e5e40f2e (diff)
downloadrust-65edf54c256e5369fdf9c0a972cd83d2414d5bb5.tar.gz
rust-65edf54c256e5369fdf9c0a972cd83d2414d5bb5.zip
Add a regression test for copy propagation miscompilation
-rw-r--r--src/test/ui/mir/issue-76740-copy-propagation.rs30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/test/ui/mir/issue-76740-copy-propagation.rs b/src/test/ui/mir/issue-76740-copy-propagation.rs
new file mode 100644
index 00000000000..e3283949b26
--- /dev/null
+++ b/src/test/ui/mir/issue-76740-copy-propagation.rs
@@ -0,0 +1,30 @@
+// Regression test for issue #76740.
+// run-fail FIXME: change to run-pass once #76899 lands
+// compile-flags: -Zmir-opt-level=3
+
+#[derive(Copy, Clone)]
+pub struct V([usize; 4]);
+
+impl V {
+    fn new() -> Self {
+        V([0; 4])
+    }
+
+    #[inline(never)]
+    fn check(mut self) {
+        assert_eq!(self.0[0], 0);
+        self.0[0] = 1;
+    }
+}
+
+fn main() {
+    let v = V::new();
+    let mut i = 0;
+    while i != 10 {
+        // Copy propagation incorrectly assumed that Operand::Move does not
+        // mutate the local, and used the same v for each V::check call,
+        // rather than a copy.
+        v.check();
+        i += 1;
+    }
+}