Skip to content

Commit 6f49aad

Browse files
committed
Disable destination propagation on all mir-opt-levels
1 parent 51748a8 commit 6f49aad

15 files changed

+260
-147
lines changed

compiler/rustc_mir/src/transform/dest_prop.rs

+5
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,11 @@ pub struct DestinationPropagation;
127127

128128
impl<'tcx> MirPass<'tcx> for DestinationPropagation {
129129
fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
130+
// FIXME(#79191, #82678)
131+
if !tcx.sess.opts.debugging_opts.unsound_mir_opts {
132+
return;
133+
}
134+
130135
// Only run at mir-opt-level=3 or higher for now (we don't fix up debuginfo and remove
131136
// storage statements at the moment).
132137
if tcx.sess.mir_opt_level() < 3 {

src/test/mir-opt/deduplicate_blocks.is_line_doc_comment_2.DeduplicateBlocks.diff

+21-15
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,26 @@
55
debug s => _1; // in scope 0 at $DIR/deduplicate_blocks.rs:2:36: 2:37
66
let mut _0: bool; // return place in scope 0 at $DIR/deduplicate_blocks.rs:2:48: 2:52
77
let mut _2: &[u8]; // in scope 0 at $DIR/deduplicate_blocks.rs:3:11: 3:23
8-
let mut _3: usize; // in scope 0 at $DIR/deduplicate_blocks.rs:5:9: 5:31
9-
let mut _4: bool; // in scope 0 at $DIR/deduplicate_blocks.rs:5:9: 5:31
10-
let mut _5: usize; // in scope 0 at $DIR/deduplicate_blocks.rs:4:9: 4:37
11-
let mut _6: bool; // in scope 0 at $DIR/deduplicate_blocks.rs:4:9: 4:37
8+
let mut _3: &str; // in scope 0 at $DIR/deduplicate_blocks.rs:3:11: 3:12
9+
let mut _4: usize; // in scope 0 at $DIR/deduplicate_blocks.rs:5:9: 5:31
10+
let mut _5: bool; // in scope 0 at $DIR/deduplicate_blocks.rs:5:9: 5:31
11+
let mut _6: usize; // in scope 0 at $DIR/deduplicate_blocks.rs:4:9: 4:37
12+
let mut _7: bool; // in scope 0 at $DIR/deduplicate_blocks.rs:4:9: 4:37
1213
scope 1 (inlined core::str::<impl str>::as_bytes) { // at $DIR/deduplicate_blocks.rs:3:11: 3:23
13-
debug self => _7; // in scope 1 at $DIR/deduplicate_blocks.rs:3:11: 3:23
14-
let mut _7: &str; // in scope 1 at $DIR/deduplicate_blocks.rs:3:11: 3:23
14+
debug self => _3; // in scope 1 at $DIR/deduplicate_blocks.rs:3:11: 3:23
15+
let mut _8: &str; // in scope 1 at $DIR/deduplicate_blocks.rs:3:11: 3:23
1516
scope 2 {
1617
}
1718
}
1819

1920
bb0: {
2021
StorageLive(_2); // scope 0 at $DIR/deduplicate_blocks.rs:3:11: 3:23
21-
_7 = _1; // scope 0 at $DIR/deduplicate_blocks.rs:3:11: 3:12
22-
- _2 = transmute::<&str, &[u8]>(move _7) -> bb14; // scope 2 at $DIR/deduplicate_blocks.rs:3:11: 3:23
23-
+ _2 = transmute::<&str, &[u8]>(move _7) -> bb12; // scope 2 at $DIR/deduplicate_blocks.rs:3:11: 3:23
22+
StorageLive(_3); // scope 0 at $DIR/deduplicate_blocks.rs:3:11: 3:12
23+
_3 = _1; // scope 0 at $DIR/deduplicate_blocks.rs:3:11: 3:12
24+
StorageLive(_8); // scope 2 at $DIR/deduplicate_blocks.rs:3:11: 3:23
25+
_8 = _3; // scope 2 at $DIR/deduplicate_blocks.rs:3:11: 3:23
26+
- _2 = transmute::<&str, &[u8]>(move _8) -> bb14; // scope 2 at $DIR/deduplicate_blocks.rs:3:11: 3:23
27+
+ _2 = transmute::<&str, &[u8]>(move _8) -> bb12; // scope 2 at $DIR/deduplicate_blocks.rs:3:11: 3:23
2428
// mir::Constant
2529
// + span: $DIR/deduplicate_blocks.rs:3:11: 3:23
2630
// + literal: Const { ty: unsafe extern "rust-intrinsic" fn(&str) -> &[u8] {std::intrinsics::transmute::<&str, &[u8]>}, val: Value(Scalar(<ZST>)) }
@@ -44,9 +48,9 @@
4448
}
4549

4650
bb5: {
47-
_3 = Len((*_2)); // scope 0 at $DIR/deduplicate_blocks.rs:5:9: 5:31
48-
_4 = Ge(move _3, const 3_usize); // scope 0 at $DIR/deduplicate_blocks.rs:5:9: 5:31
49-
switchInt(move _4) -> [false: bb9, otherwise: bb6]; // scope 0 at $DIR/deduplicate_blocks.rs:5:9: 5:31
51+
_4 = Len((*_2)); // scope 0 at $DIR/deduplicate_blocks.rs:5:9: 5:31
52+
_5 = Ge(move _4, const 3_usize); // scope 0 at $DIR/deduplicate_blocks.rs:5:9: 5:31
53+
switchInt(move _5) -> [false: bb9, otherwise: bb6]; // scope 0 at $DIR/deduplicate_blocks.rs:5:9: 5:31
5054
}
5155

5256
bb6: {
@@ -93,9 +97,11 @@
9397

9498
- bb14: {
9599
+ bb12: {
96-
_5 = Len((*_2)); // scope 0 at $DIR/deduplicate_blocks.rs:4:9: 4:37
97-
_6 = Ge(move _5, const 4_usize); // scope 0 at $DIR/deduplicate_blocks.rs:4:9: 4:37
98-
switchInt(move _6) -> [false: bb5, otherwise: bb1]; // scope 0 at $DIR/deduplicate_blocks.rs:4:9: 4:37
100+
StorageDead(_8); // scope 2 at $DIR/deduplicate_blocks.rs:3:11: 3:23
101+
StorageDead(_3); // scope 0 at $DIR/deduplicate_blocks.rs:3:22: 3:23
102+
_6 = Len((*_2)); // scope 0 at $DIR/deduplicate_blocks.rs:4:9: 4:37
103+
_7 = Ge(move _6, const 4_usize); // scope 0 at $DIR/deduplicate_blocks.rs:4:9: 4:37
104+
switchInt(move _7) -> [false: bb5, otherwise: bb1]; // scope 0 at $DIR/deduplicate_blocks.rs:4:9: 4:37
99105
}
100106
}
101107

src/test/mir-opt/dest-prop/branch.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//! Tests that assignment in both branches of an `if` are eliminated.
2-
2+
// compile-flags: -Zunsound-mir-opts
33
fn val() -> i32 {
44
1
55
}

src/test/mir-opt/dest-prop/copy_propagation_arg.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Check that DestinationPropagation does not propagate an assignment to a function argument
22
// (doing so can break usages of the original argument value)
3-
3+
// compile-flags: -Zunsound-mir-opts
44
fn dummy(x: u8) -> u8 {
55
x
66
}

src/test/mir-opt/dest-prop/cycle.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//! Tests that cyclic assignments don't hang DestinationPropagation, and result in reasonable code.
2-
2+
// compile-flags: -Zunsound-mir-opts
33
fn val() -> i32 {
44
1
55
}

src/test/mir-opt/dest-prop/simple.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//! Copy of `nrvo-simple.rs`, to ensure that full dest-prop handles it too.
2-
2+
// compile-flags: -Zunsound-mir-opts
33
// EMIT_MIR simple.nrvo.DestinationPropagation.diff
44
fn nrvo(init: fn(&mut [u8; 1024])) -> [u8; 1024] {
55
let mut buf = [0; 1024];

src/test/mir-opt/dest-prop/union.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//! Tests that projections through unions cancel `DestinationPropagation`.
2-
2+
// compile-flags: -Zunsound-mir-opts
33
fn val() -> u32 {
44
1
55
}

src/test/mir-opt/inline/inline_closure_captures.foo.Inline.after.mir

+8-4
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ fn foo(_1: T, _2: i32) -> (i32, T) {
1717
debug _q => _9; // in scope 2 at $DIR/inline-closure-captures.rs:12:5: 12:9
1818
debug q => (*((*_6).0: &i32)); // in scope 2 at $DIR/inline-closure-captures.rs:12:5: 12:9
1919
debug t => (*((*_6).1: &T)); // in scope 2 at $DIR/inline-closure-captures.rs:12:5: 12:9
20-
let mut _10: T; // in scope 2 at $DIR/inline-closure-captures.rs:12:5: 12:9
20+
let mut _10: i32; // in scope 2 at $DIR/inline-closure-captures.rs:12:5: 12:9
21+
let mut _11: T; // in scope 2 at $DIR/inline-closure-captures.rs:12:5: 12:9
2122
}
2223
}
2324

@@ -39,10 +40,13 @@ fn foo(_1: T, _2: i32) -> (i32, T) {
3940
(_7.0: i32) = move _8; // scope 1 at $DIR/inline-closure-captures.rs:12:5: 12:9
4041
StorageLive(_9); // scope 1 at $DIR/inline-closure-captures.rs:12:5: 12:9
4142
_9 = move (_7.0: i32); // scope 1 at $DIR/inline-closure-captures.rs:12:5: 12:9
42-
(_0.0: i32) = (*((*_6).0: &i32)); // scope 2 at $DIR/inline-closure-captures.rs:12:5: 12:9
4343
StorageLive(_10); // scope 2 at $DIR/inline-closure-captures.rs:12:5: 12:9
44-
_10 = (*((*_6).1: &T)); // scope 2 at $DIR/inline-closure-captures.rs:12:5: 12:9
45-
(_0.1: T) = move _10; // scope 2 at $DIR/inline-closure-captures.rs:12:5: 12:9
44+
_10 = (*((*_6).0: &i32)); // scope 2 at $DIR/inline-closure-captures.rs:12:5: 12:9
45+
StorageLive(_11); // scope 2 at $DIR/inline-closure-captures.rs:12:5: 12:9
46+
_11 = (*((*_6).1: &T)); // scope 2 at $DIR/inline-closure-captures.rs:12:5: 12:9
47+
(_0.0: i32) = move _10; // scope 2 at $DIR/inline-closure-captures.rs:12:5: 12:9
48+
(_0.1: T) = move _11; // scope 2 at $DIR/inline-closure-captures.rs:12:5: 12:9
49+
StorageDead(_11); // scope 2 at $DIR/inline-closure-captures.rs:12:5: 12:9
4650
StorageDead(_10); // scope 2 at $DIR/inline-closure-captures.rs:12:5: 12:9
4751
StorageDead(_9); // scope 1 at $DIR/inline-closure-captures.rs:12:5: 12:9
4852
StorageDead(_8); // scope 1 at $DIR/inline-closure-captures.rs:12:8: 12:9

src/test/mir-opt/inline/inline_diverging.h.Inline.diff

+9-8
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,20 @@
55
let mut _0: (); // return place in scope 0 at $DIR/inline-diverging.rs:21:12: 21:12
66
let _1: (!, !); // in scope 0 at $DIR/inline-diverging.rs:22:5: 22:22
77
+ let mut _2: fn() -> ! {sleep}; // in scope 0 at $DIR/inline-diverging.rs:22:5: 22:22
8-
+ let mut _7: (); // in scope 0 at $DIR/inline-diverging.rs:22:5: 22:22
9-
+ let mut _8: (); // in scope 0 at $DIR/inline-diverging.rs:22:5: 22:22
8+
+ let mut _9: (); // in scope 0 at $DIR/inline-diverging.rs:22:5: 22:22
9+
+ let mut _10: (); // in scope 0 at $DIR/inline-diverging.rs:22:5: 22:22
1010
+ scope 1 (inlined call_twice::<!, fn() -> ! {sleep}>) { // at $DIR/inline-diverging.rs:22:5: 22:22
1111
+ debug f => _2; // in scope 1 at $DIR/inline-diverging.rs:22:5: 22:22
1212
+ let _3: !; // in scope 1 at $DIR/inline-diverging.rs:22:5: 22:22
1313
+ let mut _4: &fn() -> ! {sleep}; // in scope 1 at $DIR/inline-diverging.rs:22:5: 22:22
14-
+ let mut _5: &fn() -> ! {sleep}; // in scope 1 at $DIR/inline-diverging.rs:22:5: 22:22
15-
+ let mut _6: !; // in scope 1 at $DIR/inline-diverging.rs:22:5: 22:22
14+
+ let mut _6: &fn() -> ! {sleep}; // in scope 1 at $DIR/inline-diverging.rs:22:5: 22:22
15+
+ let mut _7: !; // in scope 1 at $DIR/inline-diverging.rs:22:5: 22:22
16+
+ let mut _8: !; // in scope 1 at $DIR/inline-diverging.rs:22:5: 22:22
1617
+ scope 2 {
1718
+ debug a => _3; // in scope 2 at $DIR/inline-diverging.rs:22:5: 22:22
19+
+ let _5: !; // in scope 2 at $DIR/inline-diverging.rs:22:5: 22:22
1820
+ scope 3 {
19-
+ debug b => _6; // in scope 3 at $DIR/inline-diverging.rs:22:5: 22:22
21+
+ debug b => _5; // in scope 3 at $DIR/inline-diverging.rs:22:5: 22:22
2022
+ }
2123
+ scope 6 (inlined <fn() -> ! {sleep} as Fn<()>>::call - shim(fn() -> ! {sleep})) { // at $DIR/inline-diverging.rs:22:5: 22:22
2224
+ scope 7 (inlined sleep) { // at $DIR/inline-diverging.rs:22:5: 22:22
@@ -40,12 +42,11 @@
4042
- // mir::Constant
4143
// + span: $DIR/inline-diverging.rs:22:16: 22:21
4244
// + literal: Const { ty: fn() -> ! {sleep}, val: Value(Scalar(<ZST>)) }
43-
+ StorageLive(_6); // scope 0 at $DIR/inline-diverging.rs:22:5: 22:22
4445
+ StorageLive(_3); // scope 1 at $DIR/inline-diverging.rs:22:5: 22:22
4546
+ StorageLive(_4); // scope 1 at $DIR/inline-diverging.rs:22:5: 22:22
4647
+ _4 = &_2; // scope 1 at $DIR/inline-diverging.rs:22:5: 22:22
47-
+ StorageLive(_7); // scope 1 at $DIR/inline-diverging.rs:22:5: 22:22
48-
+ _7 = const (); // scope 1 at $DIR/inline-diverging.rs:22:5: 22:22
48+
+ StorageLive(_9); // scope 1 at $DIR/inline-diverging.rs:22:5: 22:22
49+
+ _9 = const (); // scope 1 at $DIR/inline-diverging.rs:22:5: 22:22
4950
+ goto -> bb1; // scope 4 at $DIR/inline-diverging.rs:22:5: 22:22
5051
}
5152

src/test/mir-opt/inline/inline_generator.main.Inline.diff

+27-14
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,12 @@
2424
+ }
2525
+ }
2626
+ scope 6 (inlined g::{closure#0}) { // at $DIR/inline-generator.rs:9:14: 9:46
27-
+ debug a => _8; // in scope 6 at $DIR/inline-generator.rs:9:14: 9:46
28-
+ let mut _8: bool; // in scope 6 at $DIR/inline-generator.rs:9:14: 9:46
29-
+ let mut _9: u32; // in scope 6 at $DIR/inline-generator.rs:9:14: 9:46
27+
+ debug a => _11; // in scope 6 at $DIR/inline-generator.rs:9:14: 9:46
28+
+ let mut _8: i32; // in scope 6 at $DIR/inline-generator.rs:9:14: 9:46
29+
+ let mut _9: bool; // in scope 6 at $DIR/inline-generator.rs:9:14: 9:46
30+
+ let mut _10: bool; // in scope 6 at $DIR/inline-generator.rs:9:14: 9:46
31+
+ let _11: bool; // in scope 6 at $DIR/inline-generator.rs:9:14: 9:46
32+
+ let mut _12: u32; // in scope 6 at $DIR/inline-generator.rs:9:14: 9:46
3033
+ }
3134

3235
bb0: {
@@ -65,16 +68,18 @@
6568
- // + literal: Const { ty: for<'r> fn(std::pin::Pin<&'r mut impl std::ops::Generator<bool>>, bool) -> std::ops::GeneratorState<<impl std::ops::Generator<bool> as std::ops::Generator<bool>>::Yield, <impl std::ops::Generator<bool> as std::ops::Generator<bool>>::Return> {<impl std::ops::Generator<bool> as std::ops::Generator<bool>>::resume}, val: Value(Scalar(<ZST>)) }
6669
+ StorageLive(_7); // scope 0 at $DIR/inline-generator.rs:9:14: 9:46
6770
+ _7 = const false; // scope 0 at $DIR/inline-generator.rs:9:14: 9:46
68-
+ StorageLive(_8); // scope 0 at $DIR/inline-generator.rs:9:14: 9:46
69-
+ StorageLive(_9); // scope 0 at $DIR/inline-generator.rs:9:14: 9:46
70-
+ _9 = discriminant((*(_2.0: &mut [generator@$DIR/inline-generator.rs:15:5: 15:41 {bool, i32}]))); // scope 6 at $DIR/inline-generator.rs:9:14: 9:46
71-
+ switchInt(move _9) -> [0_u32: bb3, 1_u32: bb8, 3_u32: bb7, otherwise: bb9]; // scope 6 at $DIR/inline-generator.rs:9:14: 9:46
71+
+ StorageLive(_10); // scope 0 at $DIR/inline-generator.rs:9:14: 9:46
72+
+ StorageLive(_11); // scope 0 at $DIR/inline-generator.rs:9:14: 9:46
73+
+ StorageLive(_12); // scope 0 at $DIR/inline-generator.rs:9:14: 9:46
74+
+ _12 = discriminant((*(_2.0: &mut [generator@$DIR/inline-generator.rs:15:5: 15:41 {bool, i32}]))); // scope 6 at $DIR/inline-generator.rs:9:14: 9:46
75+
+ switchInt(move _12) -> [0_u32: bb3, 1_u32: bb8, 3_u32: bb7, otherwise: bb9]; // scope 6 at $DIR/inline-generator.rs:9:14: 9:46
7276
}
7377

7478
- bb3: {
7579
+ bb1: {
76-
+ StorageDead(_9); // scope 0 at $DIR/inline-generator.rs:9:14: 9:46
77-
+ StorageDead(_8); // scope 0 at $DIR/inline-generator.rs:9:14: 9:46
80+
+ StorageDead(_12); // scope 0 at $DIR/inline-generator.rs:9:14: 9:46
81+
+ StorageDead(_11); // scope 0 at $DIR/inline-generator.rs:9:14: 9:46
82+
+ StorageDead(_10); // scope 0 at $DIR/inline-generator.rs:9:14: 9:46
7883
+ StorageDead(_7); // scope 0 at $DIR/inline-generator.rs:9:14: 9:46
7984
StorageDead(_2); // scope 0 at $DIR/inline-generator.rs:9:45: 9:46
8085
StorageDead(_4); // scope 0 at $DIR/inline-generator.rs:9:46: 9:47
@@ -89,28 +94,36 @@
8994
+ }
9095
+
9196
+ bb3: {
92-
+ _8 = move _7; // scope 6 at $DIR/inline-generator.rs:9:14: 9:46
93-
+ switchInt(move _8) -> [false: bb5, otherwise: bb4]; // scope 6 at $DIR/inline-generator.rs:9:14: 9:46
97+
+ _11 = move _7; // scope 6 at $DIR/inline-generator.rs:9:14: 9:46
98+
+ StorageLive(_8); // scope 6 at $DIR/inline-generator.rs:9:14: 9:46
99+
+ StorageLive(_9); // scope 6 at $DIR/inline-generator.rs:9:14: 9:46
100+
+ _9 = _11; // scope 6 at $DIR/inline-generator.rs:9:14: 9:46
101+
+ switchInt(move _9) -> [false: bb5, otherwise: bb4]; // scope 6 at $DIR/inline-generator.rs:9:14: 9:46
94102
+ }
95103
+
96104
+ bb4: {
97-
+ ((_1 as Yielded).0: i32) = const 7_i32; // scope 6 at $DIR/inline-generator.rs:9:14: 9:46
105+
+ _8 = const 7_i32; // scope 6 at $DIR/inline-generator.rs:9:14: 9:46
98106
+ goto -> bb6; // scope 6 at $DIR/inline-generator.rs:9:14: 9:46
99107
+ }
100108
+
101109
+ bb5: {
102-
+ ((_1 as Yielded).0: i32) = const 13_i32; // scope 6 at $DIR/inline-generator.rs:9:14: 9:46
110+
+ _8 = const 13_i32; // scope 6 at $DIR/inline-generator.rs:9:14: 9:46
103111
+ goto -> bb6; // scope 6 at $DIR/inline-generator.rs:9:14: 9:46
104112
+ }
105113
+
106114
+ bb6: {
115+
+ StorageDead(_9); // scope 6 at $DIR/inline-generator.rs:9:14: 9:46
116+
+ ((_1 as Yielded).0: i32) = move _8; // scope 6 at $DIR/inline-generator.rs:9:14: 9:46
107117
+ discriminant(_1) = 0; // scope 6 at $DIR/inline-generator.rs:9:14: 9:46
108118
+ discriminant((*(_2.0: &mut [generator@$DIR/inline-generator.rs:15:5: 15:41 {bool, i32}]))) = 3; // scope 6 at $DIR/inline-generator.rs:9:14: 9:46
109119
+ goto -> bb1; // scope 0 at $DIR/inline-generator.rs:15:11: 15:39
110120
+ }
111121
+
112122
+ bb7: {
113-
+ ((_1 as Complete).0: bool) = move _7; // scope 6 at $DIR/inline-generator.rs:9:14: 9:46
123+
+ StorageLive(_8); // scope 6 at $DIR/inline-generator.rs:9:14: 9:46
124+
+ _10 = move _7; // scope 6 at $DIR/inline-generator.rs:9:14: 9:46
125+
+ StorageDead(_8); // scope 6 at $DIR/inline-generator.rs:9:14: 9:46
126+
+ ((_1 as Complete).0: bool) = move _10; // scope 6 at $DIR/inline-generator.rs:9:14: 9:46
114127
+ discriminant(_1) = 1; // scope 6 at $DIR/inline-generator.rs:9:14: 9:46
115128
+ discriminant((*(_2.0: &mut [generator@$DIR/inline-generator.rs:15:5: 15:41 {bool, i32}]))) = 1; // scope 6 at $DIR/inline-generator.rs:9:14: 9:46
116129
+ goto -> bb1; // scope 0 at $DIR/inline-generator.rs:15:41: 15:41

0 commit comments

Comments
 (0)