Skip to content

Commit 65edf54

Browse files
committed
Add a regression test for copy propagation miscompilation
1 parent b873fa6 commit 65edf54

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

Diff for: src/test/ui/mir/issue-76740-copy-propagation.rs

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Regression test for issue #76740.
2+
// run-fail FIXME: change to run-pass once #76899 lands
3+
// compile-flags: -Zmir-opt-level=3
4+
5+
#[derive(Copy, Clone)]
6+
pub struct V([usize; 4]);
7+
8+
impl V {
9+
fn new() -> Self {
10+
V([0; 4])
11+
}
12+
13+
#[inline(never)]
14+
fn check(mut self) {
15+
assert_eq!(self.0[0], 0);
16+
self.0[0] = 1;
17+
}
18+
}
19+
20+
fn main() {
21+
let v = V::new();
22+
let mut i = 0;
23+
while i != 10 {
24+
// Copy propagation incorrectly assumed that Operand::Move does not
25+
// mutate the local, and used the same v for each V::check call,
26+
// rather than a copy.
27+
v.check();
28+
i += 1;
29+
}
30+
}

0 commit comments

Comments
 (0)