Rollup merge of #76977 - tmiasko:issue-76740, r=wesleywiser

Add a regression test for copy propagation miscompilation
This commit is contained in:
Ralf Jung 2020-09-21 15:30:42 +02:00 committed by GitHub
commit 9c14ef572f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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;
}
}