diff --git a/compiler/rustc_codegen_cranelift/src/intrinsics/mod.rs b/compiler/rustc_codegen_cranelift/src/intrinsics/mod.rs index 819cb5ef137ce..4215ca87c1d20 100644 --- a/compiler/rustc_codegen_cranelift/src/intrinsics/mod.rs +++ b/compiler/rustc_codegen_cranelift/src/intrinsics/mod.rs @@ -438,6 +438,14 @@ fn codegen_regular_intrinsic_call<'tcx>( fx.bcx.ins().trap(TrapCode::User(0)); return; } + sym::debug_assertions => { + let bool_layout = fx.layout_of(fx.tcx.types.bool); + let val = CValue::by_val( + fx.bcx.ins().iconst(types::I8, fx.tcx.sess.opts.debug_assertions as i64), + bool_layout, + ); + ret.write_cvalue(fx, val); + } sym::likely | sym::unlikely => { intrinsic_args!(fx, args => (a); intrinsic); diff --git a/compiler/rustc_codegen_ssa/src/mir/intrinsic.rs b/compiler/rustc_codegen_ssa/src/mir/intrinsic.rs index 8530bf9e2b363..ac051ce3ce8b0 100644 --- a/compiler/rustc_codegen_ssa/src/mir/intrinsic.rs +++ b/compiler/rustc_codegen_ssa/src/mir/intrinsic.rs @@ -84,6 +84,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { return; } + sym::debug_assertions => bx.const_bool(bx.tcx().sess.opts.debug_assertions), sym::va_start => bx.va_start(args[0].immediate()), sym::va_end => bx.va_end(args[0].immediate()), sym::size_of_val => { diff --git a/compiler/rustc_const_eval/src/const_eval/machine.rs b/compiler/rustc_const_eval/src/const_eval/machine.rs index 274ff25fb9b58..ec498eba486ef 100644 --- a/compiler/rustc_const_eval/src/const_eval/machine.rs +++ b/compiler/rustc_const_eval/src/const_eval/machine.rs @@ -536,6 +536,11 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir, // (We know the value here in the machine of course, but this is the runtime of that code, // not the optimization stage.) sym::is_val_statically_known => ecx.write_scalar(Scalar::from_bool(false), dest)?, + + sym::debug_assertions => { + ecx.write_scalar(Scalar::from_bool(ecx.tcx.sess.opts.debug_assertions), dest)? + } + _ => { throw_unsup_format!( "intrinsic `{intrinsic_name}` is not supported at compile-time" diff --git a/compiler/rustc_hir_analysis/src/check/intrinsic.rs b/compiler/rustc_hir_analysis/src/check/intrinsic.rs index 2d0d6611444c5..96b0cffc8a3d4 100644 --- a/compiler/rustc_hir_analysis/src/check/intrinsic.rs +++ b/compiler/rustc_hir_analysis/src/check/intrinsic.rs @@ -112,7 +112,8 @@ pub fn intrinsic_operation_unsafety(tcx: TyCtxt<'_>, intrinsic_id: DefId) -> hir | sym::forget | sym::black_box | sym::variant_count - | sym::ptr_mask => hir::Unsafety::Normal, + | sym::ptr_mask + | sym::debug_assertions => hir::Unsafety::Normal, _ => hir::Unsafety::Unsafe, }; @@ -461,6 +462,8 @@ pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>) { (0, vec![Ty::new_imm_ptr(tcx, Ty::new_unit(tcx))], tcx.types.usize) } + sym::debug_assertions => (0, Vec::new(), tcx.types.bool), + other => { tcx.dcx().emit_err(UnrecognizedIntrinsicFunction { span: it.span, name: other }); return; diff --git a/library/core/src/intrinsics.rs b/library/core/src/intrinsics.rs index 43124535ab5d8..dc8670eacdcf8 100644 --- a/library/core/src/intrinsics.rs +++ b/library/core/src/intrinsics.rs @@ -2569,6 +2569,12 @@ extern "rust-intrinsic" { #[rustc_nounwind] #[cfg(not(bootstrap))] pub fn is_val_statically_known(arg: T) -> bool; + + #[rustc_const_unstable(feature = "delayed_debug_assertions", issue = "none")] + #[rustc_safe_intrinsic] + #[rustc_nounwind] + #[cfg(not(bootstrap))] + pub(crate) fn debug_assertions() -> bool; } // FIXME: Seems using `unstable` here completely ignores `rustc_allow_const_fn_unstable` @@ -2604,10 +2610,18 @@ pub const unsafe fn is_val_statically_known(_arg: T) -> bool { /// /// So in a sense it is UB if this macro is useful, but we expect callers of `unsafe fn` to make /// the occasional mistake, and this check should help them figure things out. -#[allow_internal_unstable(const_eval_select)] // permit this to be called in stably-const fn +#[allow_internal_unstable(const_eval_select, delayed_debug_assertions)] // permit this to be called in stably-const fn macro_rules! assert_unsafe_precondition { ($name:expr, $([$($tt:tt)*])?($($i:ident:$ty:ty),*$(,)?) => $e:expr $(,)?) => { - if cfg!(debug_assertions) { + { + #[cfg(bootstrap)] + let should_check = cfg!(debug_assertions); + + // Turn assertions off in Miri, but otherwise check in codegen + #[cfg(not(bootstrap))] + let should_check = !cfg!(miri) && ::core::intrinsics::debug_assertions(); + + if should_check { // allow non_snake_case to allow capturing const generics #[allow(non_snake_case)] #[inline(always)] @@ -2625,6 +2639,7 @@ macro_rules! assert_unsafe_precondition { ::core::intrinsics::const_eval_select(($($i,)*), comptime, runtime); } + } }; } pub(crate) use assert_unsafe_precondition; diff --git a/library/core/src/ptr/mod.rs b/library/core/src/ptr/mod.rs index dce7e035fc73a..ee3fb7a5b5e89 100644 --- a/library/core/src/ptr/mod.rs +++ b/library/core/src/ptr/mod.rs @@ -1208,10 +1208,12 @@ pub const unsafe fn read(src: *const T) -> T { // SAFETY: the caller must guarantee that `src` is valid for reads. unsafe { + /* assert_unsafe_precondition!( "ptr::read requires that the pointer argument is aligned and non-null", [T](src: *const T) => is_aligned_and_not_null(src) ); + */ crate::intrinsics::read_via_copy(src) } } @@ -1408,10 +1410,12 @@ pub const unsafe fn write(dst: *mut T, src: T) { // `dst` cannot overlap `src` because the caller has mutable access // to `dst` while `src` is owned by this function. unsafe { + /* assert_unsafe_precondition!( "ptr::write requires that the pointer argument is aligned and non-null", [T](dst: *mut T) => is_aligned_and_not_null(dst) ); + */ intrinsics::write_via_move(dst, src) } } diff --git a/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.DataflowConstProp.32bit.panic-abort.diff b/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.DataflowConstProp.32bit.panic-abort.diff index ffbd97bb5452f..4fd6e6aef1d4f 100644 --- a/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.DataflowConstProp.32bit.panic-abort.diff +++ b/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.DataflowConstProp.32bit.panic-abort.diff @@ -24,22 +24,28 @@ debug ptr => _6; scope 11 (inlined NonNull::<[bool; 0]>::new_unchecked) { debug ptr => _6; - let mut _8: *const [bool; 0]; - let mut _9: *mut [bool; 0]; + let mut _9: *const [bool; 0]; scope 12 { - scope 13 (inlined NonNull::::new_unchecked::runtime::<[bool; 0]>) { - debug ptr => _9; - scope 14 (inlined std::ptr::mut_ptr::::is_null) { - debug self => _9; - let mut _10: *mut u8; - scope 15 { - scope 16 (inlined std::ptr::mut_ptr::::is_null::runtime_impl) { - debug ptr => _10; - scope 17 (inlined std::ptr::mut_ptr::::addr) { - debug self => _10; - scope 18 { - scope 19 (inlined std::ptr::mut_ptr::::cast::<()>) { - debug self => _10; + let _8: bool; + scope 13 { + debug should_check => _8; + scope 14 (inlined NonNull::::new_unchecked::runtime::<[bool; 0]>) { + debug ptr => _6; + let _10: !; + scope 15 (inlined std::ptr::mut_ptr::::is_null) { + debug self => _6; + let mut _11: *mut u8; + scope 16 { + scope 17 (inlined std::ptr::mut_ptr::::is_null::runtime_impl) { + debug ptr => _11; + let mut _12: usize; + scope 18 (inlined std::ptr::mut_ptr::::addr) { + debug self => _11; + let mut _13: *mut (); + scope 19 { + scope 20 (inlined std::ptr::mut_ptr::::cast::<()>) { + debug self => _11; + } } } } @@ -66,6 +72,7 @@ StorageLive(_1); StorageLive(_2); StorageLive(_3); + StorageLive(_10); StorageLive(_4); StorageLive(_5); StorageLive(_6); @@ -75,10 +82,33 @@ StorageDead(_7); StorageLive(_8); StorageLive(_9); - StorageLive(_10); - _8 = const {0x1 as *mut [bool; 0]} as *const [bool; 0] (PointerCoercion(MutToConstPointer)); - _5 = NonNull::<[bool; 0]> { pointer: _8 }; - StorageDead(_10); + _8 = intrinsics::debug_assertions() -> [return: bb2, unwind unreachable]; + } + + bb1: { + StorageDead(_1); + return; + } + + bb2: { + switchInt(_8) -> [0: bb4, otherwise: bb3]; + } + + bb3: { + StorageLive(_11); + _11 = const {0x1 as *mut [bool; 0]} as *mut u8 (PtrToPtr); + StorageLive(_12); + StorageLive(_13); + _13 = _11 as *mut () (PtrToPtr); + _12 = move _13 as usize (Transmute); + StorageDead(_13); + StorageDead(_11); + switchInt(move _12) -> [0: bb5, otherwise: bb6]; + } + + bb4: { + _9 = const {0x1 as *mut [bool; 0]} as *const [bool; 0] (PointerCoercion(MutToConstPointer)); + _5 = NonNull::<[bool; 0]> { pointer: _9 }; StorageDead(_9); StorageDead(_8); StorageDead(_6); @@ -87,6 +117,7 @@ _3 = move _4 as std::ptr::Unique<[bool]> (PointerCoercion(Unsize)); StorageDead(_4); _2 = Box::<[bool]>(_3, const std::alloc::Global); + StorageDead(_10); StorageDead(_3); _1 = A { foo: move _2 }; StorageDead(_2); @@ -94,9 +125,14 @@ drop(_1) -> [return: bb1, unwind unreachable]; } - bb1: { - StorageDead(_1); - return; + bb5: { + StorageDead(_12); + _10 = core::panicking::panic_nounwind(const "unsafe precondition(s) violated: NonNull::new_unchecked requires that the pointer is non-null") -> unwind unreachable; + } + + bb6: { + StorageDead(_12); + goto -> bb4; } } diff --git a/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.DataflowConstProp.32bit.panic-unwind.diff b/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.DataflowConstProp.32bit.panic-unwind.diff index 7b6dcf1972b2e..93df1d1452597 100644 --- a/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.DataflowConstProp.32bit.panic-unwind.diff +++ b/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.DataflowConstProp.32bit.panic-unwind.diff @@ -24,22 +24,28 @@ debug ptr => _6; scope 11 (inlined NonNull::<[bool; 0]>::new_unchecked) { debug ptr => _6; - let mut _8: *const [bool; 0]; - let mut _9: *mut [bool; 0]; + let mut _9: *const [bool; 0]; scope 12 { - scope 13 (inlined NonNull::::new_unchecked::runtime::<[bool; 0]>) { - debug ptr => _9; - scope 14 (inlined std::ptr::mut_ptr::::is_null) { - debug self => _9; - let mut _10: *mut u8; - scope 15 { - scope 16 (inlined std::ptr::mut_ptr::::is_null::runtime_impl) { - debug ptr => _10; - scope 17 (inlined std::ptr::mut_ptr::::addr) { - debug self => _10; - scope 18 { - scope 19 (inlined std::ptr::mut_ptr::::cast::<()>) { - debug self => _10; + let _8: bool; + scope 13 { + debug should_check => _8; + scope 14 (inlined NonNull::::new_unchecked::runtime::<[bool; 0]>) { + debug ptr => _6; + let _10: !; + scope 15 (inlined std::ptr::mut_ptr::::is_null) { + debug self => _6; + let mut _11: *mut u8; + scope 16 { + scope 17 (inlined std::ptr::mut_ptr::::is_null::runtime_impl) { + debug ptr => _11; + let mut _12: usize; + scope 18 (inlined std::ptr::mut_ptr::::addr) { + debug self => _11; + let mut _13: *mut (); + scope 19 { + scope 20 (inlined std::ptr::mut_ptr::::cast::<()>) { + debug self => _11; + } } } } @@ -66,6 +72,7 @@ StorageLive(_1); StorageLive(_2); StorageLive(_3); + StorageLive(_10); StorageLive(_4); StorageLive(_5); StorageLive(_6); @@ -75,10 +82,37 @@ StorageDead(_7); StorageLive(_8); StorageLive(_9); - StorageLive(_10); - _8 = const {0x1 as *mut [bool; 0]} as *const [bool; 0] (PointerCoercion(MutToConstPointer)); - _5 = NonNull::<[bool; 0]> { pointer: _8 }; - StorageDead(_10); + _8 = intrinsics::debug_assertions() -> [return: bb3, unwind unreachable]; + } + + bb1: { + StorageDead(_1); + return; + } + + bb2 (cleanup): { + resume; + } + + bb3: { + switchInt(_8) -> [0: bb5, otherwise: bb4]; + } + + bb4: { + StorageLive(_11); + _11 = const {0x1 as *mut [bool; 0]} as *mut u8 (PtrToPtr); + StorageLive(_12); + StorageLive(_13); + _13 = _11 as *mut () (PtrToPtr); + _12 = move _13 as usize (Transmute); + StorageDead(_13); + StorageDead(_11); + switchInt(move _12) -> [0: bb6, otherwise: bb7]; + } + + bb5: { + _9 = const {0x1 as *mut [bool; 0]} as *const [bool; 0] (PointerCoercion(MutToConstPointer)); + _5 = NonNull::<[bool; 0]> { pointer: _9 }; StorageDead(_9); StorageDead(_8); StorageDead(_6); @@ -87,6 +121,7 @@ _3 = move _4 as std::ptr::Unique<[bool]> (PointerCoercion(Unsize)); StorageDead(_4); _2 = Box::<[bool]>(_3, const std::alloc::Global); + StorageDead(_10); StorageDead(_3); _1 = A { foo: move _2 }; StorageDead(_2); @@ -94,13 +129,14 @@ drop(_1) -> [return: bb1, unwind: bb2]; } - bb1: { - StorageDead(_1); - return; + bb6: { + StorageDead(_12); + _10 = core::panicking::panic_nounwind(const "unsafe precondition(s) violated: NonNull::new_unchecked requires that the pointer is non-null") -> unwind unreachable; } - bb2 (cleanup): { - resume; + bb7: { + StorageDead(_12); + goto -> bb5; } } diff --git a/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.DataflowConstProp.64bit.panic-abort.diff b/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.DataflowConstProp.64bit.panic-abort.diff index ffbd97bb5452f..4fd6e6aef1d4f 100644 --- a/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.DataflowConstProp.64bit.panic-abort.diff +++ b/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.DataflowConstProp.64bit.panic-abort.diff @@ -24,22 +24,28 @@ debug ptr => _6; scope 11 (inlined NonNull::<[bool; 0]>::new_unchecked) { debug ptr => _6; - let mut _8: *const [bool; 0]; - let mut _9: *mut [bool; 0]; + let mut _9: *const [bool; 0]; scope 12 { - scope 13 (inlined NonNull::::new_unchecked::runtime::<[bool; 0]>) { - debug ptr => _9; - scope 14 (inlined std::ptr::mut_ptr::::is_null) { - debug self => _9; - let mut _10: *mut u8; - scope 15 { - scope 16 (inlined std::ptr::mut_ptr::::is_null::runtime_impl) { - debug ptr => _10; - scope 17 (inlined std::ptr::mut_ptr::::addr) { - debug self => _10; - scope 18 { - scope 19 (inlined std::ptr::mut_ptr::::cast::<()>) { - debug self => _10; + let _8: bool; + scope 13 { + debug should_check => _8; + scope 14 (inlined NonNull::::new_unchecked::runtime::<[bool; 0]>) { + debug ptr => _6; + let _10: !; + scope 15 (inlined std::ptr::mut_ptr::::is_null) { + debug self => _6; + let mut _11: *mut u8; + scope 16 { + scope 17 (inlined std::ptr::mut_ptr::::is_null::runtime_impl) { + debug ptr => _11; + let mut _12: usize; + scope 18 (inlined std::ptr::mut_ptr::::addr) { + debug self => _11; + let mut _13: *mut (); + scope 19 { + scope 20 (inlined std::ptr::mut_ptr::::cast::<()>) { + debug self => _11; + } } } } @@ -66,6 +72,7 @@ StorageLive(_1); StorageLive(_2); StorageLive(_3); + StorageLive(_10); StorageLive(_4); StorageLive(_5); StorageLive(_6); @@ -75,10 +82,33 @@ StorageDead(_7); StorageLive(_8); StorageLive(_9); - StorageLive(_10); - _8 = const {0x1 as *mut [bool; 0]} as *const [bool; 0] (PointerCoercion(MutToConstPointer)); - _5 = NonNull::<[bool; 0]> { pointer: _8 }; - StorageDead(_10); + _8 = intrinsics::debug_assertions() -> [return: bb2, unwind unreachable]; + } + + bb1: { + StorageDead(_1); + return; + } + + bb2: { + switchInt(_8) -> [0: bb4, otherwise: bb3]; + } + + bb3: { + StorageLive(_11); + _11 = const {0x1 as *mut [bool; 0]} as *mut u8 (PtrToPtr); + StorageLive(_12); + StorageLive(_13); + _13 = _11 as *mut () (PtrToPtr); + _12 = move _13 as usize (Transmute); + StorageDead(_13); + StorageDead(_11); + switchInt(move _12) -> [0: bb5, otherwise: bb6]; + } + + bb4: { + _9 = const {0x1 as *mut [bool; 0]} as *const [bool; 0] (PointerCoercion(MutToConstPointer)); + _5 = NonNull::<[bool; 0]> { pointer: _9 }; StorageDead(_9); StorageDead(_8); StorageDead(_6); @@ -87,6 +117,7 @@ _3 = move _4 as std::ptr::Unique<[bool]> (PointerCoercion(Unsize)); StorageDead(_4); _2 = Box::<[bool]>(_3, const std::alloc::Global); + StorageDead(_10); StorageDead(_3); _1 = A { foo: move _2 }; StorageDead(_2); @@ -94,9 +125,14 @@ drop(_1) -> [return: bb1, unwind unreachable]; } - bb1: { - StorageDead(_1); - return; + bb5: { + StorageDead(_12); + _10 = core::panicking::panic_nounwind(const "unsafe precondition(s) violated: NonNull::new_unchecked requires that the pointer is non-null") -> unwind unreachable; + } + + bb6: { + StorageDead(_12); + goto -> bb4; } } diff --git a/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.DataflowConstProp.64bit.panic-unwind.diff b/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.DataflowConstProp.64bit.panic-unwind.diff index 7b6dcf1972b2e..93df1d1452597 100644 --- a/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.DataflowConstProp.64bit.panic-unwind.diff +++ b/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.DataflowConstProp.64bit.panic-unwind.diff @@ -24,22 +24,28 @@ debug ptr => _6; scope 11 (inlined NonNull::<[bool; 0]>::new_unchecked) { debug ptr => _6; - let mut _8: *const [bool; 0]; - let mut _9: *mut [bool; 0]; + let mut _9: *const [bool; 0]; scope 12 { - scope 13 (inlined NonNull::::new_unchecked::runtime::<[bool; 0]>) { - debug ptr => _9; - scope 14 (inlined std::ptr::mut_ptr::::is_null) { - debug self => _9; - let mut _10: *mut u8; - scope 15 { - scope 16 (inlined std::ptr::mut_ptr::::is_null::runtime_impl) { - debug ptr => _10; - scope 17 (inlined std::ptr::mut_ptr::::addr) { - debug self => _10; - scope 18 { - scope 19 (inlined std::ptr::mut_ptr::::cast::<()>) { - debug self => _10; + let _8: bool; + scope 13 { + debug should_check => _8; + scope 14 (inlined NonNull::::new_unchecked::runtime::<[bool; 0]>) { + debug ptr => _6; + let _10: !; + scope 15 (inlined std::ptr::mut_ptr::::is_null) { + debug self => _6; + let mut _11: *mut u8; + scope 16 { + scope 17 (inlined std::ptr::mut_ptr::::is_null::runtime_impl) { + debug ptr => _11; + let mut _12: usize; + scope 18 (inlined std::ptr::mut_ptr::::addr) { + debug self => _11; + let mut _13: *mut (); + scope 19 { + scope 20 (inlined std::ptr::mut_ptr::::cast::<()>) { + debug self => _11; + } } } } @@ -66,6 +72,7 @@ StorageLive(_1); StorageLive(_2); StorageLive(_3); + StorageLive(_10); StorageLive(_4); StorageLive(_5); StorageLive(_6); @@ -75,10 +82,37 @@ StorageDead(_7); StorageLive(_8); StorageLive(_9); - StorageLive(_10); - _8 = const {0x1 as *mut [bool; 0]} as *const [bool; 0] (PointerCoercion(MutToConstPointer)); - _5 = NonNull::<[bool; 0]> { pointer: _8 }; - StorageDead(_10); + _8 = intrinsics::debug_assertions() -> [return: bb3, unwind unreachable]; + } + + bb1: { + StorageDead(_1); + return; + } + + bb2 (cleanup): { + resume; + } + + bb3: { + switchInt(_8) -> [0: bb5, otherwise: bb4]; + } + + bb4: { + StorageLive(_11); + _11 = const {0x1 as *mut [bool; 0]} as *mut u8 (PtrToPtr); + StorageLive(_12); + StorageLive(_13); + _13 = _11 as *mut () (PtrToPtr); + _12 = move _13 as usize (Transmute); + StorageDead(_13); + StorageDead(_11); + switchInt(move _12) -> [0: bb6, otherwise: bb7]; + } + + bb5: { + _9 = const {0x1 as *mut [bool; 0]} as *const [bool; 0] (PointerCoercion(MutToConstPointer)); + _5 = NonNull::<[bool; 0]> { pointer: _9 }; StorageDead(_9); StorageDead(_8); StorageDead(_6); @@ -87,6 +121,7 @@ _3 = move _4 as std::ptr::Unique<[bool]> (PointerCoercion(Unsize)); StorageDead(_4); _2 = Box::<[bool]>(_3, const std::alloc::Global); + StorageDead(_10); StorageDead(_3); _1 = A { foo: move _2 }; StorageDead(_2); @@ -94,13 +129,14 @@ drop(_1) -> [return: bb1, unwind: bb2]; } - bb1: { - StorageDead(_1); - return; + bb6: { + StorageDead(_12); + _10 = core::panicking::panic_nounwind(const "unsafe precondition(s) violated: NonNull::new_unchecked requires that the pointer is non-null") -> unwind unreachable; } - bb2 (cleanup): { - resume; + bb7: { + StorageDead(_12); + goto -> bb5; } } diff --git a/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.GVN.32bit.panic-abort.diff b/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.GVN.32bit.panic-abort.diff index df68ce496fd8c..26a8f7d85fb26 100644 --- a/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.GVN.32bit.panic-abort.diff +++ b/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.GVN.32bit.panic-abort.diff @@ -24,22 +24,28 @@ debug ptr => _6; scope 11 (inlined NonNull::<[bool; 0]>::new_unchecked) { debug ptr => _6; - let mut _8: *const [bool; 0]; - let mut _9: *mut [bool; 0]; + let mut _9: *const [bool; 0]; scope 12 { - scope 13 (inlined NonNull::::new_unchecked::runtime::<[bool; 0]>) { - debug ptr => _9; - scope 14 (inlined std::ptr::mut_ptr::::is_null) { - debug self => _9; - let mut _10: *mut u8; - scope 15 { - scope 16 (inlined std::ptr::mut_ptr::::is_null::runtime_impl) { - debug ptr => _10; - scope 17 (inlined std::ptr::mut_ptr::::addr) { - debug self => _10; - scope 18 { - scope 19 (inlined std::ptr::mut_ptr::::cast::<()>) { - debug self => _10; + let _8: bool; + scope 13 { + debug should_check => _8; + scope 14 (inlined NonNull::::new_unchecked::runtime::<[bool; 0]>) { + debug ptr => _6; + let _10: !; + scope 15 (inlined std::ptr::mut_ptr::::is_null) { + debug self => _6; + let mut _11: *mut u8; + scope 16 { + scope 17 (inlined std::ptr::mut_ptr::::is_null::runtime_impl) { + debug ptr => _11; + let mut _12: usize; + scope 18 (inlined std::ptr::mut_ptr::::addr) { + debug self => _11; + let mut _13: *mut (); + scope 19 { + scope 20 (inlined std::ptr::mut_ptr::::cast::<()>) { + debug self => _11; + } } } } @@ -66,6 +72,7 @@ StorageLive(_1); StorageLive(_2); StorageLive(_3); + StorageLive(_10); StorageLive(_4); StorageLive(_5); StorageLive(_6); @@ -77,11 +84,35 @@ StorageDead(_7); StorageLive(_8); StorageLive(_9); - StorageLive(_10); -- _8 = _6 as *const [bool; 0] (PointerCoercion(MutToConstPointer)); -+ _8 = const {0x1 as *mut [bool; 0]} as *const [bool; 0] (PointerCoercion(MutToConstPointer)); - _5 = NonNull::<[bool; 0]> { pointer: _8 }; - StorageDead(_10); + _8 = intrinsics::debug_assertions() -> [return: bb2, unwind unreachable]; + } + + bb1: { + StorageDead(_1); + return; + } + + bb2: { + switchInt(_8) -> [0: bb4, otherwise: bb3]; + } + + bb3: { + StorageLive(_11); +- _11 = _6 as *mut u8 (PtrToPtr); ++ _11 = const {0x1 as *mut [bool; 0]} as *mut u8 (PtrToPtr); + StorageLive(_12); + StorageLive(_13); + _13 = _11 as *mut () (PtrToPtr); + _12 = move _13 as usize (Transmute); + StorageDead(_13); + StorageDead(_11); + switchInt(move _12) -> [0: bb5, otherwise: bb6]; + } + + bb4: { +- _9 = _6 as *const [bool; 0] (PointerCoercion(MutToConstPointer)); ++ _9 = const {0x1 as *mut [bool; 0]} as *const [bool; 0] (PointerCoercion(MutToConstPointer)); + _5 = NonNull::<[bool; 0]> { pointer: _9 }; StorageDead(_9); StorageDead(_8); StorageDead(_6); @@ -90,6 +121,7 @@ _3 = move _4 as std::ptr::Unique<[bool]> (PointerCoercion(Unsize)); StorageDead(_4); _2 = Box::<[bool]>(_3, const std::alloc::Global); + StorageDead(_10); StorageDead(_3); _1 = A { foo: move _2 }; StorageDead(_2); @@ -97,9 +129,14 @@ drop(_1) -> [return: bb1, unwind unreachable]; } - bb1: { - StorageDead(_1); - return; + bb5: { + StorageDead(_12); + _10 = core::panicking::panic_nounwind(const "unsafe precondition(s) violated: NonNull::new_unchecked requires that the pointer is non-null") -> unwind unreachable; + } + + bb6: { + StorageDead(_12); + goto -> bb4; } } diff --git a/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.GVN.32bit.panic-unwind.diff b/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.GVN.32bit.panic-unwind.diff index e16ea22091ee2..788bb49dce531 100644 --- a/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.GVN.32bit.panic-unwind.diff +++ b/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.GVN.32bit.panic-unwind.diff @@ -24,22 +24,28 @@ debug ptr => _6; scope 11 (inlined NonNull::<[bool; 0]>::new_unchecked) { debug ptr => _6; - let mut _8: *const [bool; 0]; - let mut _9: *mut [bool; 0]; + let mut _9: *const [bool; 0]; scope 12 { - scope 13 (inlined NonNull::::new_unchecked::runtime::<[bool; 0]>) { - debug ptr => _9; - scope 14 (inlined std::ptr::mut_ptr::::is_null) { - debug self => _9; - let mut _10: *mut u8; - scope 15 { - scope 16 (inlined std::ptr::mut_ptr::::is_null::runtime_impl) { - debug ptr => _10; - scope 17 (inlined std::ptr::mut_ptr::::addr) { - debug self => _10; - scope 18 { - scope 19 (inlined std::ptr::mut_ptr::::cast::<()>) { - debug self => _10; + let _8: bool; + scope 13 { + debug should_check => _8; + scope 14 (inlined NonNull::::new_unchecked::runtime::<[bool; 0]>) { + debug ptr => _6; + let _10: !; + scope 15 (inlined std::ptr::mut_ptr::::is_null) { + debug self => _6; + let mut _11: *mut u8; + scope 16 { + scope 17 (inlined std::ptr::mut_ptr::::is_null::runtime_impl) { + debug ptr => _11; + let mut _12: usize; + scope 18 (inlined std::ptr::mut_ptr::::addr) { + debug self => _11; + let mut _13: *mut (); + scope 19 { + scope 20 (inlined std::ptr::mut_ptr::::cast::<()>) { + debug self => _11; + } } } } @@ -66,6 +72,7 @@ StorageLive(_1); StorageLive(_2); StorageLive(_3); + StorageLive(_10); StorageLive(_4); StorageLive(_5); StorageLive(_6); @@ -77,11 +84,39 @@ StorageDead(_7); StorageLive(_8); StorageLive(_9); - StorageLive(_10); -- _8 = _6 as *const [bool; 0] (PointerCoercion(MutToConstPointer)); -+ _8 = const {0x1 as *mut [bool; 0]} as *const [bool; 0] (PointerCoercion(MutToConstPointer)); - _5 = NonNull::<[bool; 0]> { pointer: _8 }; - StorageDead(_10); + _8 = intrinsics::debug_assertions() -> [return: bb3, unwind unreachable]; + } + + bb1: { + StorageDead(_1); + return; + } + + bb2 (cleanup): { + resume; + } + + bb3: { + switchInt(_8) -> [0: bb5, otherwise: bb4]; + } + + bb4: { + StorageLive(_11); +- _11 = _6 as *mut u8 (PtrToPtr); ++ _11 = const {0x1 as *mut [bool; 0]} as *mut u8 (PtrToPtr); + StorageLive(_12); + StorageLive(_13); + _13 = _11 as *mut () (PtrToPtr); + _12 = move _13 as usize (Transmute); + StorageDead(_13); + StorageDead(_11); + switchInt(move _12) -> [0: bb6, otherwise: bb7]; + } + + bb5: { +- _9 = _6 as *const [bool; 0] (PointerCoercion(MutToConstPointer)); ++ _9 = const {0x1 as *mut [bool; 0]} as *const [bool; 0] (PointerCoercion(MutToConstPointer)); + _5 = NonNull::<[bool; 0]> { pointer: _9 }; StorageDead(_9); StorageDead(_8); StorageDead(_6); @@ -90,6 +125,7 @@ _3 = move _4 as std::ptr::Unique<[bool]> (PointerCoercion(Unsize)); StorageDead(_4); _2 = Box::<[bool]>(_3, const std::alloc::Global); + StorageDead(_10); StorageDead(_3); _1 = A { foo: move _2 }; StorageDead(_2); @@ -97,13 +133,14 @@ drop(_1) -> [return: bb1, unwind: bb2]; } - bb1: { - StorageDead(_1); - return; + bb6: { + StorageDead(_12); + _10 = core::panicking::panic_nounwind(const "unsafe precondition(s) violated: NonNull::new_unchecked requires that the pointer is non-null") -> unwind unreachable; } - bb2 (cleanup): { - resume; + bb7: { + StorageDead(_12); + goto -> bb5; } } diff --git a/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.GVN.64bit.panic-abort.diff b/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.GVN.64bit.panic-abort.diff index df68ce496fd8c..26a8f7d85fb26 100644 --- a/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.GVN.64bit.panic-abort.diff +++ b/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.GVN.64bit.panic-abort.diff @@ -24,22 +24,28 @@ debug ptr => _6; scope 11 (inlined NonNull::<[bool; 0]>::new_unchecked) { debug ptr => _6; - let mut _8: *const [bool; 0]; - let mut _9: *mut [bool; 0]; + let mut _9: *const [bool; 0]; scope 12 { - scope 13 (inlined NonNull::::new_unchecked::runtime::<[bool; 0]>) { - debug ptr => _9; - scope 14 (inlined std::ptr::mut_ptr::::is_null) { - debug self => _9; - let mut _10: *mut u8; - scope 15 { - scope 16 (inlined std::ptr::mut_ptr::::is_null::runtime_impl) { - debug ptr => _10; - scope 17 (inlined std::ptr::mut_ptr::::addr) { - debug self => _10; - scope 18 { - scope 19 (inlined std::ptr::mut_ptr::::cast::<()>) { - debug self => _10; + let _8: bool; + scope 13 { + debug should_check => _8; + scope 14 (inlined NonNull::::new_unchecked::runtime::<[bool; 0]>) { + debug ptr => _6; + let _10: !; + scope 15 (inlined std::ptr::mut_ptr::::is_null) { + debug self => _6; + let mut _11: *mut u8; + scope 16 { + scope 17 (inlined std::ptr::mut_ptr::::is_null::runtime_impl) { + debug ptr => _11; + let mut _12: usize; + scope 18 (inlined std::ptr::mut_ptr::::addr) { + debug self => _11; + let mut _13: *mut (); + scope 19 { + scope 20 (inlined std::ptr::mut_ptr::::cast::<()>) { + debug self => _11; + } } } } @@ -66,6 +72,7 @@ StorageLive(_1); StorageLive(_2); StorageLive(_3); + StorageLive(_10); StorageLive(_4); StorageLive(_5); StorageLive(_6); @@ -77,11 +84,35 @@ StorageDead(_7); StorageLive(_8); StorageLive(_9); - StorageLive(_10); -- _8 = _6 as *const [bool; 0] (PointerCoercion(MutToConstPointer)); -+ _8 = const {0x1 as *mut [bool; 0]} as *const [bool; 0] (PointerCoercion(MutToConstPointer)); - _5 = NonNull::<[bool; 0]> { pointer: _8 }; - StorageDead(_10); + _8 = intrinsics::debug_assertions() -> [return: bb2, unwind unreachable]; + } + + bb1: { + StorageDead(_1); + return; + } + + bb2: { + switchInt(_8) -> [0: bb4, otherwise: bb3]; + } + + bb3: { + StorageLive(_11); +- _11 = _6 as *mut u8 (PtrToPtr); ++ _11 = const {0x1 as *mut [bool; 0]} as *mut u8 (PtrToPtr); + StorageLive(_12); + StorageLive(_13); + _13 = _11 as *mut () (PtrToPtr); + _12 = move _13 as usize (Transmute); + StorageDead(_13); + StorageDead(_11); + switchInt(move _12) -> [0: bb5, otherwise: bb6]; + } + + bb4: { +- _9 = _6 as *const [bool; 0] (PointerCoercion(MutToConstPointer)); ++ _9 = const {0x1 as *mut [bool; 0]} as *const [bool; 0] (PointerCoercion(MutToConstPointer)); + _5 = NonNull::<[bool; 0]> { pointer: _9 }; StorageDead(_9); StorageDead(_8); StorageDead(_6); @@ -90,6 +121,7 @@ _3 = move _4 as std::ptr::Unique<[bool]> (PointerCoercion(Unsize)); StorageDead(_4); _2 = Box::<[bool]>(_3, const std::alloc::Global); + StorageDead(_10); StorageDead(_3); _1 = A { foo: move _2 }; StorageDead(_2); @@ -97,9 +129,14 @@ drop(_1) -> [return: bb1, unwind unreachable]; } - bb1: { - StorageDead(_1); - return; + bb5: { + StorageDead(_12); + _10 = core::panicking::panic_nounwind(const "unsafe precondition(s) violated: NonNull::new_unchecked requires that the pointer is non-null") -> unwind unreachable; + } + + bb6: { + StorageDead(_12); + goto -> bb4; } } diff --git a/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.GVN.64bit.panic-unwind.diff b/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.GVN.64bit.panic-unwind.diff index e16ea22091ee2..788bb49dce531 100644 --- a/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.GVN.64bit.panic-unwind.diff +++ b/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.GVN.64bit.panic-unwind.diff @@ -24,22 +24,28 @@ debug ptr => _6; scope 11 (inlined NonNull::<[bool; 0]>::new_unchecked) { debug ptr => _6; - let mut _8: *const [bool; 0]; - let mut _9: *mut [bool; 0]; + let mut _9: *const [bool; 0]; scope 12 { - scope 13 (inlined NonNull::::new_unchecked::runtime::<[bool; 0]>) { - debug ptr => _9; - scope 14 (inlined std::ptr::mut_ptr::::is_null) { - debug self => _9; - let mut _10: *mut u8; - scope 15 { - scope 16 (inlined std::ptr::mut_ptr::::is_null::runtime_impl) { - debug ptr => _10; - scope 17 (inlined std::ptr::mut_ptr::::addr) { - debug self => _10; - scope 18 { - scope 19 (inlined std::ptr::mut_ptr::::cast::<()>) { - debug self => _10; + let _8: bool; + scope 13 { + debug should_check => _8; + scope 14 (inlined NonNull::::new_unchecked::runtime::<[bool; 0]>) { + debug ptr => _6; + let _10: !; + scope 15 (inlined std::ptr::mut_ptr::::is_null) { + debug self => _6; + let mut _11: *mut u8; + scope 16 { + scope 17 (inlined std::ptr::mut_ptr::::is_null::runtime_impl) { + debug ptr => _11; + let mut _12: usize; + scope 18 (inlined std::ptr::mut_ptr::::addr) { + debug self => _11; + let mut _13: *mut (); + scope 19 { + scope 20 (inlined std::ptr::mut_ptr::::cast::<()>) { + debug self => _11; + } } } } @@ -66,6 +72,7 @@ StorageLive(_1); StorageLive(_2); StorageLive(_3); + StorageLive(_10); StorageLive(_4); StorageLive(_5); StorageLive(_6); @@ -77,11 +84,39 @@ StorageDead(_7); StorageLive(_8); StorageLive(_9); - StorageLive(_10); -- _8 = _6 as *const [bool; 0] (PointerCoercion(MutToConstPointer)); -+ _8 = const {0x1 as *mut [bool; 0]} as *const [bool; 0] (PointerCoercion(MutToConstPointer)); - _5 = NonNull::<[bool; 0]> { pointer: _8 }; - StorageDead(_10); + _8 = intrinsics::debug_assertions() -> [return: bb3, unwind unreachable]; + } + + bb1: { + StorageDead(_1); + return; + } + + bb2 (cleanup): { + resume; + } + + bb3: { + switchInt(_8) -> [0: bb5, otherwise: bb4]; + } + + bb4: { + StorageLive(_11); +- _11 = _6 as *mut u8 (PtrToPtr); ++ _11 = const {0x1 as *mut [bool; 0]} as *mut u8 (PtrToPtr); + StorageLive(_12); + StorageLive(_13); + _13 = _11 as *mut () (PtrToPtr); + _12 = move _13 as usize (Transmute); + StorageDead(_13); + StorageDead(_11); + switchInt(move _12) -> [0: bb6, otherwise: bb7]; + } + + bb5: { +- _9 = _6 as *const [bool; 0] (PointerCoercion(MutToConstPointer)); ++ _9 = const {0x1 as *mut [bool; 0]} as *const [bool; 0] (PointerCoercion(MutToConstPointer)); + _5 = NonNull::<[bool; 0]> { pointer: _9 }; StorageDead(_9); StorageDead(_8); StorageDead(_6); @@ -90,6 +125,7 @@ _3 = move _4 as std::ptr::Unique<[bool]> (PointerCoercion(Unsize)); StorageDead(_4); _2 = Box::<[bool]>(_3, const std::alloc::Global); + StorageDead(_10); StorageDead(_3); _1 = A { foo: move _2 }; StorageDead(_2); @@ -97,13 +133,14 @@ drop(_1) -> [return: bb1, unwind: bb2]; } - bb1: { - StorageDead(_1); - return; + bb6: { + StorageDead(_12); + _10 = core::panicking::panic_nounwind(const "unsafe precondition(s) violated: NonNull::new_unchecked requires that the pointer is non-null") -> unwind unreachable; } - bb2 (cleanup): { - resume; + bb7: { + StorageDead(_12); + goto -> bb5; } } diff --git a/tests/mir-opt/inline/unwrap_unchecked.unwrap_unchecked.Inline.panic-abort.diff b/tests/mir-opt/inline/unwrap_unchecked.unwrap_unchecked.Inline.panic-abort.diff index 2a36ad9230e4b..814afbae4bf4d 100644 --- a/tests/mir-opt/inline/unwrap_unchecked.unwrap_unchecked.Inline.panic-abort.diff +++ b/tests/mir-opt/inline/unwrap_unchecked.unwrap_unchecked.Inline.panic-abort.diff @@ -9,14 +9,18 @@ + debug self => _2; + let mut _3: &std::option::Option; + let mut _4: isize; -+ let mut _5: bool; + scope 2 { + debug val => _0; + } + scope 3 { + scope 5 (inlined unreachable_unchecked) { + scope 6 { -+ scope 7 (inlined unreachable_unchecked::runtime) { ++ let _5: bool; ++ scope 7 { ++ debug should_check => _5; ++ scope 8 (inlined unreachable_unchecked::runtime) { ++ let _6: !; ++ } + } + } + } @@ -30,21 +34,34 @@ StorageLive(_2); _2 = move _1; - _0 = Option::::unwrap_unchecked(move _2) -> [return: bb1, unwind unreachable]; -- } -- -- bb1: { + StorageLive(_3); + StorageLive(_4); -+ StorageLive(_5); ++ StorageLive(_6); + _4 = discriminant(_2); -+ _5 = Eq(_4, const 1_isize); -+ assume(move _5); ++ switchInt(move _4) -> [0: bb1, 1: bb3, otherwise: bb2]; + } + + bb1: { ++ StorageLive(_5); ++ _5 = intrinsics::debug_assertions() -> [return: bb4, unwind unreachable]; ++ } ++ ++ bb2: { ++ unreachable; ++ } ++ ++ bb3: { + _0 = move ((_2 as Some).0: T); -+ StorageDead(_5); ++ StorageDead(_6); + StorageDead(_4); + StorageDead(_3); StorageDead(_2); return; ++ } ++ ++ bb4: { ++ assume(_5); ++ _6 = core::panicking::panic_nounwind(const "unsafe precondition(s) violated: hint::unreachable_unchecked must never be reached") -> unwind unreachable; } } diff --git a/tests/mir-opt/inline/unwrap_unchecked.unwrap_unchecked.Inline.panic-unwind.diff b/tests/mir-opt/inline/unwrap_unchecked.unwrap_unchecked.Inline.panic-unwind.diff index 14c8c671d3fe2..d32f01b2d3e26 100644 --- a/tests/mir-opt/inline/unwrap_unchecked.unwrap_unchecked.Inline.panic-unwind.diff +++ b/tests/mir-opt/inline/unwrap_unchecked.unwrap_unchecked.Inline.panic-unwind.diff @@ -9,14 +9,18 @@ + debug self => _2; + let mut _3: &std::option::Option; + let mut _4: isize; -+ let mut _5: bool; + scope 2 { + debug val => _0; + } + scope 3 { + scope 5 (inlined unreachable_unchecked) { + scope 6 { -+ scope 7 (inlined unreachable_unchecked::runtime) { ++ let _5: bool; ++ scope 7 { ++ debug should_check => _5; ++ scope 8 (inlined unreachable_unchecked::runtime) { ++ let _6: !; ++ } + } + } + } @@ -30,25 +34,36 @@ StorageLive(_2); _2 = move _1; - _0 = Option::::unwrap_unchecked(move _2) -> [return: bb1, unwind: bb2]; -- } -- -- bb1: { + StorageLive(_3); + StorageLive(_4); -+ StorageLive(_5); ++ StorageLive(_6); + _4 = discriminant(_2); -+ _5 = Eq(_4, const 1_isize); -+ assume(move _5); ++ switchInt(move _4) -> [0: bb1, 1: bb3, otherwise: bb2]; + } + + bb1: { ++ StorageLive(_5); ++ _5 = intrinsics::debug_assertions() -> [return: bb4, unwind unreachable]; ++ } ++ ++ bb2: { ++ unreachable; ++ } ++ ++ bb3: { + _0 = move ((_2 as Some).0: T); -+ StorageDead(_5); ++ StorageDead(_6); + StorageDead(_4); + StorageDead(_3); StorageDead(_2); return; -- } -- + } + - bb2 (cleanup): { - resume; ++ bb4: { ++ assume(_5); ++ _6 = core::panicking::panic_nounwind(const "unsafe precondition(s) violated: hint::unreachable_unchecked must never be reached") -> unwind unreachable; } } diff --git a/tests/mir-opt/inline/unwrap_unchecked.unwrap_unchecked.PreCodegen.after.panic-abort.mir b/tests/mir-opt/inline/unwrap_unchecked.unwrap_unchecked.PreCodegen.after.panic-abort.mir index d6a608476df9c..aaedd1437b475 100644 --- a/tests/mir-opt/inline/unwrap_unchecked.unwrap_unchecked.PreCodegen.after.panic-abort.mir +++ b/tests/mir-opt/inline/unwrap_unchecked.unwrap_unchecked.PreCodegen.after.panic-abort.mir @@ -6,35 +6,53 @@ fn unwrap_unchecked(_1: Option) -> T { scope 1 (inlined #[track_caller] Option::::unwrap_unchecked) { debug self => _1; let mut _2: isize; - let mut _3: bool; - let mut _4: &std::option::Option; + let mut _5: &std::option::Option; scope 2 { debug val => _0; } scope 3 { scope 5 (inlined unreachable_unchecked) { scope 6 { - scope 7 (inlined unreachable_unchecked::runtime) { + let _3: bool; + scope 7 { + debug should_check => _3; + scope 8 (inlined unreachable_unchecked::runtime) { + let _4: !; + } } } } } scope 4 (inlined Option::::is_some) { - debug self => _4; + debug self => _5; } } bb0: { - StorageLive(_4); + StorageLive(_5); StorageLive(_2); - StorageLive(_3); _2 = discriminant(_1); - _3 = Eq(_2, const 1_isize); - assume(move _3); + switchInt(move _2) -> [0: bb1, 1: bb3, otherwise: bb4]; + } + + bb1: { + StorageLive(_3); + _3 = intrinsics::debug_assertions() -> [return: bb2, unwind unreachable]; + } + + bb2: { + assume(_3); + _4 = core::panicking::panic_nounwind(const "unsafe precondition(s) violated: hint::unreachable_unchecked must never be reached") -> unwind unreachable; + } + + bb3: { _0 = ((_1 as Some).0: T); - StorageDead(_3); StorageDead(_2); - StorageDead(_4); + StorageDead(_5); return; } + + bb4: { + unreachable; + } } diff --git a/tests/mir-opt/inline/unwrap_unchecked.unwrap_unchecked.PreCodegen.after.panic-unwind.mir b/tests/mir-opt/inline/unwrap_unchecked.unwrap_unchecked.PreCodegen.after.panic-unwind.mir index d6a608476df9c..aaedd1437b475 100644 --- a/tests/mir-opt/inline/unwrap_unchecked.unwrap_unchecked.PreCodegen.after.panic-unwind.mir +++ b/tests/mir-opt/inline/unwrap_unchecked.unwrap_unchecked.PreCodegen.after.panic-unwind.mir @@ -6,35 +6,53 @@ fn unwrap_unchecked(_1: Option) -> T { scope 1 (inlined #[track_caller] Option::::unwrap_unchecked) { debug self => _1; let mut _2: isize; - let mut _3: bool; - let mut _4: &std::option::Option; + let mut _5: &std::option::Option; scope 2 { debug val => _0; } scope 3 { scope 5 (inlined unreachable_unchecked) { scope 6 { - scope 7 (inlined unreachable_unchecked::runtime) { + let _3: bool; + scope 7 { + debug should_check => _3; + scope 8 (inlined unreachable_unchecked::runtime) { + let _4: !; + } } } } } scope 4 (inlined Option::::is_some) { - debug self => _4; + debug self => _5; } } bb0: { - StorageLive(_4); + StorageLive(_5); StorageLive(_2); - StorageLive(_3); _2 = discriminant(_1); - _3 = Eq(_2, const 1_isize); - assume(move _3); + switchInt(move _2) -> [0: bb1, 1: bb3, otherwise: bb4]; + } + + bb1: { + StorageLive(_3); + _3 = intrinsics::debug_assertions() -> [return: bb2, unwind unreachable]; + } + + bb2: { + assume(_3); + _4 = core::panicking::panic_nounwind(const "unsafe precondition(s) violated: hint::unreachable_unchecked must never be reached") -> unwind unreachable; + } + + bb3: { _0 = ((_1 as Some).0: T); - StorageDead(_3); StorageDead(_2); - StorageDead(_4); + StorageDead(_5); return; } + + bb4: { + unreachable; + } } diff --git a/tests/mir-opt/pre-codegen/duplicate_switch_targets.ub_if_b.PreCodegen.after.mir b/tests/mir-opt/pre-codegen/duplicate_switch_targets.ub_if_b.PreCodegen.after.mir index 0114309dbb58e..467aa75b06a4a 100644 --- a/tests/mir-opt/pre-codegen/duplicate_switch_targets.ub_if_b.PreCodegen.after.mir +++ b/tests/mir-opt/pre-codegen/duplicate_switch_targets.ub_if_b.PreCodegen.after.mir @@ -4,19 +4,39 @@ fn ub_if_b(_1: Thing) -> Thing { debug t => _1; let mut _0: Thing; let mut _2: isize; - let mut _3: bool; scope 1 (inlined unreachable_unchecked) { scope 2 { - scope 3 (inlined unreachable_unchecked::runtime) { + let _3: bool; + scope 3 { + debug should_check => _3; + scope 4 (inlined unreachable_unchecked::runtime) { + let _4: !; + } } } } bb0: { _2 = discriminant(_1); - _3 = Eq(_2, const 0_isize); - assume(move _3); + switchInt(move _2) -> [0: bb1, 1: bb2, otherwise: bb4]; + } + + bb1: { _0 = move _1; return; } + + bb2: { + StorageLive(_3); + _3 = intrinsics::debug_assertions() -> [return: bb3, unwind unreachable]; + } + + bb3: { + assume(_3); + _4 = core::panicking::panic_nounwind(const "unsafe precondition(s) violated: hint::unreachable_unchecked must never be reached") -> unwind unreachable; + } + + bb4: { + unreachable; + } } diff --git a/tests/mir-opt/pre-codegen/mem_replace.manual_replace.PreCodegen.after.mir b/tests/mir-opt/pre-codegen/mem_replace.manual_replace.PreCodegen.after.panic-abort.mir similarity index 100% rename from tests/mir-opt/pre-codegen/mem_replace.manual_replace.PreCodegen.after.mir rename to tests/mir-opt/pre-codegen/mem_replace.manual_replace.PreCodegen.after.panic-abort.mir diff --git a/tests/mir-opt/pre-codegen/mem_replace.manual_replace.PreCodegen.after.panic-unwind.mir b/tests/mir-opt/pre-codegen/mem_replace.manual_replace.PreCodegen.after.panic-unwind.mir new file mode 100644 index 0000000000000..3ca24e152a4e0 --- /dev/null +++ b/tests/mir-opt/pre-codegen/mem_replace.manual_replace.PreCodegen.after.panic-unwind.mir @@ -0,0 +1,16 @@ +// MIR for `manual_replace` after PreCodegen + +fn manual_replace(_1: &mut u32, _2: u32) -> u32 { + debug r => _1; + debug v => _2; + let mut _0: u32; + scope 1 { + debug temp => _0; + } + + bb0: { + _0 = (*_1); + (*_1) = _2; + return; + } +} diff --git a/tests/mir-opt/pre-codegen/mem_replace.mem_replace.PreCodegen.after.mir b/tests/mir-opt/pre-codegen/mem_replace.mem_replace.PreCodegen.after.mir deleted file mode 100644 index f0cb4ca31fecc..0000000000000 --- a/tests/mir-opt/pre-codegen/mem_replace.mem_replace.PreCodegen.after.mir +++ /dev/null @@ -1,66 +0,0 @@ -// MIR for `mem_replace` after PreCodegen - -fn mem_replace(_1: &mut u32, _2: u32) -> u32 { - debug r => _1; - debug v => _2; - let mut _0: u32; - scope 1 (inlined std::mem::replace::) { - debug dest => _1; - debug src => _2; - scope 2 { - scope 3 { - debug result => _0; - scope 16 (inlined std::ptr::write::) { - debug dst => _1; - debug src => _2; - scope 17 { - } - } - } - scope 4 (inlined std::ptr::read::) { - debug src => _1; - let mut _3: *const u32; - scope 5 { - scope 6 (inlined std::ptr::read::runtime::) { - debug src => _3; - scope 7 (inlined intrinsics::is_aligned_and_not_null::) { - debug ptr => _3; - scope 8 (inlined std::ptr::const_ptr::::is_null) { - debug self => _3; - let mut _4: *const u8; - scope 9 { - scope 10 (inlined std::ptr::const_ptr::::is_null::runtime_impl) { - debug ptr => _4; - scope 11 (inlined std::ptr::const_ptr::::addr) { - debug self => _4; - scope 12 { - scope 13 (inlined std::ptr::const_ptr::::cast::<()>) { - debug self => _4; - } - } - } - } - } - } - scope 14 (inlined std::ptr::const_ptr::::is_aligned) { - debug self => _3; - scope 15 (inlined align_of::) { - } - } - } - } - } - } - } - } - - bb0: { - StorageLive(_3); - StorageLive(_4); - _0 = (*_1); - StorageDead(_4); - StorageDead(_3); - (*_1) = _2; - return; - } -} diff --git a/tests/mir-opt/pre-codegen/mem_replace.mem_replace.PreCodegen.after.panic-abort.mir b/tests/mir-opt/pre-codegen/mem_replace.mem_replace.PreCodegen.after.panic-abort.mir new file mode 100644 index 0000000000000..26919dd98dd27 --- /dev/null +++ b/tests/mir-opt/pre-codegen/mem_replace.mem_replace.PreCodegen.after.panic-abort.mir @@ -0,0 +1,33 @@ +// MIR for `mem_replace` after PreCodegen + +fn mem_replace(_1: &mut u32, _2: u32) -> u32 { + debug r => _1; + debug v => _2; + let mut _0: u32; + scope 1 (inlined std::mem::replace::) { + debug dest => _1; + debug src => _2; + scope 2 { + scope 3 { + debug result => _0; + scope 6 (inlined std::ptr::write::) { + debug dst => _1; + debug src => _2; + scope 7 { + } + } + } + scope 4 (inlined std::ptr::read::) { + debug src => _1; + scope 5 { + } + } + } + } + + bb0: { + _0 = (*_1); + (*_1) = _2; + return; + } +} diff --git a/tests/mir-opt/pre-codegen/mem_replace.mem_replace.PreCodegen.after.panic-unwind.mir b/tests/mir-opt/pre-codegen/mem_replace.mem_replace.PreCodegen.after.panic-unwind.mir new file mode 100644 index 0000000000000..26919dd98dd27 --- /dev/null +++ b/tests/mir-opt/pre-codegen/mem_replace.mem_replace.PreCodegen.after.panic-unwind.mir @@ -0,0 +1,33 @@ +// MIR for `mem_replace` after PreCodegen + +fn mem_replace(_1: &mut u32, _2: u32) -> u32 { + debug r => _1; + debug v => _2; + let mut _0: u32; + scope 1 (inlined std::mem::replace::) { + debug dest => _1; + debug src => _2; + scope 2 { + scope 3 { + debug result => _0; + scope 6 (inlined std::ptr::write::) { + debug dst => _1; + debug src => _2; + scope 7 { + } + } + } + scope 4 (inlined std::ptr::read::) { + debug src => _1; + scope 5 { + } + } + } + } + + bb0: { + _0 = (*_1); + (*_1) = _2; + return; + } +} diff --git a/tests/mir-opt/pre-codegen/mem_replace.rs b/tests/mir-opt/pre-codegen/mem_replace.rs index 18c4653d4c6ea..551afea3ba5a8 100644 --- a/tests/mir-opt/pre-codegen/mem_replace.rs +++ b/tests/mir-opt/pre-codegen/mem_replace.rs @@ -1,7 +1,8 @@ // skip-filecheck -// compile-flags: -O -C debuginfo=0 -Zmir-opt-level=2 +// compile-flags: -O -C debuginfo=0 -Zmir-opt-level=2 -Zinline-mir // only-64bit // ignore-debug the standard library debug assertions leak into this test +// EMIT_MIR_FOR_EACH_PANIC_STRATEGY #![crate_type = "lib"] diff --git a/tests/mir-opt/pre-codegen/slice_iter.enumerated_loop.PreCodegen.after.panic-abort.mir b/tests/mir-opt/pre-codegen/slice_iter.enumerated_loop.PreCodegen.after.panic-abort.mir index 26b2663fa3580..6ddcf0edf78f2 100644 --- a/tests/mir-opt/pre-codegen/slice_iter.enumerated_loop.PreCodegen.after.panic-abort.mir +++ b/tests/mir-opt/pre-codegen/slice_iter.enumerated_loop.PreCodegen.after.panic-abort.mir @@ -4,196 +4,91 @@ fn enumerated_loop(_1: &[T], _2: impl Fn(usize, &T)) -> () { debug slice => _1; debug f => _2; let mut _0: (); - let mut _13: std::slice::Iter<'_, T>; - let mut _14: std::iter::Enumerate>; - let mut _15: std::iter::Enumerate>; - let mut _16: &mut std::iter::Enumerate>; - let mut _17: std::option::Option<(usize, &T)>; - let mut _18: isize; - let mut _21: &impl Fn(usize, &T); - let mut _22: (usize, &T); - let _23: (); + let mut _3: std::slice::Iter<'_, T>; + let mut _4: std::iter::Enumerate>; + let mut _5: std::iter::Enumerate>; + let mut _6: &mut std::iter::Enumerate>; + let mut _7: std::option::Option<(usize, &T)>; + let mut _8: isize; + let mut _11: &impl Fn(usize, &T); + let mut _12: (usize, &T); + let _13: (); scope 1 { - debug iter => _15; - let _19: usize; - let _20: &T; + debug iter => _5; + let _9: usize; + let _10: &T; scope 2 { - debug i => _19; - debug x => _20; + debug i => _9; + debug x => _10; } } scope 3 (inlined core::slice::::iter) { debug self => _1; - scope 4 (inlined std::slice::Iter::<'_, T>::new) { - debug slice => _1; - let _4: *const T; - let mut _5: bool; - let mut _6: usize; - let mut _8: usize; - let mut _9: *mut T; - let mut _11: std::ptr::NonNull; - let mut _12: *const T; - scope 5 { - debug ptr => _4; - scope 6 { - let _7: *const T; - scope 7 { - debug end_or_len => _7; - scope 13 (inlined NonNull::::new_unchecked) { - debug ptr => _9; - let mut _10: *const T; - let mut _24: *mut T; - scope 14 { - scope 15 (inlined NonNull::::new_unchecked::runtime::) { - debug ptr => _24; - scope 16 (inlined std::ptr::mut_ptr::::is_null) { - debug self => _24; - let mut _25: *mut u8; - scope 17 { - scope 18 (inlined std::ptr::mut_ptr::::is_null::runtime_impl) { - debug ptr => _25; - scope 19 (inlined std::ptr::mut_ptr::::addr) { - debug self => _25; - scope 20 { - scope 21 (inlined std::ptr::mut_ptr::::cast::<()>) { - debug self => _25; - } - } - } - } - } - } - } - } - } - } - scope 9 (inlined invalid::) { - debug addr => _8; - scope 10 { - } - } - scope 11 (inlined std::ptr::const_ptr::::add) { - debug self => _4; - debug count => _6; - scope 12 { - } - } - } - } - scope 8 (inlined core::slice::::as_ptr) { - debug self => _1; - let mut _3: *const [T]; - } - } } - scope 22 (inlined as Iterator>::enumerate) { - debug self => _13; - scope 23 (inlined Enumerate::>::new) { - debug iter => _13; + scope 4 (inlined as Iterator>::enumerate) { + debug self => _3; + scope 5 (inlined Enumerate::>::new) { + debug iter => _3; } } - scope 24 (inlined > as IntoIterator>::into_iter) { - debug self => _14; + scope 6 (inlined > as IntoIterator>::into_iter) { + debug self => _4; } bb0: { - StorageLive(_13); - StorageLive(_4); StorageLive(_3); - _3 = &raw const (*_1); - _4 = move _3 as *const T (PtrToPtr); - StorageDead(_3); - StorageLive(_7); - StorageLive(_5); - _5 = const _; - switchInt(move _5) -> [0: bb1, otherwise: bb2]; + _3 = std::slice::Iter::<'_, T>::new(move _1) -> [return: bb1, unwind unreachable]; } bb1: { - StorageLive(_6); - _6 = Len((*_1)); - _7 = Offset(_4, _6); - StorageDead(_6); - goto -> bb3; + _4 = Enumerate::> { iter: _3, count: const 0_usize }; + StorageDead(_3); + StorageLive(_5); + _5 = _4; + goto -> bb2; } bb2: { - StorageLive(_8); - _8 = Len((*_1)); - _7 = _8 as *const T (Transmute); - StorageDead(_8); - goto -> bb3; + StorageLive(_7); + StorageLive(_6); + _6 = &mut _5; + _7 = > as Iterator>::next(move _6) -> [return: bb3, unwind unreachable]; } bb3: { - StorageDead(_5); - StorageLive(_11); - StorageLive(_9); - _9 = _4 as *mut T (PtrToPtr); - StorageLive(_10); - StorageLive(_24); - StorageLive(_25); - _10 = _9 as *const T (PointerCoercion(MutToConstPointer)); - _11 = NonNull:: { pointer: _10 }; - StorageDead(_25); - StorageDead(_24); - StorageDead(_10); - StorageDead(_9); - StorageLive(_12); - _12 = _7; - _13 = std::slice::Iter::<'_, T> { ptr: move _11, end_or_len: move _12, _marker: const ZeroSized: PhantomData<&T> }; - StorageDead(_12); - StorageDead(_11); - StorageDead(_7); - StorageDead(_4); - _14 = Enumerate::> { iter: _13, count: const 0_usize }; - StorageDead(_13); - StorageLive(_15); - _15 = _14; - goto -> bb4; + StorageDead(_6); + _8 = discriminant(_7); + switchInt(move _8) -> [0: bb4, 1: bb6, otherwise: bb8]; } bb4: { - StorageLive(_17); - StorageLive(_16); - _16 = &mut _15; - _17 = > as Iterator>::next(move _16) -> [return: bb5, unwind unreachable]; + StorageDead(_7); + StorageDead(_5); + drop(_2) -> [return: bb5, unwind unreachable]; } bb5: { - StorageDead(_16); - _18 = discriminant(_17); - switchInt(move _18) -> [0: bb6, 1: bb8, otherwise: bb10]; + return; } bb6: { - StorageDead(_17); - StorageDead(_15); - drop(_2) -> [return: bb7, unwind unreachable]; + _9 = (((_7 as Some).0: (usize, &T)).0: usize); + _10 = (((_7 as Some).0: (usize, &T)).1: &T); + StorageLive(_11); + _11 = &_2; + StorageLive(_12); + _12 = (_9, _10); + _13 = >::call(move _11, move _12) -> [return: bb7, unwind unreachable]; } bb7: { - return; + StorageDead(_12); + StorageDead(_11); + StorageDead(_7); + goto -> bb2; } bb8: { - _19 = (((_17 as Some).0: (usize, &T)).0: usize); - _20 = (((_17 as Some).0: (usize, &T)).1: &T); - StorageLive(_21); - _21 = &_2; - StorageLive(_22); - _22 = (_19, _20); - _23 = >::call(move _21, move _22) -> [return: bb9, unwind unreachable]; - } - - bb9: { - StorageDead(_22); - StorageDead(_21); - StorageDead(_17); - goto -> bb4; - } - - bb10: { unreachable; } } diff --git a/tests/mir-opt/pre-codegen/slice_iter.enumerated_loop.PreCodegen.after.panic-unwind.mir b/tests/mir-opt/pre-codegen/slice_iter.enumerated_loop.PreCodegen.after.panic-unwind.mir index a055612bd5feb..577f2a599420d 100644 --- a/tests/mir-opt/pre-codegen/slice_iter.enumerated_loop.PreCodegen.after.panic-unwind.mir +++ b/tests/mir-opt/pre-codegen/slice_iter.enumerated_loop.PreCodegen.after.panic-unwind.mir @@ -4,204 +4,99 @@ fn enumerated_loop(_1: &[T], _2: impl Fn(usize, &T)) -> () { debug slice => _1; debug f => _2; let mut _0: (); - let mut _13: std::slice::Iter<'_, T>; - let mut _14: std::iter::Enumerate>; - let mut _15: std::iter::Enumerate>; - let mut _16: &mut std::iter::Enumerate>; - let mut _17: std::option::Option<(usize, &T)>; - let mut _18: isize; - let mut _21: &impl Fn(usize, &T); - let mut _22: (usize, &T); - let _23: (); + let mut _3: std::slice::Iter<'_, T>; + let mut _4: std::iter::Enumerate>; + let mut _5: std::iter::Enumerate>; + let mut _6: &mut std::iter::Enumerate>; + let mut _7: std::option::Option<(usize, &T)>; + let mut _8: isize; + let mut _11: &impl Fn(usize, &T); + let mut _12: (usize, &T); + let _13: (); scope 1 { - debug iter => _15; - let _19: usize; - let _20: &T; + debug iter => _5; + let _9: usize; + let _10: &T; scope 2 { - debug i => _19; - debug x => _20; + debug i => _9; + debug x => _10; } } scope 3 (inlined core::slice::::iter) { debug self => _1; - scope 4 (inlined std::slice::Iter::<'_, T>::new) { - debug slice => _1; - let _4: *const T; - let mut _5: bool; - let mut _6: usize; - let mut _8: usize; - let mut _9: *mut T; - let mut _11: std::ptr::NonNull; - let mut _12: *const T; - scope 5 { - debug ptr => _4; - scope 6 { - let _7: *const T; - scope 7 { - debug end_or_len => _7; - scope 13 (inlined NonNull::::new_unchecked) { - debug ptr => _9; - let mut _10: *const T; - let mut _24: *mut T; - scope 14 { - scope 15 (inlined NonNull::::new_unchecked::runtime::) { - debug ptr => _24; - scope 16 (inlined std::ptr::mut_ptr::::is_null) { - debug self => _24; - let mut _25: *mut u8; - scope 17 { - scope 18 (inlined std::ptr::mut_ptr::::is_null::runtime_impl) { - debug ptr => _25; - scope 19 (inlined std::ptr::mut_ptr::::addr) { - debug self => _25; - scope 20 { - scope 21 (inlined std::ptr::mut_ptr::::cast::<()>) { - debug self => _25; - } - } - } - } - } - } - } - } - } - } - scope 9 (inlined invalid::) { - debug addr => _8; - scope 10 { - } - } - scope 11 (inlined std::ptr::const_ptr::::add) { - debug self => _4; - debug count => _6; - scope 12 { - } - } - } - } - scope 8 (inlined core::slice::::as_ptr) { - debug self => _1; - let mut _3: *const [T]; - } - } } - scope 22 (inlined as Iterator>::enumerate) { - debug self => _13; - scope 23 (inlined Enumerate::>::new) { - debug iter => _13; + scope 4 (inlined as Iterator>::enumerate) { + debug self => _3; + scope 5 (inlined Enumerate::>::new) { + debug iter => _3; } } - scope 24 (inlined > as IntoIterator>::into_iter) { - debug self => _14; + scope 6 (inlined > as IntoIterator>::into_iter) { + debug self => _4; } bb0: { - StorageLive(_13); - StorageLive(_4); StorageLive(_3); - _3 = &raw const (*_1); - _4 = move _3 as *const T (PtrToPtr); - StorageDead(_3); - StorageLive(_7); - StorageLive(_5); - _5 = const _; - switchInt(move _5) -> [0: bb1, otherwise: bb2]; + _3 = std::slice::Iter::<'_, T>::new(move _1) -> [return: bb1, unwind: bb9]; } bb1: { - StorageLive(_6); - _6 = Len((*_1)); - _7 = Offset(_4, _6); - StorageDead(_6); - goto -> bb3; + _4 = Enumerate::> { iter: _3, count: const 0_usize }; + StorageDead(_3); + StorageLive(_5); + _5 = _4; + goto -> bb2; } bb2: { - StorageLive(_8); - _8 = Len((*_1)); - _7 = _8 as *const T (Transmute); - StorageDead(_8); - goto -> bb3; + StorageLive(_7); + StorageLive(_6); + _6 = &mut _5; + _7 = > as Iterator>::next(move _6) -> [return: bb3, unwind: bb9]; } bb3: { - StorageDead(_5); - StorageLive(_11); - StorageLive(_9); - _9 = _4 as *mut T (PtrToPtr); - StorageLive(_10); - StorageLive(_24); - StorageLive(_25); - _10 = _9 as *const T (PointerCoercion(MutToConstPointer)); - _11 = NonNull:: { pointer: _10 }; - StorageDead(_25); - StorageDead(_24); - StorageDead(_10); - StorageDead(_9); - StorageLive(_12); - _12 = _7; - _13 = std::slice::Iter::<'_, T> { ptr: move _11, end_or_len: move _12, _marker: const ZeroSized: PhantomData<&T> }; - StorageDead(_12); - StorageDead(_11); - StorageDead(_7); - StorageDead(_4); - _14 = Enumerate::> { iter: _13, count: const 0_usize }; - StorageDead(_13); - StorageLive(_15); - _15 = _14; - goto -> bb4; + StorageDead(_6); + _8 = discriminant(_7); + switchInt(move _8) -> [0: bb4, 1: bb6, otherwise: bb8]; } bb4: { - StorageLive(_17); - StorageLive(_16); - _16 = &mut _15; - _17 = > as Iterator>::next(move _16) -> [return: bb5, unwind: bb11]; + StorageDead(_7); + StorageDead(_5); + drop(_2) -> [return: bb5, unwind continue]; } bb5: { - StorageDead(_16); - _18 = discriminant(_17); - switchInt(move _18) -> [0: bb6, 1: bb8, otherwise: bb10]; + return; } bb6: { - StorageDead(_17); - StorageDead(_15); - drop(_2) -> [return: bb7, unwind continue]; + _9 = (((_7 as Some).0: (usize, &T)).0: usize); + _10 = (((_7 as Some).0: (usize, &T)).1: &T); + StorageLive(_11); + _11 = &_2; + StorageLive(_12); + _12 = (_9, _10); + _13 = >::call(move _11, move _12) -> [return: bb7, unwind: bb9]; } bb7: { - return; + StorageDead(_12); + StorageDead(_11); + StorageDead(_7); + goto -> bb2; } bb8: { - _19 = (((_17 as Some).0: (usize, &T)).0: usize); - _20 = (((_17 as Some).0: (usize, &T)).1: &T); - StorageLive(_21); - _21 = &_2; - StorageLive(_22); - _22 = (_19, _20); - _23 = >::call(move _21, move _22) -> [return: bb9, unwind: bb11]; - } - - bb9: { - StorageDead(_22); - StorageDead(_21); - StorageDead(_17); - goto -> bb4; - } - - bb10: { unreachable; } - bb11 (cleanup): { - drop(_2) -> [return: bb12, unwind terminate(cleanup)]; + bb9 (cleanup): { + drop(_2) -> [return: bb10, unwind terminate(cleanup)]; } - bb12 (cleanup): { + bb10 (cleanup): { resume; } } diff --git a/tests/mir-opt/pre-codegen/slice_iter.forward_loop.PreCodegen.after.panic-abort.mir b/tests/mir-opt/pre-codegen/slice_iter.forward_loop.PreCodegen.after.panic-abort.mir index 471491108e0b6..4f84ac739678a 100644 --- a/tests/mir-opt/pre-codegen/slice_iter.forward_loop.PreCodegen.after.panic-abort.mir +++ b/tests/mir-opt/pre-codegen/slice_iter.forward_loop.PreCodegen.after.panic-abort.mir @@ -4,183 +4,78 @@ fn forward_loop(_1: &[T], _2: impl Fn(&T)) -> () { debug slice => _1; debug f => _2; let mut _0: (); - let mut _13: std::slice::Iter<'_, T>; - let mut _14: std::slice::Iter<'_, T>; - let mut _15: &mut std::slice::Iter<'_, T>; - let mut _16: std::option::Option<&T>; - let mut _17: isize; - let mut _19: &impl Fn(&T); - let mut _20: (&T,); - let _21: (); + let mut _3: std::slice::Iter<'_, T>; + let mut _4: std::slice::Iter<'_, T>; + let mut _5: &mut std::slice::Iter<'_, T>; + let mut _6: std::option::Option<&T>; + let mut _7: isize; + let mut _9: &impl Fn(&T); + let mut _10: (&T,); + let _11: (); scope 1 { - debug iter => _14; - let _18: &T; + debug iter => _4; + let _8: &T; scope 2 { - debug x => _18; + debug x => _8; } } scope 3 (inlined core::slice::::iter) { debug self => _1; - scope 4 (inlined std::slice::Iter::<'_, T>::new) { - debug slice => _1; - let _4: *const T; - let mut _5: bool; - let mut _6: usize; - let mut _8: usize; - let mut _9: *mut T; - let mut _11: std::ptr::NonNull; - let mut _12: *const T; - scope 5 { - debug ptr => _4; - scope 6 { - let _7: *const T; - scope 7 { - debug end_or_len => _7; - scope 13 (inlined NonNull::::new_unchecked) { - debug ptr => _9; - let mut _10: *const T; - let mut _22: *mut T; - scope 14 { - scope 15 (inlined NonNull::::new_unchecked::runtime::) { - debug ptr => _22; - scope 16 (inlined std::ptr::mut_ptr::::is_null) { - debug self => _22; - let mut _23: *mut u8; - scope 17 { - scope 18 (inlined std::ptr::mut_ptr::::is_null::runtime_impl) { - debug ptr => _23; - scope 19 (inlined std::ptr::mut_ptr::::addr) { - debug self => _23; - scope 20 { - scope 21 (inlined std::ptr::mut_ptr::::cast::<()>) { - debug self => _23; - } - } - } - } - } - } - } - } - } - } - scope 9 (inlined invalid::) { - debug addr => _8; - scope 10 { - } - } - scope 11 (inlined std::ptr::const_ptr::::add) { - debug self => _4; - debug count => _6; - scope 12 { - } - } - } - } - scope 8 (inlined core::slice::::as_ptr) { - debug self => _1; - let mut _3: *const [T]; - } - } } - scope 22 (inlined as IntoIterator>::into_iter) { - debug self => _13; + scope 4 (inlined as IntoIterator>::into_iter) { + debug self => _3; } bb0: { - StorageLive(_4); - StorageLive(_3); - _3 = &raw const (*_1); - _4 = move _3 as *const T (PtrToPtr); - StorageDead(_3); - StorageLive(_7); - StorageLive(_5); - _5 = const _; - switchInt(move _5) -> [0: bb1, otherwise: bb2]; + _3 = std::slice::Iter::<'_, T>::new(move _1) -> [return: bb1, unwind unreachable]; } bb1: { - StorageLive(_6); - _6 = Len((*_1)); - _7 = Offset(_4, _6); - StorageDead(_6); - goto -> bb3; + StorageLive(_4); + _4 = _3; + goto -> bb2; } bb2: { - StorageLive(_8); - _8 = Len((*_1)); - _7 = _8 as *const T (Transmute); - StorageDead(_8); - goto -> bb3; + StorageLive(_6); + StorageLive(_5); + _5 = &mut _4; + _6 = as Iterator>::next(move _5) -> [return: bb3, unwind unreachable]; } bb3: { StorageDead(_5); - StorageLive(_11); - StorageLive(_9); - _9 = _4 as *mut T (PtrToPtr); - StorageLive(_10); - StorageLive(_22); - StorageLive(_23); - _10 = _9 as *const T (PointerCoercion(MutToConstPointer)); - _11 = NonNull:: { pointer: _10 }; - StorageDead(_23); - StorageDead(_22); - StorageDead(_10); - StorageDead(_9); - StorageLive(_12); - _12 = _7; - _13 = std::slice::Iter::<'_, T> { ptr: move _11, end_or_len: move _12, _marker: const ZeroSized: PhantomData<&T> }; - StorageDead(_12); - StorageDead(_11); - StorageDead(_7); - StorageDead(_4); - StorageLive(_14); - _14 = _13; - goto -> bb4; + _7 = discriminant(_6); + switchInt(move _7) -> [0: bb4, 1: bb6, otherwise: bb8]; } bb4: { - StorageLive(_16); - StorageLive(_15); - _15 = &mut _14; - _16 = as Iterator>::next(move _15) -> [return: bb5, unwind unreachable]; + StorageDead(_6); + StorageDead(_4); + drop(_2) -> [return: bb5, unwind unreachable]; } bb5: { - StorageDead(_15); - _17 = discriminant(_16); - switchInt(move _17) -> [0: bb6, 1: bb8, otherwise: bb10]; + return; } bb6: { - StorageDead(_16); - StorageDead(_14); - drop(_2) -> [return: bb7, unwind unreachable]; + _8 = ((_6 as Some).0: &T); + StorageLive(_9); + _9 = &_2; + StorageLive(_10); + _10 = (_8,); + _11 = >::call(move _9, move _10) -> [return: bb7, unwind unreachable]; } bb7: { - return; + StorageDead(_10); + StorageDead(_9); + StorageDead(_6); + goto -> bb2; } bb8: { - _18 = ((_16 as Some).0: &T); - StorageLive(_19); - _19 = &_2; - StorageLive(_20); - _20 = (_18,); - _21 = >::call(move _19, move _20) -> [return: bb9, unwind unreachable]; - } - - bb9: { - StorageDead(_20); - StorageDead(_19); - StorageDead(_16); - goto -> bb4; - } - - bb10: { unreachable; } } diff --git a/tests/mir-opt/pre-codegen/slice_iter.forward_loop.PreCodegen.after.panic-unwind.mir b/tests/mir-opt/pre-codegen/slice_iter.forward_loop.PreCodegen.after.panic-unwind.mir index bbf38aba91f08..acbd958eb4bb9 100644 --- a/tests/mir-opt/pre-codegen/slice_iter.forward_loop.PreCodegen.after.panic-unwind.mir +++ b/tests/mir-opt/pre-codegen/slice_iter.forward_loop.PreCodegen.after.panic-unwind.mir @@ -4,191 +4,86 @@ fn forward_loop(_1: &[T], _2: impl Fn(&T)) -> () { debug slice => _1; debug f => _2; let mut _0: (); - let mut _13: std::slice::Iter<'_, T>; - let mut _14: std::slice::Iter<'_, T>; - let mut _15: &mut std::slice::Iter<'_, T>; - let mut _16: std::option::Option<&T>; - let mut _17: isize; - let mut _19: &impl Fn(&T); - let mut _20: (&T,); - let _21: (); + let mut _3: std::slice::Iter<'_, T>; + let mut _4: std::slice::Iter<'_, T>; + let mut _5: &mut std::slice::Iter<'_, T>; + let mut _6: std::option::Option<&T>; + let mut _7: isize; + let mut _9: &impl Fn(&T); + let mut _10: (&T,); + let _11: (); scope 1 { - debug iter => _14; - let _18: &T; + debug iter => _4; + let _8: &T; scope 2 { - debug x => _18; + debug x => _8; } } scope 3 (inlined core::slice::::iter) { debug self => _1; - scope 4 (inlined std::slice::Iter::<'_, T>::new) { - debug slice => _1; - let _4: *const T; - let mut _5: bool; - let mut _6: usize; - let mut _8: usize; - let mut _9: *mut T; - let mut _11: std::ptr::NonNull; - let mut _12: *const T; - scope 5 { - debug ptr => _4; - scope 6 { - let _7: *const T; - scope 7 { - debug end_or_len => _7; - scope 13 (inlined NonNull::::new_unchecked) { - debug ptr => _9; - let mut _10: *const T; - let mut _22: *mut T; - scope 14 { - scope 15 (inlined NonNull::::new_unchecked::runtime::) { - debug ptr => _22; - scope 16 (inlined std::ptr::mut_ptr::::is_null) { - debug self => _22; - let mut _23: *mut u8; - scope 17 { - scope 18 (inlined std::ptr::mut_ptr::::is_null::runtime_impl) { - debug ptr => _23; - scope 19 (inlined std::ptr::mut_ptr::::addr) { - debug self => _23; - scope 20 { - scope 21 (inlined std::ptr::mut_ptr::::cast::<()>) { - debug self => _23; - } - } - } - } - } - } - } - } - } - } - scope 9 (inlined invalid::) { - debug addr => _8; - scope 10 { - } - } - scope 11 (inlined std::ptr::const_ptr::::add) { - debug self => _4; - debug count => _6; - scope 12 { - } - } - } - } - scope 8 (inlined core::slice::::as_ptr) { - debug self => _1; - let mut _3: *const [T]; - } - } } - scope 22 (inlined as IntoIterator>::into_iter) { - debug self => _13; + scope 4 (inlined as IntoIterator>::into_iter) { + debug self => _3; } bb0: { - StorageLive(_4); - StorageLive(_3); - _3 = &raw const (*_1); - _4 = move _3 as *const T (PtrToPtr); - StorageDead(_3); - StorageLive(_7); - StorageLive(_5); - _5 = const _; - switchInt(move _5) -> [0: bb1, otherwise: bb2]; + _3 = std::slice::Iter::<'_, T>::new(move _1) -> [return: bb1, unwind: bb9]; } bb1: { - StorageLive(_6); - _6 = Len((*_1)); - _7 = Offset(_4, _6); - StorageDead(_6); - goto -> bb3; + StorageLive(_4); + _4 = _3; + goto -> bb2; } bb2: { - StorageLive(_8); - _8 = Len((*_1)); - _7 = _8 as *const T (Transmute); - StorageDead(_8); - goto -> bb3; + StorageLive(_6); + StorageLive(_5); + _5 = &mut _4; + _6 = as Iterator>::next(move _5) -> [return: bb3, unwind: bb9]; } bb3: { StorageDead(_5); - StorageLive(_11); - StorageLive(_9); - _9 = _4 as *mut T (PtrToPtr); - StorageLive(_10); - StorageLive(_22); - StorageLive(_23); - _10 = _9 as *const T (PointerCoercion(MutToConstPointer)); - _11 = NonNull:: { pointer: _10 }; - StorageDead(_23); - StorageDead(_22); - StorageDead(_10); - StorageDead(_9); - StorageLive(_12); - _12 = _7; - _13 = std::slice::Iter::<'_, T> { ptr: move _11, end_or_len: move _12, _marker: const ZeroSized: PhantomData<&T> }; - StorageDead(_12); - StorageDead(_11); - StorageDead(_7); - StorageDead(_4); - StorageLive(_14); - _14 = _13; - goto -> bb4; + _7 = discriminant(_6); + switchInt(move _7) -> [0: bb4, 1: bb6, otherwise: bb8]; } bb4: { - StorageLive(_16); - StorageLive(_15); - _15 = &mut _14; - _16 = as Iterator>::next(move _15) -> [return: bb5, unwind: bb11]; + StorageDead(_6); + StorageDead(_4); + drop(_2) -> [return: bb5, unwind continue]; } bb5: { - StorageDead(_15); - _17 = discriminant(_16); - switchInt(move _17) -> [0: bb6, 1: bb8, otherwise: bb10]; + return; } bb6: { - StorageDead(_16); - StorageDead(_14); - drop(_2) -> [return: bb7, unwind continue]; + _8 = ((_6 as Some).0: &T); + StorageLive(_9); + _9 = &_2; + StorageLive(_10); + _10 = (_8,); + _11 = >::call(move _9, move _10) -> [return: bb7, unwind: bb9]; } bb7: { - return; + StorageDead(_10); + StorageDead(_9); + StorageDead(_6); + goto -> bb2; } bb8: { - _18 = ((_16 as Some).0: &T); - StorageLive(_19); - _19 = &_2; - StorageLive(_20); - _20 = (_18,); - _21 = >::call(move _19, move _20) -> [return: bb9, unwind: bb11]; - } - - bb9: { - StorageDead(_20); - StorageDead(_19); - StorageDead(_16); - goto -> bb4; - } - - bb10: { unreachable; } - bb11 (cleanup): { - drop(_2) -> [return: bb12, unwind terminate(cleanup)]; + bb9 (cleanup): { + drop(_2) -> [return: bb10, unwind terminate(cleanup)]; } - bb12 (cleanup): { + bb10 (cleanup): { resume; } } diff --git a/tests/mir-opt/pre-codegen/slice_iter.reverse_loop.PreCodegen.after.panic-abort.mir b/tests/mir-opt/pre-codegen/slice_iter.reverse_loop.PreCodegen.after.panic-abort.mir index f9c8ab4db60b7..7fc7dd5800a5d 100644 --- a/tests/mir-opt/pre-codegen/slice_iter.reverse_loop.PreCodegen.after.panic-abort.mir +++ b/tests/mir-opt/pre-codegen/slice_iter.reverse_loop.PreCodegen.after.panic-abort.mir @@ -4,198 +4,93 @@ fn reverse_loop(_1: &[T], _2: impl Fn(&T)) -> () { debug slice => _1; debug f => _2; let mut _0: (); - let mut _13: std::slice::Iter<'_, T>; - let mut _14: std::iter::Rev>; - let mut _15: std::iter::Rev>; - let mut _16: &mut std::iter::Rev>; - let mut _18: std::option::Option<&T>; - let mut _19: isize; - let mut _21: &impl Fn(&T); - let mut _22: (&T,); - let _23: (); + let mut _3: std::slice::Iter<'_, T>; + let mut _4: std::iter::Rev>; + let mut _5: std::iter::Rev>; + let mut _6: &mut std::iter::Rev>; + let mut _8: std::option::Option<&T>; + let mut _9: isize; + let mut _11: &impl Fn(&T); + let mut _12: (&T,); + let _13: (); scope 1 { - debug iter => _15; - let _20: &T; + debug iter => _5; + let _10: &T; scope 2 { - debug x => _20; + debug x => _10; } - scope 25 (inlined > as Iterator>::next) { - debug self => _16; - let mut _17: &mut std::slice::Iter<'_, T>; + scope 7 (inlined > as Iterator>::next) { + debug self => _6; + let mut _7: &mut std::slice::Iter<'_, T>; } } scope 3 (inlined core::slice::::iter) { debug self => _1; - scope 4 (inlined std::slice::Iter::<'_, T>::new) { - debug slice => _1; - let _4: *const T; - let mut _5: bool; - let mut _6: usize; - let mut _8: usize; - let mut _9: *mut T; - let mut _11: std::ptr::NonNull; - let mut _12: *const T; - scope 5 { - debug ptr => _4; - scope 6 { - let _7: *const T; - scope 7 { - debug end_or_len => _7; - scope 13 (inlined NonNull::::new_unchecked) { - debug ptr => _9; - let mut _10: *const T; - let mut _24: *mut T; - scope 14 { - scope 15 (inlined NonNull::::new_unchecked::runtime::) { - debug ptr => _24; - scope 16 (inlined std::ptr::mut_ptr::::is_null) { - debug self => _24; - let mut _25: *mut u8; - scope 17 { - scope 18 (inlined std::ptr::mut_ptr::::is_null::runtime_impl) { - debug ptr => _25; - scope 19 (inlined std::ptr::mut_ptr::::addr) { - debug self => _25; - scope 20 { - scope 21 (inlined std::ptr::mut_ptr::::cast::<()>) { - debug self => _25; - } - } - } - } - } - } - } - } - } - } - scope 9 (inlined invalid::) { - debug addr => _8; - scope 10 { - } - } - scope 11 (inlined std::ptr::const_ptr::::add) { - debug self => _4; - debug count => _6; - scope 12 { - } - } - } - } - scope 8 (inlined core::slice::::as_ptr) { - debug self => _1; - let mut _3: *const [T]; - } - } } - scope 22 (inlined as Iterator>::rev) { - debug self => _13; - scope 23 (inlined Rev::>::new) { - debug iter => _13; + scope 4 (inlined as Iterator>::rev) { + debug self => _3; + scope 5 (inlined Rev::>::new) { + debug iter => _3; } } - scope 24 (inlined > as IntoIterator>::into_iter) { - debug self => _14; + scope 6 (inlined > as IntoIterator>::into_iter) { + debug self => _4; } bb0: { - StorageLive(_13); - StorageLive(_4); StorageLive(_3); - _3 = &raw const (*_1); - _4 = move _3 as *const T (PtrToPtr); - StorageDead(_3); - StorageLive(_7); - StorageLive(_5); - _5 = const _; - switchInt(move _5) -> [0: bb1, otherwise: bb2]; + _3 = std::slice::Iter::<'_, T>::new(move _1) -> [return: bb1, unwind unreachable]; } bb1: { - StorageLive(_6); - _6 = Len((*_1)); - _7 = Offset(_4, _6); - StorageDead(_6); - goto -> bb3; + _4 = Rev::> { iter: _3 }; + StorageDead(_3); + StorageLive(_5); + _5 = _4; + goto -> bb2; } bb2: { StorageLive(_8); - _8 = Len((*_1)); - _7 = _8 as *const T (Transmute); - StorageDead(_8); - goto -> bb3; + _6 = &mut _5; + StorageLive(_7); + _7 = &mut (_5.0: std::slice::Iter<'_, T>); + _8 = as DoubleEndedIterator>::next_back(move _7) -> [return: bb3, unwind unreachable]; } bb3: { - StorageDead(_5); - StorageLive(_11); - StorageLive(_9); - _9 = _4 as *mut T (PtrToPtr); - StorageLive(_10); - StorageLive(_24); - StorageLive(_25); - _10 = _9 as *const T (PointerCoercion(MutToConstPointer)); - _11 = NonNull:: { pointer: _10 }; - StorageDead(_25); - StorageDead(_24); - StorageDead(_10); - StorageDead(_9); - StorageLive(_12); - _12 = _7; - _13 = std::slice::Iter::<'_, T> { ptr: move _11, end_or_len: move _12, _marker: const ZeroSized: PhantomData<&T> }; - StorageDead(_12); - StorageDead(_11); StorageDead(_7); - StorageDead(_4); - _14 = Rev::> { iter: _13 }; - StorageDead(_13); - StorageLive(_15); - _15 = _14; - goto -> bb4; + _9 = discriminant(_8); + switchInt(move _9) -> [0: bb4, 1: bb6, otherwise: bb8]; } bb4: { - StorageLive(_18); - _16 = &mut _15; - StorageLive(_17); - _17 = &mut (_15.0: std::slice::Iter<'_, T>); - _18 = as DoubleEndedIterator>::next_back(move _17) -> [return: bb5, unwind unreachable]; + StorageDead(_8); + StorageDead(_5); + drop(_2) -> [return: bb5, unwind unreachable]; } bb5: { - StorageDead(_17); - _19 = discriminant(_18); - switchInt(move _19) -> [0: bb6, 1: bb8, otherwise: bb10]; + return; } bb6: { - StorageDead(_18); - StorageDead(_15); - drop(_2) -> [return: bb7, unwind unreachable]; + _10 = ((_8 as Some).0: &T); + StorageLive(_11); + _11 = &_2; + StorageLive(_12); + _12 = (_10,); + _13 = >::call(move _11, move _12) -> [return: bb7, unwind unreachable]; } bb7: { - return; + StorageDead(_12); + StorageDead(_11); + StorageDead(_8); + goto -> bb2; } bb8: { - _20 = ((_18 as Some).0: &T); - StorageLive(_21); - _21 = &_2; - StorageLive(_22); - _22 = (_20,); - _23 = >::call(move _21, move _22) -> [return: bb9, unwind unreachable]; - } - - bb9: { - StorageDead(_22); - StorageDead(_21); - StorageDead(_18); - goto -> bb4; - } - - bb10: { unreachable; } } diff --git a/tests/mir-opt/pre-codegen/slice_iter.reverse_loop.PreCodegen.after.panic-unwind.mir b/tests/mir-opt/pre-codegen/slice_iter.reverse_loop.PreCodegen.after.panic-unwind.mir index 65f423ac326be..2d250a6cd2265 100644 --- a/tests/mir-opt/pre-codegen/slice_iter.reverse_loop.PreCodegen.after.panic-unwind.mir +++ b/tests/mir-opt/pre-codegen/slice_iter.reverse_loop.PreCodegen.after.panic-unwind.mir @@ -4,206 +4,101 @@ fn reverse_loop(_1: &[T], _2: impl Fn(&T)) -> () { debug slice => _1; debug f => _2; let mut _0: (); - let mut _13: std::slice::Iter<'_, T>; - let mut _14: std::iter::Rev>; - let mut _15: std::iter::Rev>; - let mut _16: &mut std::iter::Rev>; - let mut _18: std::option::Option<&T>; - let mut _19: isize; - let mut _21: &impl Fn(&T); - let mut _22: (&T,); - let _23: (); + let mut _3: std::slice::Iter<'_, T>; + let mut _4: std::iter::Rev>; + let mut _5: std::iter::Rev>; + let mut _6: &mut std::iter::Rev>; + let mut _8: std::option::Option<&T>; + let mut _9: isize; + let mut _11: &impl Fn(&T); + let mut _12: (&T,); + let _13: (); scope 1 { - debug iter => _15; - let _20: &T; + debug iter => _5; + let _10: &T; scope 2 { - debug x => _20; + debug x => _10; } - scope 25 (inlined > as Iterator>::next) { - debug self => _16; - let mut _17: &mut std::slice::Iter<'_, T>; + scope 7 (inlined > as Iterator>::next) { + debug self => _6; + let mut _7: &mut std::slice::Iter<'_, T>; } } scope 3 (inlined core::slice::::iter) { debug self => _1; - scope 4 (inlined std::slice::Iter::<'_, T>::new) { - debug slice => _1; - let _4: *const T; - let mut _5: bool; - let mut _6: usize; - let mut _8: usize; - let mut _9: *mut T; - let mut _11: std::ptr::NonNull; - let mut _12: *const T; - scope 5 { - debug ptr => _4; - scope 6 { - let _7: *const T; - scope 7 { - debug end_or_len => _7; - scope 13 (inlined NonNull::::new_unchecked) { - debug ptr => _9; - let mut _10: *const T; - let mut _24: *mut T; - scope 14 { - scope 15 (inlined NonNull::::new_unchecked::runtime::) { - debug ptr => _24; - scope 16 (inlined std::ptr::mut_ptr::::is_null) { - debug self => _24; - let mut _25: *mut u8; - scope 17 { - scope 18 (inlined std::ptr::mut_ptr::::is_null::runtime_impl) { - debug ptr => _25; - scope 19 (inlined std::ptr::mut_ptr::::addr) { - debug self => _25; - scope 20 { - scope 21 (inlined std::ptr::mut_ptr::::cast::<()>) { - debug self => _25; - } - } - } - } - } - } - } - } - } - } - scope 9 (inlined invalid::) { - debug addr => _8; - scope 10 { - } - } - scope 11 (inlined std::ptr::const_ptr::::add) { - debug self => _4; - debug count => _6; - scope 12 { - } - } - } - } - scope 8 (inlined core::slice::::as_ptr) { - debug self => _1; - let mut _3: *const [T]; - } - } } - scope 22 (inlined as Iterator>::rev) { - debug self => _13; - scope 23 (inlined Rev::>::new) { - debug iter => _13; + scope 4 (inlined as Iterator>::rev) { + debug self => _3; + scope 5 (inlined Rev::>::new) { + debug iter => _3; } } - scope 24 (inlined > as IntoIterator>::into_iter) { - debug self => _14; + scope 6 (inlined > as IntoIterator>::into_iter) { + debug self => _4; } bb0: { - StorageLive(_13); - StorageLive(_4); StorageLive(_3); - _3 = &raw const (*_1); - _4 = move _3 as *const T (PtrToPtr); - StorageDead(_3); - StorageLive(_7); - StorageLive(_5); - _5 = const _; - switchInt(move _5) -> [0: bb1, otherwise: bb2]; + _3 = std::slice::Iter::<'_, T>::new(move _1) -> [return: bb1, unwind: bb9]; } bb1: { - StorageLive(_6); - _6 = Len((*_1)); - _7 = Offset(_4, _6); - StorageDead(_6); - goto -> bb3; + _4 = Rev::> { iter: _3 }; + StorageDead(_3); + StorageLive(_5); + _5 = _4; + goto -> bb2; } bb2: { StorageLive(_8); - _8 = Len((*_1)); - _7 = _8 as *const T (Transmute); - StorageDead(_8); - goto -> bb3; + _6 = &mut _5; + StorageLive(_7); + _7 = &mut (_5.0: std::slice::Iter<'_, T>); + _8 = as DoubleEndedIterator>::next_back(move _7) -> [return: bb3, unwind: bb9]; } bb3: { - StorageDead(_5); - StorageLive(_11); - StorageLive(_9); - _9 = _4 as *mut T (PtrToPtr); - StorageLive(_10); - StorageLive(_24); - StorageLive(_25); - _10 = _9 as *const T (PointerCoercion(MutToConstPointer)); - _11 = NonNull:: { pointer: _10 }; - StorageDead(_25); - StorageDead(_24); - StorageDead(_10); - StorageDead(_9); - StorageLive(_12); - _12 = _7; - _13 = std::slice::Iter::<'_, T> { ptr: move _11, end_or_len: move _12, _marker: const ZeroSized: PhantomData<&T> }; - StorageDead(_12); - StorageDead(_11); StorageDead(_7); - StorageDead(_4); - _14 = Rev::> { iter: _13 }; - StorageDead(_13); - StorageLive(_15); - _15 = _14; - goto -> bb4; + _9 = discriminant(_8); + switchInt(move _9) -> [0: bb4, 1: bb6, otherwise: bb8]; } bb4: { - StorageLive(_18); - _16 = &mut _15; - StorageLive(_17); - _17 = &mut (_15.0: std::slice::Iter<'_, T>); - _18 = as DoubleEndedIterator>::next_back(move _17) -> [return: bb5, unwind: bb11]; + StorageDead(_8); + StorageDead(_5); + drop(_2) -> [return: bb5, unwind continue]; } bb5: { - StorageDead(_17); - _19 = discriminant(_18); - switchInt(move _19) -> [0: bb6, 1: bb8, otherwise: bb10]; + return; } bb6: { - StorageDead(_18); - StorageDead(_15); - drop(_2) -> [return: bb7, unwind continue]; + _10 = ((_8 as Some).0: &T); + StorageLive(_11); + _11 = &_2; + StorageLive(_12); + _12 = (_10,); + _13 = >::call(move _11, move _12) -> [return: bb7, unwind: bb9]; } bb7: { - return; + StorageDead(_12); + StorageDead(_11); + StorageDead(_8); + goto -> bb2; } bb8: { - _20 = ((_18 as Some).0: &T); - StorageLive(_21); - _21 = &_2; - StorageLive(_22); - _22 = (_20,); - _23 = >::call(move _21, move _22) -> [return: bb9, unwind: bb11]; - } - - bb9: { - StorageDead(_22); - StorageDead(_21); - StorageDead(_18); - goto -> bb4; - } - - bb10: { unreachable; } - bb11 (cleanup): { - drop(_2) -> [return: bb12, unwind terminate(cleanup)]; + bb9 (cleanup): { + drop(_2) -> [return: bb10, unwind terminate(cleanup)]; } - bb12 (cleanup): { + bb10 (cleanup): { resume; } }