Skip to content

Commit

Permalink
Rollup merge of rust-lang#77066 - jonas-schievink:dest-prop-borrow, r…
Browse files Browse the repository at this point in the history
…=oli-obk

Fix dest prop miscompilation around references

Closes rust-lang#77002
  • Loading branch information
Dylan-DPC authored Sep 24, 2020
2 parents 7075433 + 928a29f commit 1a66e27
Show file tree
Hide file tree
Showing 7 changed files with 205 additions and 179 deletions.
2 changes: 1 addition & 1 deletion compiler/rustc_mir/src/transform/dest_prop.rs
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ fn main() -> () {
}

alloc0 (static: FOO, size: 4, align: 4) {
╾─alloc3──╼ │ ╾──╼
╾─alloc9──╼ │ ╾──╼
}

alloc3 (size: 168, align: 1) {
alloc9 (size: 168, align: 1) {
0x00 │ ab ab ab ab ab ab ab ab ab ab ab ab ab ab ab ab │ ................
0x10 │ ab ab ab ab ab ab ab ab ab ab ab ab ╾─alloc4──╼ │ ............╾──╼
0x20 │ 01 ef cd ab 00 00 00 00 00 00 00 00 00 00 00 00 │ ................
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ fn main() -> () {
}

alloc0 (static: FOO, size: 8, align: 8) {
╾───────alloc3────────╼ │ ╾──────╼
╾───────alloc9────────╼ │ ╾──────╼
}

alloc3 (size: 180, align: 1) {
alloc9 (size: 180, align: 1) {
0x00 │ ab ab ab ab ab ab ab ab ab ab ab ab ab ab ab ab │ ................
0x10 │ ab ab ab ab ab ab ab ab ab ab ab ab ╾──alloc4── │ ............╾───
0x20 │ ──────────╼ 01 ef cd ab 00 00 00 00 00 00 00 00 │ ───╼............
Expand Down
18 changes: 6 additions & 12 deletions src/test/mir-opt/dest-prop/simple.nrvo.DestinationPropagation.diff
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,18 @@
let mut _5: &mut [u8; 1024]; // in scope 0 at $DIR/simple.rs:6:10: 6:18
let mut _6: &mut [u8; 1024]; // in scope 0 at $DIR/simple.rs:6:10: 6:18
scope 1 {
- debug buf => _2; // in scope 1 at $DIR/simple.rs:5:9: 5:16
+ debug buf => _0; // in scope 1 at $DIR/simple.rs:5:9: 5:16
debug buf => _2; // in scope 1 at $DIR/simple.rs:5:9: 5:16
}

bb0: {
- StorageLive(_2); // scope 0 at $DIR/simple.rs:5:9: 5:16
- _2 = [const 0_u8; 1024]; // scope 0 at $DIR/simple.rs:5:19: 5:28
+ nop; // scope 0 at $DIR/simple.rs:5:9: 5:16
+ _0 = [const 0_u8; 1024]; // scope 0 at $DIR/simple.rs:5:19: 5:28
StorageLive(_2); // scope 0 at $DIR/simple.rs:5:9: 5:16
_2 = [const 0_u8; 1024]; // scope 0 at $DIR/simple.rs:5:19: 5:28
StorageLive(_3); // scope 1 at $DIR/simple.rs:6:5: 6:19
StorageLive(_4); // scope 1 at $DIR/simple.rs:6:5: 6:9
_4 = _1; // scope 1 at $DIR/simple.rs:6:5: 6:9
StorageLive(_5); // scope 1 at $DIR/simple.rs:6:10: 6:18
StorageLive(_6); // scope 1 at $DIR/simple.rs:6:10: 6:18
- _6 = &mut _2; // scope 1 at $DIR/simple.rs:6:10: 6:18
+ _6 = &mut _0; // scope 1 at $DIR/simple.rs:6:10: 6:18
_6 = &mut _2; // scope 1 at $DIR/simple.rs:6:10: 6:18
_5 = &mut (*_6); // scope 1 at $DIR/simple.rs:6:10: 6:18
_3 = move _4(move _5) -> bb1; // scope 1 at $DIR/simple.rs:6:5: 6:19
}
Expand All @@ -35,10 +31,8 @@
StorageDead(_4); // scope 1 at $DIR/simple.rs:6:18: 6:19
StorageDead(_6); // scope 1 at $DIR/simple.rs:6:19: 6:20
StorageDead(_3); // scope 1 at $DIR/simple.rs:6:19: 6:20
- _0 = _2; // scope 1 at $DIR/simple.rs:7:5: 7:8
- StorageDead(_2); // scope 0 at $DIR/simple.rs:8:1: 8:2
+ nop; // scope 1 at $DIR/simple.rs:7:5: 7:8
+ nop; // scope 0 at $DIR/simple.rs:8:1: 8:2
_0 = _2; // scope 1 at $DIR/simple.rs:7:5: 7:8
StorageDead(_2); // scope 0 at $DIR/simple.rs:8:1: 8:2
return; // scope 0 at $DIR/simple.rs:8:2: 8:2
}
}
Expand Down
Loading

0 comments on commit 1a66e27

Please sign in to comment.