Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix dest prop miscompilation around references
  • Loading branch information
jonas-schievink committed Sep 22, 2020
1 parent e0bc267 commit 4b6a482
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion compiler/rustc_mir/src/transform/dest_prop.rs
Expand Up @@ -905,7 +905,7 @@ impl<'a, 'tcx> Visitor<'tcx> for FindAssignments<'a, 'tcx> {
// FIXME: This can be smarter and take `StorageDead` into account (which
// invalidates borrows).
if self.ever_borrowed_locals.contains(dest.local)
&& self.ever_borrowed_locals.contains(src.local)
|| self.ever_borrowed_locals.contains(src.local)
{
return;
}
Expand Down
16 changes: 16 additions & 0 deletions src/test/ui/issues/issue-77002.rs
@@ -0,0 +1,16 @@
// compile-flags: -Zmir-opt-level=2 -Copt-level=0
// run-pass

type M = [i64; 2];

fn f(a: &M) -> M {
let mut b: M = M::default();
b[0] = a[0] * a[0];
b
}

fn main() {
let mut a: M = [1, 1];
a = f(&a);
assert_eq!(a[0], 1);
}

0 comments on commit 4b6a482

Please sign in to comment.