Fix dest prop miscompilation around references

This commit is contained in:
Jonas Schievink 2020-09-22 20:19:00 +02:00
parent e0bc267512
commit 4b6a4821b7
2 changed files with 17 additions and 1 deletions

View file

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

View file

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