Skip to content

Commit 38b44eb

Browse files
committed
Auto merge of #112834 - oli-obk:mir_opts_considered_unsound, r=cjgillot
Disable two mir opts that are known to be unsound closes #112460 (does not fix the underlying issue) r? `@cjgillot`
2 parents 97bf23d + c409f05 commit 38b44eb

9 files changed

+164
-171
lines changed

compiler/rustc_mir_transform/src/const_goto.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ pub struct ConstGoto;
2828

2929
impl<'tcx> MirPass<'tcx> for ConstGoto {
3030
fn is_enabled(&self, sess: &rustc_session::Session) -> bool {
31-
sess.mir_opt_level() >= 2
31+
// This pass participates in some as-of-yet untested unsoundness found
32+
// in https://github.com/rust-lang/rust/issues/112460
33+
sess.mir_opt_level() >= 2 && sess.opts.unstable_opts.unsound_mir_opts
3234
}
3335

3436
fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {

compiler/rustc_mir_transform/src/separate_const_switch.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@ pub struct SeparateConstSwitch;
4646

4747
impl<'tcx> MirPass<'tcx> for SeparateConstSwitch {
4848
fn is_enabled(&self, sess: &rustc_session::Session) -> bool {
49-
sess.mir_opt_level() >= 2
49+
// This pass participates in some as-of-yet untested unsoundness found
50+
// in https://github.com/rust-lang/rust/issues/112460
51+
sess.mir_opt_level() >= 2 && sess.opts.unstable_opts.unsound_mir_opts
5052
}
5153

5254
fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {

tests/mir-opt/const_goto_const_eval_fail.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#![feature(min_const_generics)]
22
#![crate_type = "lib"]
33

4+
// compile-flags: -Zunsound-mir-opts
5+
46
// If const eval fails, then don't crash
57
// EMIT_MIR const_goto_const_eval_fail.f.ConstGoto.diff
68
pub fn f<const A: i32, const B: bool>() -> u64 {

tests/mir-opt/pre-codegen/chained_comparison.naive.PreCodegen.after.mir

+62-53
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,26 @@ fn naive(_1: &Blueprint, _2: &Blueprint) -> bool {
77
let mut _3: u32;
88
let mut _4: u32;
99
let mut _5: bool;
10-
let mut _6: u32;
10+
let mut _6: bool;
1111
let mut _7: u32;
12-
let mut _8: bool;
12+
let mut _8: u32;
1313
let mut _9: bool;
14-
let mut _10: u32;
14+
let mut _10: bool;
1515
let mut _11: u32;
16-
let mut _12: bool;
16+
let mut _12: u32;
1717
let mut _13: bool;
18-
let mut _14: u32;
18+
let mut _14: bool;
1919
let mut _15: u32;
20-
let mut _16: bool;
20+
let mut _16: u32;
2121
let mut _17: bool;
2222
let mut _18: u32;
2323
let mut _19: u32;
2424
let mut _20: bool;
2525

2626
bb0: {
27-
StorageLive(_17);
28-
StorageLive(_13);
29-
StorageLive(_9);
27+
StorageLive(_14);
28+
StorageLive(_10);
29+
StorageLive(_6);
3030
StorageLive(_5);
3131
StorageLive(_3);
3232
_3 = ((*_1).0: u32);
@@ -39,74 +39,83 @@ fn naive(_1: &Blueprint, _2: &Blueprint) -> bool {
3939
}
4040

4141
bb1: {
42-
StorageDead(_8);
43-
StorageDead(_5);
42+
_6 = const false;
4443
goto -> bb3;
4544
}
4645

4746
bb2: {
48-
StorageLive(_8);
49-
StorageLive(_6);
50-
_6 = ((*_1).1: u32);
47+
StorageLive(_9);
5148
StorageLive(_7);
52-
_7 = ((*_2).1: u32);
53-
_8 = Eq(move _6, move _7);
54-
StorageDead(_7);
55-
StorageDead(_6);
56-
_9 = move _8;
49+
_7 = ((*_1).1: u32);
50+
StorageLive(_8);
51+
_8 = ((*_2).1: u32);
52+
_9 = Eq(move _7, move _8);
5753
StorageDead(_8);
58-
StorageDead(_5);
59-
switchInt(move _9) -> [0: bb3, otherwise: bb4];
54+
StorageDead(_7);
55+
_6 = move _9;
56+
goto -> bb3;
6057
}
6158

6259
bb3: {
63-
StorageDead(_12);
6460
StorageDead(_9);
65-
goto -> bb5;
61+
StorageDead(_5);
62+
switchInt(move _6) -> [0: bb4, otherwise: bb5];
6663
}
6764

6865
bb4: {
69-
StorageLive(_12);
70-
StorageLive(_10);
71-
_10 = ((*_1).2: u32);
72-
StorageLive(_11);
73-
_11 = ((*_2).2: u32);
74-
_12 = Eq(move _10, move _11);
75-
StorageDead(_11);
76-
StorageDead(_10);
77-
_13 = move _12;
78-
StorageDead(_12);
79-
StorageDead(_9);
80-
switchInt(move _13) -> [0: bb5, otherwise: bb6];
66+
_10 = const false;
67+
goto -> bb6;
8168
}
8269

8370
bb5: {
84-
StorageDead(_16);
85-
StorageDead(_13);
86-
goto -> bb7;
71+
StorageLive(_13);
72+
StorageLive(_11);
73+
_11 = ((*_1).2: u32);
74+
StorageLive(_12);
75+
_12 = ((*_2).2: u32);
76+
_13 = Eq(move _11, move _12);
77+
StorageDead(_12);
78+
StorageDead(_11);
79+
_10 = move _13;
80+
goto -> bb6;
8781
}
8882

8983
bb6: {
90-
StorageLive(_16);
91-
StorageLive(_14);
92-
_14 = ((*_1).3: u32);
93-
StorageLive(_15);
94-
_15 = ((*_2).3: u32);
95-
_16 = Eq(move _14, move _15);
96-
StorageDead(_15);
97-
StorageDead(_14);
98-
_17 = move _16;
99-
StorageDead(_16);
10084
StorageDead(_13);
101-
switchInt(move _17) -> [0: bb7, otherwise: bb8];
85+
StorageDead(_6);
86+
switchInt(move _10) -> [0: bb7, otherwise: bb8];
10287
}
10388

10489
bb7: {
105-
_0 = const false;
90+
_14 = const false;
10691
goto -> bb9;
10792
}
10893

10994
bb8: {
95+
StorageLive(_17);
96+
StorageLive(_15);
97+
_15 = ((*_1).3: u32);
98+
StorageLive(_16);
99+
_16 = ((*_2).3: u32);
100+
_17 = Eq(move _15, move _16);
101+
StorageDead(_16);
102+
StorageDead(_15);
103+
_14 = move _17;
104+
goto -> bb9;
105+
}
106+
107+
bb9: {
108+
StorageDead(_17);
109+
StorageDead(_10);
110+
switchInt(move _14) -> [0: bb10, otherwise: bb11];
111+
}
112+
113+
bb10: {
114+
_0 = const false;
115+
goto -> bb12;
116+
}
117+
118+
bb11: {
110119
StorageLive(_20);
111120
StorageLive(_18);
112121
_18 = ((*_1).4: u32);
@@ -116,12 +125,12 @@ fn naive(_1: &Blueprint, _2: &Blueprint) -> bool {
116125
StorageDead(_19);
117126
StorageDead(_18);
118127
_0 = move _20;
119-
goto -> bb9;
128+
goto -> bb12;
120129
}
121130

122-
bb9: {
131+
bb12: {
123132
StorageDead(_20);
124-
StorageDead(_17);
133+
StorageDead(_14);
125134
return;
126135
}
127136
}

tests/mir-opt/pre-codegen/slice_filter.variant_a-{closure#0}.PreCodegen.after.mir

+45-42
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ fn variant_a::{closure#0}(_1: &mut [closure@$DIR/slice_filter.rs:7:25: 7:39], _2
1414
let _12: &usize;
1515
let mut _13: &&usize;
1616
let mut _18: bool;
17-
let mut _19: &&usize;
18-
let _20: &usize;
19-
let mut _21: &&usize;
20-
let mut _26: bool;
17+
let mut _19: bool;
18+
let mut _20: &&usize;
19+
let _21: &usize;
20+
let mut _22: &&usize;
2121
let mut _27: bool;
2222
let mut _28: &&usize;
2323
let _29: &usize;
@@ -58,15 +58,15 @@ fn variant_a::{closure#0}(_1: &mut [closure@$DIR/slice_filter.rs:7:25: 7:39], _2
5858
}
5959
}
6060
scope 6 (inlined cmp::impls::<impl PartialOrd for &usize>::le) {
61-
debug self => _19;
62-
debug other => _21;
63-
let mut _22: &usize;
61+
debug self => _20;
62+
debug other => _22;
6463
let mut _23: &usize;
64+
let mut _24: &usize;
6565
scope 7 (inlined cmp::impls::<impl PartialOrd for usize>::le) {
66-
debug self => _22;
67-
debug other => _23;
68-
let mut _24: usize;
66+
debug self => _23;
67+
debug other => _24;
6968
let mut _25: usize;
69+
let mut _26: usize;
7070
}
7171
}
7272
scope 8 (inlined cmp::impls::<impl PartialOrd for &usize>::le) {
@@ -96,7 +96,7 @@ fn variant_a::{closure#0}(_1: &mut [closure@$DIR/slice_filter.rs:7:25: 7:39], _2
9696
StorageLive(_10);
9797
_9 = deref_copy (*_2);
9898
_10 = &((*_9).3: usize);
99-
StorageLive(_27);
99+
StorageLive(_19);
100100
StorageLive(_18);
101101
StorageLive(_11);
102102
_11 = &_4;
@@ -120,38 +120,41 @@ fn variant_a::{closure#0}(_1: &mut [closure@$DIR/slice_filter.rs:7:25: 7:39], _2
120120
}
121121

122122
bb1: {
123-
StorageDead(_26);
124-
StorageDead(_18);
123+
_19 = const false;
125124
goto -> bb3;
126125
}
127126

128127
bb2: {
129-
StorageLive(_26);
130-
StorageLive(_19);
131-
_19 = &_10;
132-
StorageLive(_21);
128+
StorageLive(_27);
133129
StorageLive(_20);
134-
_20 = _6;
135-
_21 = &_20;
136-
_22 = deref_copy (*_19);
137-
_23 = deref_copy (*_21);
138-
StorageLive(_24);
139-
_24 = (*_22);
130+
_20 = &_10;
131+
StorageLive(_22);
132+
StorageLive(_21);
133+
_21 = _6;
134+
_22 = &_21;
135+
_23 = deref_copy (*_20);
136+
_24 = deref_copy (*_22);
140137
StorageLive(_25);
141138
_25 = (*_23);
142-
_26 = Le(move _24, move _25);
139+
StorageLive(_26);
140+
_26 = (*_24);
141+
_27 = Le(move _25, move _26);
142+
StorageDead(_26);
143143
StorageDead(_25);
144-
StorageDead(_24);
145-
StorageDead(_20);
146144
StorageDead(_21);
147-
StorageDead(_19);
148-
_27 = move _26;
149-
StorageDead(_26);
150-
StorageDead(_18);
151-
switchInt(move _27) -> [0: bb3, otherwise: bb7];
145+
StorageDead(_22);
146+
StorageDead(_20);
147+
_19 = move _27;
148+
goto -> bb3;
152149
}
153150

154151
bb3: {
152+
StorageDead(_27);
153+
StorageDead(_18);
154+
switchInt(move _19) -> [0: bb4, otherwise: bb8];
155+
}
156+
157+
bb4: {
155158
StorageLive(_36);
156159
StorageLive(_35);
157160
StorageLive(_28);
@@ -172,15 +175,15 @@ fn variant_a::{closure#0}(_1: &mut [closure@$DIR/slice_filter.rs:7:25: 7:39], _2
172175
StorageDead(_29);
173176
StorageDead(_30);
174177
StorageDead(_28);
175-
switchInt(move _35) -> [0: bb4, otherwise: bb5];
178+
switchInt(move _35) -> [0: bb5, otherwise: bb6];
176179
}
177180

178-
bb4: {
181+
bb5: {
179182
_36 = const false;
180-
goto -> bb6;
183+
goto -> bb7;
181184
}
182185

183-
bb5: {
186+
bb6: {
184187
StorageLive(_44);
185188
StorageLive(_37);
186189
_37 = &_6;
@@ -201,24 +204,24 @@ fn variant_a::{closure#0}(_1: &mut [closure@$DIR/slice_filter.rs:7:25: 7:39], _2
201204
StorageDead(_39);
202205
StorageDead(_37);
203206
_36 = move _44;
204-
goto -> bb6;
207+
goto -> bb7;
205208
}
206209

207-
bb6: {
210+
bb7: {
208211
StorageDead(_44);
209212
StorageDead(_35);
210213
_0 = move _36;
211-
goto -> bb8;
214+
goto -> bb9;
212215
}
213216

214-
bb7: {
217+
bb8: {
215218
_0 = const true;
216-
goto -> bb8;
219+
goto -> bb9;
217220
}
218221

219-
bb8: {
222+
bb9: {
220223
StorageDead(_36);
221-
StorageDead(_27);
224+
StorageDead(_19);
222225
StorageDead(_10);
223226
StorageDead(_8);
224227
StorageDead(_6);

0 commit comments

Comments
 (0)