Skip to content

Add a regression test for copy propagation miscompilation #76977

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 21, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions src/test/ui/mir/issue-76740-copy-propagation.rs
Original file line number Diff line number Diff line change
@@ -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;
}
}