diff --git a/compiler/rustc_mir_transform/src/const_goto.rs b/compiler/rustc_mir_transform/src/const_goto.rs index 024bea62098..e175f22d7a9 100644 --- a/compiler/rustc_mir_transform/src/const_goto.rs +++ b/compiler/rustc_mir_transform/src/const_goto.rs @@ -28,7 +28,9 @@ 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 } fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { diff --git a/compiler/rustc_mir_transform/src/separate_const_switch.rs b/compiler/rustc_mir_transform/src/separate_const_switch.rs index f35a5fb4276..1d8e54cdca0 100644 --- a/compiler/rustc_mir_transform/src/separate_const_switch.rs +++ b/compiler/rustc_mir_transform/src/separate_const_switch.rs @@ -46,7 +46,9 @@ 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>) { diff --git a/tests/mir-opt/const_goto_const_eval_fail.rs b/tests/mir-opt/const_goto_const_eval_fail.rs index 3b85fe6ab3c..b2357663a90 100644 --- a/tests/mir-opt/const_goto_const_eval_fail.rs +++ b/tests/mir-opt/const_goto_const_eval_fail.rs @@ -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() -> u64 { diff --git a/tests/mir-opt/pre-codegen/chained_comparison.naive.PreCodegen.after.mir b/tests/mir-opt/pre-codegen/chained_comparison.naive.PreCodegen.after.mir index 1c74ae74d53..c7fd397fcd4 100644 --- a/tests/mir-opt/pre-codegen/chained_comparison.naive.PreCodegen.after.mir +++ b/tests/mir-opt/pre-codegen/chained_comparison.naive.PreCodegen.after.mir @@ -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); @@ -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); @@ -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; } } diff --git a/tests/mir-opt/pre-codegen/slice_filter.variant_a-{closure#0}.PreCodegen.after.mir b/tests/mir-opt/pre-codegen/slice_filter.variant_a-{closure#0}.PreCodegen.after.mir index 6c1d5096db0..499bee2ae40 100644 --- a/tests/mir-opt/pre-codegen/slice_filter.variant_a-{closure#0}.PreCodegen.after.mir +++ b/tests/mir-opt/pre-codegen/slice_filter.variant_a-{closure#0}.PreCodegen.after.mir @@ -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; @@ -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::::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::::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::::le) { @@ -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; @@ -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); - StorageDead(_25); - StorageDead(_24); - StorageDead(_20); - StorageDead(_21); - StorageDead(_19); - _27 = move _26; + StorageLive(_26); + _26 = (*_24); + _27 = Le(move _25, move _26); StorageDead(_26); - StorageDead(_18); - switchInt(move _27) -> [0: bb3, otherwise: bb7]; + StorageDead(_25); + StorageDead(_21); + 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); @@ -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]; - } - - bb4: { - _36 = const false; - goto -> bb6; + switchInt(move _35) -> [0: bb5, otherwise: bb6]; } bb5: { + _36 = const false; + goto -> bb7; + } + + bb6: { StorageLive(_44); StorageLive(_37); _37 = &_6; @@ -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; - } - - bb6: { - StorageDead(_44); - StorageDead(_35); - _0 = move _36; - goto -> bb8; + goto -> bb7; } bb7: { - _0 = const true; - goto -> bb8; + StorageDead(_44); + StorageDead(_35); + _0 = move _36; + goto -> bb9; } bb8: { + _0 = const true; + goto -> bb9; + } + + bb9: { StorageDead(_36); - StorageDead(_27); + StorageDead(_19); StorageDead(_10); StorageDead(_8); StorageDead(_6); diff --git a/tests/mir-opt/pre-codegen/slice_filter.variant_b-{closure#0}.PreCodegen.after.mir b/tests/mir-opt/pre-codegen/slice_filter.variant_b-{closure#0}.PreCodegen.after.mir index ef1036d5faf..bab9f0b58aa 100644 --- a/tests/mir-opt/pre-codegen/slice_filter.variant_b-{closure#0}.PreCodegen.after.mir +++ b/tests/mir-opt/pre-codegen/slice_filter.variant_b-{closure#0}.PreCodegen.after.mir @@ -32,61 +32,64 @@ fn variant_b::{closure#0}(_1: &mut [closure@$DIR/slice_filter.rs:11:25: 11:41], _8 = ((*_7).2: usize); _9 = deref_copy (*_2); _10 = ((*_9).3: usize); - StorageLive(_13); + StorageLive(_12); StorageLive(_11); _11 = Le(_4, _8); switchInt(move _11) -> [0: bb1, otherwise: bb2]; } bb1: { - StorageDead(_12); - StorageDead(_11); + _12 = const false; goto -> bb3; } bb2: { - StorageLive(_12); - _12 = Le(_10, _6); - _13 = move _12; - StorageDead(_12); - StorageDead(_11); - switchInt(move _13) -> [0: bb3, otherwise: bb7]; + StorageLive(_13); + _13 = Le(_10, _6); + _12 = move _13; + goto -> bb3; } bb3: { - StorageLive(_15); - StorageLive(_14); - _14 = Le(_8, _4); - switchInt(move _14) -> [0: bb4, otherwise: bb5]; + StorageDead(_13); + StorageDead(_11); + switchInt(move _12) -> [0: bb4, otherwise: bb8]; } bb4: { - _15 = const false; - goto -> bb6; + StorageLive(_15); + StorageLive(_14); + _14 = Le(_8, _4); + switchInt(move _14) -> [0: bb5, otherwise: bb6]; } bb5: { - StorageLive(_16); - _16 = Le(_6, _10); - _15 = move _16; - goto -> bb6; + _15 = const false; + goto -> bb7; } bb6: { - StorageDead(_16); - StorageDead(_14); - _0 = move _15; - goto -> bb8; + StorageLive(_16); + _16 = Le(_6, _10); + _15 = move _16; + goto -> bb7; } bb7: { - _0 = const true; - goto -> bb8; + StorageDead(_16); + StorageDead(_14); + _0 = move _15; + goto -> bb9; } bb8: { + _0 = const true; + goto -> bb9; + } + + bb9: { StorageDead(_15); - StorageDead(_13); + StorageDead(_12); return; } } diff --git a/tests/mir-opt/pre-codegen/slice_index.slice_get_unchecked_mut_range.PreCodegen.after.panic-abort.mir b/tests/mir-opt/pre-codegen/slice_index.slice_get_unchecked_mut_range.PreCodegen.after.panic-abort.mir index 9d914e95344..a337ca89992 100644 --- a/tests/mir-opt/pre-codegen/slice_index.slice_get_unchecked_mut_range.PreCodegen.after.panic-abort.mir +++ b/tests/mir-opt/pre-codegen/slice_index.slice_get_unchecked_mut_range.PreCodegen.after.panic-abort.mir @@ -17,50 +17,37 @@ fn slice_get_unchecked_mut_range(_1: &mut [u32], _2: std::ops::Range) -> debug slice => _5; let mut _7: *mut u32; let mut _8: *mut u32; + let _14: usize; let _15: usize; - let _16: usize; scope 4 { - debug this => std::ops::Range{ .0 => _15, .1 => _16, }; + debug this => std::ops::Range{ .0 => _14, .1 => _15, }; scope 5 { let _6: usize; scope 6 { debug new_len => _6; - scope 11 (inlined ptr::mut_ptr::::as_mut_ptr) { + scope 7 (inlined ptr::mut_ptr::::as_mut_ptr) { debug self => _5; } - scope 12 (inlined ptr::mut_ptr::::add) { + scope 8 (inlined ptr::mut_ptr::::add) { debug self => _7; debug count => _3; - scope 13 { + scope 9 { } } - scope 14 (inlined slice_from_raw_parts_mut::) { + scope 10 (inlined slice_from_raw_parts_mut::) { debug data => _8; debug len => _6; let mut _9: *mut (); - scope 15 (inlined ptr::mut_ptr::::cast::<()>) { + scope 11 (inlined ptr::mut_ptr::::cast::<()>) { debug self => _8; } - scope 16 (inlined std::ptr::from_raw_parts_mut::<[u32]>) { + scope 12 (inlined std::ptr::from_raw_parts_mut::<[u32]>) { debug data_address => _9; debug metadata => _6; let mut _10: *const (); let mut _11: std::ptr::metadata::PtrComponents<[u32]>; let mut _12: std::ptr::metadata::PtrRepr<[u32]>; - scope 17 { - } - } - } - } - scope 7 (inlined as SliceIndex<[T]>>::get_unchecked_mut::runtime::) { - debug this => std::ops::Range{ .0 => _15, .1 => _16, }; - debug slice => _5; - scope 8 (inlined ptr::mut_ptr::::len) { - debug self => _5; - let mut _14: *const [u32]; - scope 9 (inlined std::ptr::metadata::<[u32]>) { - debug ptr => _14; - scope 10 { + scope 13 { } } } @@ -77,10 +64,9 @@ fn slice_get_unchecked_mut_range(_1: &mut [u32], _2: std::ops::Range) -> StorageLive(_13); StorageLive(_5); _5 = &raw mut (*_1); - StorageLive(_6); StorageLive(_14); StorageLive(_15); - StorageLive(_16); + StorageLive(_6); _6 = SubUnchecked(_4, _3); StorageLive(_8); StorageLive(_7); @@ -101,10 +87,9 @@ fn slice_get_unchecked_mut_range(_1: &mut [u32], _2: std::ops::Range) -> StorageDead(_12); StorageDead(_9); StorageDead(_8); - StorageDead(_16); - StorageDead(_15); - StorageDead(_14); StorageDead(_6); + StorageDead(_14); + StorageDead(_15); StorageDead(_5); _0 = &mut (*_13); StorageDead(_13); diff --git a/tests/mir-opt/pre-codegen/slice_index.slice_get_unchecked_mut_range.PreCodegen.after.panic-unwind.mir b/tests/mir-opt/pre-codegen/slice_index.slice_get_unchecked_mut_range.PreCodegen.after.panic-unwind.mir index 9d914e95344..a337ca89992 100644 --- a/tests/mir-opt/pre-codegen/slice_index.slice_get_unchecked_mut_range.PreCodegen.after.panic-unwind.mir +++ b/tests/mir-opt/pre-codegen/slice_index.slice_get_unchecked_mut_range.PreCodegen.after.panic-unwind.mir @@ -17,50 +17,37 @@ fn slice_get_unchecked_mut_range(_1: &mut [u32], _2: std::ops::Range) -> debug slice => _5; let mut _7: *mut u32; let mut _8: *mut u32; + let _14: usize; let _15: usize; - let _16: usize; scope 4 { - debug this => std::ops::Range{ .0 => _15, .1 => _16, }; + debug this => std::ops::Range{ .0 => _14, .1 => _15, }; scope 5 { let _6: usize; scope 6 { debug new_len => _6; - scope 11 (inlined ptr::mut_ptr::::as_mut_ptr) { + scope 7 (inlined ptr::mut_ptr::::as_mut_ptr) { debug self => _5; } - scope 12 (inlined ptr::mut_ptr::::add) { + scope 8 (inlined ptr::mut_ptr::::add) { debug self => _7; debug count => _3; - scope 13 { + scope 9 { } } - scope 14 (inlined slice_from_raw_parts_mut::) { + scope 10 (inlined slice_from_raw_parts_mut::) { debug data => _8; debug len => _6; let mut _9: *mut (); - scope 15 (inlined ptr::mut_ptr::::cast::<()>) { + scope 11 (inlined ptr::mut_ptr::::cast::<()>) { debug self => _8; } - scope 16 (inlined std::ptr::from_raw_parts_mut::<[u32]>) { + scope 12 (inlined std::ptr::from_raw_parts_mut::<[u32]>) { debug data_address => _9; debug metadata => _6; let mut _10: *const (); let mut _11: std::ptr::metadata::PtrComponents<[u32]>; let mut _12: std::ptr::metadata::PtrRepr<[u32]>; - scope 17 { - } - } - } - } - scope 7 (inlined as SliceIndex<[T]>>::get_unchecked_mut::runtime::) { - debug this => std::ops::Range{ .0 => _15, .1 => _16, }; - debug slice => _5; - scope 8 (inlined ptr::mut_ptr::::len) { - debug self => _5; - let mut _14: *const [u32]; - scope 9 (inlined std::ptr::metadata::<[u32]>) { - debug ptr => _14; - scope 10 { + scope 13 { } } } @@ -77,10 +64,9 @@ fn slice_get_unchecked_mut_range(_1: &mut [u32], _2: std::ops::Range) -> StorageLive(_13); StorageLive(_5); _5 = &raw mut (*_1); - StorageLive(_6); StorageLive(_14); StorageLive(_15); - StorageLive(_16); + StorageLive(_6); _6 = SubUnchecked(_4, _3); StorageLive(_8); StorageLive(_7); @@ -101,10 +87,9 @@ fn slice_get_unchecked_mut_range(_1: &mut [u32], _2: std::ops::Range) -> StorageDead(_12); StorageDead(_9); StorageDead(_8); - StorageDead(_16); - StorageDead(_15); - StorageDead(_14); StorageDead(_6); + StorageDead(_14); + StorageDead(_15); StorageDead(_5); _0 = &mut (*_13); StorageDead(_13); diff --git a/tests/mir-opt/separate_const_switch.rs b/tests/mir-opt/separate_const_switch.rs index c809e5629cc..d333d4b6be2 100644 --- a/tests/mir-opt/separate_const_switch.rs +++ b/tests/mir-opt/separate_const_switch.rs @@ -1,6 +1,8 @@ #![feature(control_flow_enum)] #![feature(try_trait_v2)] +// compile-flags: -Zunsound-mir-opts + use std::ops::ControlFlow; // EMIT_MIR separate_const_switch.too_complex.SeparateConstSwitch.diff