Skip to content

Disable two mir opts that are known to be unsound #112834

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion compiler/rustc_mir_transform/src/const_goto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ pub struct ConstGoto;

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be good to link to some form of explanation of what is unsound here.

}

fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
Expand Down
4 changes: 3 additions & 1 deletion compiler/rustc_mir_transform/src/separate_const_switch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ pub struct SeparateConstSwitch;

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

fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
Expand Down
2 changes: 2 additions & 0 deletions tests/mir-opt/const_goto_const_eval_fail.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#![feature(min_const_generics)]
#![crate_type = "lib"]

// compile-flags: -Zunsound-mir-opts

// If const eval fails, then don't crash
// EMIT_MIR const_goto_const_eval_fail.f.ConstGoto.diff
pub fn f<const A: i32, const B: bool>() -> u64 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,26 @@ fn naive(_1: &Blueprint, _2: &Blueprint) -> bool {
let mut _3: u32;
let mut _4: u32;
let mut _5: bool;
let mut _6: u32;
let mut _6: bool;
let mut _7: u32;
let mut _8: bool;
let mut _8: u32;
let mut _9: bool;
let mut _10: u32;
let mut _10: bool;
let mut _11: u32;
let mut _12: bool;
let mut _12: u32;
let mut _13: bool;
let mut _14: u32;
let mut _14: bool;
let mut _15: u32;
let mut _16: bool;
let mut _16: u32;
let mut _17: bool;
let mut _18: u32;
let mut _19: u32;
let mut _20: bool;

bb0: {
StorageLive(_17);
StorageLive(_13);
StorageLive(_9);
StorageLive(_14);
StorageLive(_10);
StorageLive(_6);
StorageLive(_5);
StorageLive(_3);
_3 = ((*_1).0: u32);
Expand All @@ -39,74 +39,83 @@ fn naive(_1: &Blueprint, _2: &Blueprint) -> bool {
}

bb1: {
StorageDead(_8);
StorageDead(_5);
_6 = const false;
goto -> bb3;
}

bb2: {
StorageLive(_8);
StorageLive(_6);
_6 = ((*_1).1: u32);
StorageLive(_9);
StorageLive(_7);
_7 = ((*_2).1: u32);
_8 = Eq(move _6, move _7);
StorageDead(_7);
StorageDead(_6);
_9 = move _8;
_7 = ((*_1).1: u32);
StorageLive(_8);
_8 = ((*_2).1: u32);
_9 = Eq(move _7, move _8);
StorageDead(_8);
StorageDead(_5);
switchInt(move _9) -> [0: bb3, otherwise: bb4];
StorageDead(_7);
_6 = move _9;
goto -> bb3;
}

bb3: {
StorageDead(_12);
StorageDead(_9);
goto -> bb5;
StorageDead(_5);
switchInt(move _6) -> [0: bb4, otherwise: bb5];
}

bb4: {
StorageLive(_12);
StorageLive(_10);
_10 = ((*_1).2: u32);
StorageLive(_11);
_11 = ((*_2).2: u32);
_12 = Eq(move _10, move _11);
StorageDead(_11);
StorageDead(_10);
_13 = move _12;
StorageDead(_12);
StorageDead(_9);
switchInt(move _13) -> [0: bb5, otherwise: bb6];
_10 = const false;
goto -> bb6;
}

bb5: {
StorageDead(_16);
StorageDead(_13);
goto -> bb7;
StorageLive(_13);
StorageLive(_11);
_11 = ((*_1).2: u32);
StorageLive(_12);
_12 = ((*_2).2: u32);
_13 = Eq(move _11, move _12);
StorageDead(_12);
StorageDead(_11);
_10 = move _13;
goto -> bb6;
}

bb6: {
StorageLive(_16);
StorageLive(_14);
_14 = ((*_1).3: u32);
StorageLive(_15);
_15 = ((*_2).3: u32);
_16 = Eq(move _14, move _15);
StorageDead(_15);
StorageDead(_14);
_17 = move _16;
StorageDead(_16);
StorageDead(_13);
switchInt(move _17) -> [0: bb7, otherwise: bb8];
StorageDead(_6);
switchInt(move _10) -> [0: bb7, otherwise: bb8];
}

bb7: {
_0 = const false;
_14 = const false;
goto -> bb9;
}

bb8: {
StorageLive(_17);
StorageLive(_15);
_15 = ((*_1).3: u32);
StorageLive(_16);
_16 = ((*_2).3: u32);
_17 = Eq(move _15, move _16);
StorageDead(_16);
StorageDead(_15);
_14 = move _17;
goto -> bb9;
}

bb9: {
StorageDead(_17);
StorageDead(_10);
switchInt(move _14) -> [0: bb10, otherwise: bb11];
}

bb10: {
_0 = const false;
goto -> bb12;
}

bb11: {
StorageLive(_20);
StorageLive(_18);
_18 = ((*_1).4: u32);
Expand All @@ -116,12 +125,12 @@ fn naive(_1: &Blueprint, _2: &Blueprint) -> bool {
StorageDead(_19);
StorageDead(_18);
_0 = move _20;
goto -> bb9;
goto -> bb12;
}

bb9: {
bb12: {
StorageDead(_20);
StorageDead(_17);
StorageDead(_14);
return;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ fn variant_a::{closure#0}(_1: &mut [closure@$DIR/slice_filter.rs:7:25: 7:39], _2
let _12: &usize;
let mut _13: &&usize;
let mut _18: bool;
let mut _19: &&usize;
let _20: &usize;
let mut _21: &&usize;
let mut _26: bool;
let mut _19: bool;
let mut _20: &&usize;
let _21: &usize;
let mut _22: &&usize;
let mut _27: bool;
let mut _28: &&usize;
let _29: &usize;
Expand Down Expand Up @@ -58,15 +58,15 @@ fn variant_a::{closure#0}(_1: &mut [closure@$DIR/slice_filter.rs:7:25: 7:39], _2
}
}
scope 6 (inlined cmp::impls::<impl PartialOrd for &usize>::le) {
debug self => _19;
debug other => _21;
let mut _22: &usize;
debug self => _20;
debug other => _22;
let mut _23: &usize;
let mut _24: &usize;
scope 7 (inlined cmp::impls::<impl PartialOrd for usize>::le) {
debug self => _22;
debug other => _23;
let mut _24: usize;
debug self => _23;
debug other => _24;
let mut _25: usize;
let mut _26: usize;
}
}
scope 8 (inlined cmp::impls::<impl PartialOrd for &usize>::le) {
Expand Down Expand Up @@ -96,7 +96,7 @@ fn variant_a::{closure#0}(_1: &mut [closure@$DIR/slice_filter.rs:7:25: 7:39], _2
StorageLive(_10);
_9 = deref_copy (*_2);
_10 = &((*_9).3: usize);
StorageLive(_27);
StorageLive(_19);
StorageLive(_18);
StorageLive(_11);
_11 = &_4;
Expand All @@ -120,38 +120,41 @@ fn variant_a::{closure#0}(_1: &mut [closure@$DIR/slice_filter.rs:7:25: 7:39], _2
}

bb1: {
StorageDead(_26);
StorageDead(_18);
_19 = const false;
goto -> bb3;
}

bb2: {
StorageLive(_26);
StorageLive(_19);
_19 = &_10;
StorageLive(_21);
StorageLive(_27);
StorageLive(_20);
_20 = _6;
_21 = &_20;
_22 = deref_copy (*_19);
_23 = deref_copy (*_21);
StorageLive(_24);
_24 = (*_22);
_20 = &_10;
StorageLive(_22);
StorageLive(_21);
_21 = _6;
_22 = &_21;
_23 = deref_copy (*_20);
_24 = deref_copy (*_22);
StorageLive(_25);
_25 = (*_23);
_26 = Le(move _24, move _25);
StorageLive(_26);
_26 = (*_24);
_27 = Le(move _25, move _26);
StorageDead(_26);
StorageDead(_25);
StorageDead(_24);
StorageDead(_20);
StorageDead(_21);
StorageDead(_19);
_27 = move _26;
StorageDead(_26);
StorageDead(_18);
switchInt(move _27) -> [0: bb3, otherwise: bb7];
StorageDead(_22);
StorageDead(_20);
_19 = move _27;
goto -> bb3;
}

bb3: {
StorageDead(_27);
StorageDead(_18);
switchInt(move _19) -> [0: bb4, otherwise: bb8];
}

bb4: {
StorageLive(_36);
StorageLive(_35);
StorageLive(_28);
Expand All @@ -172,15 +175,15 @@ fn variant_a::{closure#0}(_1: &mut [closure@$DIR/slice_filter.rs:7:25: 7:39], _2
StorageDead(_29);
StorageDead(_30);
StorageDead(_28);
switchInt(move _35) -> [0: bb4, otherwise: bb5];
switchInt(move _35) -> [0: bb5, otherwise: bb6];
}

bb4: {
bb5: {
_36 = const false;
goto -> bb6;
goto -> bb7;
}

bb5: {
bb6: {
StorageLive(_44);
StorageLive(_37);
_37 = &_6;
Expand All @@ -201,24 +204,24 @@ fn variant_a::{closure#0}(_1: &mut [closure@$DIR/slice_filter.rs:7:25: 7:39], _2
StorageDead(_39);
StorageDead(_37);
_36 = move _44;
goto -> bb6;
goto -> bb7;
}

bb6: {
bb7: {
StorageDead(_44);
StorageDead(_35);
_0 = move _36;
goto -> bb8;
goto -> bb9;
}

bb7: {
bb8: {
_0 = const true;
goto -> bb8;
goto -> bb9;
}

bb8: {
bb9: {
StorageDead(_36);
StorageDead(_27);
StorageDead(_19);
StorageDead(_10);
StorageDead(_8);
StorageDead(_6);
Expand Down
Loading