Skip to content

Commit 452aa75

Browse files
Rollup merge of #77066 - jonas-schievink:dest-prop-borrow, r=oli-obk
Fix dest prop miscompilation around references Closes #77002
2 parents e8dc07c + 928a29f commit 452aa75

7 files changed

+205
-179
lines changed

compiler/rustc_mir/src/transform/dest_prop.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -905,7 +905,7 @@ impl<'a, 'tcx> Visitor<'tcx> for FindAssignments<'a, 'tcx> {
905905
// FIXME: This can be smarter and take `StorageDead` into account (which
906906
// invalidates borrows).
907907
if self.ever_borrowed_locals.contains(dest.local)
908-
&& self.ever_borrowed_locals.contains(src.local)
908+
|| self.ever_borrowed_locals.contains(src.local)
909909
{
910910
return;
911911
}

src/test/mir-opt/const_allocation3.main.ConstProp.after.32bit.mir

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ fn main() -> () {
2424
}
2525

2626
alloc0 (static: FOO, size: 4, align: 4) {
27-
╾─alloc3──╼ │ ╾──╼
27+
╾─alloc9──╼ │ ╾──╼
2828
}
2929

30-
alloc3 (size: 168, align: 1) {
30+
alloc9 (size: 168, align: 1) {
3131
0x00 │ ab ab ab ab ab ab ab ab ab ab ab ab ab ab ab ab │ ................
3232
0x10 │ ab ab ab ab ab ab ab ab ab ab ab ab ╾─alloc4──╼ │ ............╾──╼
3333
0x20 │ 01 ef cd ab 00 00 00 00 00 00 00 00 00 00 00 00 │ ................

src/test/mir-opt/const_allocation3.main.ConstProp.after.64bit.mir

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ fn main() -> () {
2424
}
2525

2626
alloc0 (static: FOO, size: 8, align: 8) {
27-
╾───────alloc3────────╼ │ ╾──────╼
27+
╾───────alloc9────────╼ │ ╾──────╼
2828
}
2929

30-
alloc3 (size: 180, align: 1) {
30+
alloc9 (size: 180, align: 1) {
3131
0x00 │ ab ab ab ab ab ab ab ab ab ab ab ab ab ab ab ab │ ................
3232
0x10 │ ab ab ab ab ab ab ab ab ab ab ab ab ╾──alloc4── │ ............╾───
3333
0x20 │ ──────────╼ 01 ef cd ab 00 00 00 00 00 00 00 00 │ ───╼............

src/test/mir-opt/dest-prop/simple.nrvo.DestinationPropagation.diff

+6-12
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,18 @@
1010
let mut _5: &mut [u8; 1024]; // in scope 0 at $DIR/simple.rs:6:10: 6:18
1111
let mut _6: &mut [u8; 1024]; // in scope 0 at $DIR/simple.rs:6:10: 6:18
1212
scope 1 {
13-
- debug buf => _2; // in scope 1 at $DIR/simple.rs:5:9: 5:16
14-
+ debug buf => _0; // in scope 1 at $DIR/simple.rs:5:9: 5:16
13+
debug buf => _2; // in scope 1 at $DIR/simple.rs:5:9: 5:16
1514
}
1615

1716
bb0: {
18-
- StorageLive(_2); // scope 0 at $DIR/simple.rs:5:9: 5:16
19-
- _2 = [const 0_u8; 1024]; // scope 0 at $DIR/simple.rs:5:19: 5:28
20-
+ nop; // scope 0 at $DIR/simple.rs:5:9: 5:16
21-
+ _0 = [const 0_u8; 1024]; // scope 0 at $DIR/simple.rs:5:19: 5:28
17+
StorageLive(_2); // scope 0 at $DIR/simple.rs:5:9: 5:16
18+
_2 = [const 0_u8; 1024]; // scope 0 at $DIR/simple.rs:5:19: 5:28
2219
StorageLive(_3); // scope 1 at $DIR/simple.rs:6:5: 6:19
2320
StorageLive(_4); // scope 1 at $DIR/simple.rs:6:5: 6:9
2421
_4 = _1; // scope 1 at $DIR/simple.rs:6:5: 6:9
2522
StorageLive(_5); // scope 1 at $DIR/simple.rs:6:10: 6:18
2623
StorageLive(_6); // scope 1 at $DIR/simple.rs:6:10: 6:18
27-
- _6 = &mut _2; // scope 1 at $DIR/simple.rs:6:10: 6:18
28-
+ _6 = &mut _0; // scope 1 at $DIR/simple.rs:6:10: 6:18
24+
_6 = &mut _2; // scope 1 at $DIR/simple.rs:6:10: 6:18
2925
_5 = &mut (*_6); // scope 1 at $DIR/simple.rs:6:10: 6:18
3026
_3 = move _4(move _5) -> bb1; // scope 1 at $DIR/simple.rs:6:5: 6:19
3127
}
@@ -35,10 +31,8 @@
3531
StorageDead(_4); // scope 1 at $DIR/simple.rs:6:18: 6:19
3632
StorageDead(_6); // scope 1 at $DIR/simple.rs:6:19: 6:20
3733
StorageDead(_3); // scope 1 at $DIR/simple.rs:6:19: 6:20
38-
- _0 = _2; // scope 1 at $DIR/simple.rs:7:5: 7:8
39-
- StorageDead(_2); // scope 0 at $DIR/simple.rs:8:1: 8:2
40-
+ nop; // scope 1 at $DIR/simple.rs:7:5: 7:8
41-
+ nop; // scope 0 at $DIR/simple.rs:8:1: 8:2
34+
_0 = _2; // scope 1 at $DIR/simple.rs:7:5: 7:8
35+
StorageDead(_2); // scope 0 at $DIR/simple.rs:8:1: 8:2
4236
return; // scope 0 at $DIR/simple.rs:8:2: 8:2
4337
}
4438
}

0 commit comments

Comments
 (0)