diff options
| author | Ralf Jung <post@ralfj.de> | 2020-09-21 15:30:42 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-09-21 15:30:42 +0200 |
| commit | 9c14ef572fd5bd032a5b86df8a5d2eadf5b935b5 (patch) | |
| tree | 8855c562dca5ba812c15e4e7d47aa4d7527b340d /src/test | |
| parent | b0c2eab66a4a59a66575e8afbfb9e707de2d7bd8 (diff) | |
| parent | 65edf54c256e5369fdf9c0a972cd83d2414d5bb5 (diff) | |
| download | rust-9c14ef572fd5bd032a5b86df8a5d2eadf5b935b5.tar.gz rust-9c14ef572fd5bd032a5b86df8a5d2eadf5b935b5.zip | |
Rollup merge of #76977 - tmiasko:issue-76740, r=wesleywiser
Add a regression test for copy propagation miscompilation
Diffstat (limited to 'src/test')
| -rw-r--r-- | src/test/ui/mir/issue-76740-copy-propagation.rs | 30 |
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; + } +} |
