diff --git a/compiler/rustc_mir_transform/src/cost_checker.rs b/compiler/rustc_mir_transform/src/cost_checker.rs index 79bed960b950f..5a1a42e64cc8c 100644 --- a/compiler/rustc_mir_transform/src/cost_checker.rs +++ b/compiler/rustc_mir_transform/src/cost_checker.rs @@ -2,7 +2,7 @@ use rustc_middle::mir::visit::*; use rustc_middle::mir::*; use rustc_middle::ty::{self, ParamEnv, Ty, TyCtxt}; -const INSTR_COST: usize = 5; +const INSTR_COST: usize = 1; const CALL_PENALTY: usize = 25; const LANDINGPAD_PENALTY: usize = 50; const RESUME_PENALTY: usize = 45; diff --git a/library/core/src/ptr/non_null.rs b/library/core/src/ptr/non_null.rs index 427a9f3f49456..d523850b2819b 100644 --- a/library/core/src/ptr/non_null.rs +++ b/library/core/src/ptr/non_null.rs @@ -341,10 +341,13 @@ impl NonNull { /// ``` #[stable(feature = "nonnull", since = "1.25.0")] #[rustc_const_stable(feature = "const_nonnull_as_ptr", since = "1.32.0")] + #[rustc_allow_const_fn_unstable(const_ptr_is_null)] #[rustc_never_returns_null_ptr] #[must_use] #[inline(always)] pub const fn as_ptr(self) -> *mut T { + // SAFETY: By definition of this type. + unsafe { crate::intrinsics::assume(!self.pointer.is_null()) }; self.pointer as *mut T } diff --git a/tests/mir-opt/inline/inline_shims.drop.Inline.panic-abort.diff b/tests/mir-opt/inline/inline_shims.drop.Inline.panic-abort.diff index 4fcd49994f0d7..59c2d9c5f3415 100644 --- a/tests/mir-opt/inline/inline_shims.drop.Inline.panic-abort.diff +++ b/tests/mir-opt/inline/inline_shims.drop.Inline.panic-abort.diff @@ -12,12 +12,82 @@ + scope 3 (inlined std::ptr::drop_in_place::> - shim(Some(Vec))) { + let mut _6: &mut std::vec::Vec; + let mut _7: (); ++ scope 4 (inlined as Drop>::drop) { ++ debug self => _6; ++ let mut _8: *mut [A]; ++ let mut _9: *mut A; ++ let mut _10: usize; ++ scope 5 { ++ scope 6 (inlined Vec::::as_mut_ptr) { ++ debug self => _6; ++ let mut _11: &alloc::raw_vec::RawVec; ++ scope 7 (inlined alloc::raw_vec::RawVec::::ptr) { ++ debug self => _11; ++ let mut _18: std::ptr::NonNull; ++ scope 8 (inlined Unique::::as_ptr) { ++ debug ((self: Unique).0: std::ptr::NonNull) => _18; ++ debug ((self: Unique).1: std::marker::PhantomData) => const ZeroSized: PhantomData; ++ scope 9 (inlined NonNull::::as_ptr) { ++ debug self => _18; ++ let mut _12: bool; ++ let mut _13: bool; ++ let mut _14: *const A; ++ scope 10 { ++ scope 11 (inlined std::ptr::const_ptr::::is_null) { ++ debug self => _14; ++ let mut _15: *const u8; ++ scope 12 { ++ scope 13 (inlined std::ptr::const_ptr::::is_null::runtime_impl) { ++ debug ptr => _15; ++ let mut _16: usize; ++ scope 14 (inlined std::ptr::const_ptr::::addr) { ++ debug self => _15; ++ let mut _17: *const (); ++ scope 15 { ++ scope 16 (inlined std::ptr::const_ptr::::cast::<()>) { ++ debug self => _15; ++ } ++ } ++ } ++ } ++ } ++ } ++ } ++ } ++ } ++ } ++ } ++ scope 17 (inlined slice_from_raw_parts_mut::) { ++ debug data => _9; ++ debug len => _10; ++ let mut _19: *mut (); ++ scope 18 (inlined std::ptr::mut_ptr::::cast::<()>) { ++ debug self => _9; ++ } ++ scope 19 (inlined std::ptr::from_raw_parts_mut::<[A]>) { ++ debug data_address => _19; ++ debug metadata => _10; ++ let mut _20: std::ptr::metadata::PtrRepr<[A]>; ++ let mut _21: std::ptr::metadata::PtrComponents<[A]>; ++ let mut _22: *const (); ++ scope 20 { ++ } ++ } ++ } ++ scope 21 (inlined std::ptr::drop_in_place::<[A]> - shim(Some([A]))) { ++ let mut _23: usize; ++ let mut _24: usize; ++ let mut _25: *mut A; ++ let mut _26: bool; ++ } ++ } ++ } + } } scope 2 { -+ scope 4 (inlined std::ptr::drop_in_place::> - shim(Some(Option))) { -+ let mut _8: isize; -+ let mut _9: isize; ++ scope 22 (inlined std::ptr::drop_in_place::> - shim(Some(Option))) { ++ let mut _27: isize; ++ let mut _28: isize; + } } @@ -29,7 +99,58 @@ + StorageLive(_6); + StorageLive(_7); + _6 = &mut (*_4); -+ _7 = as Drop>::drop(move _6) -> [return: bb2, unwind unreachable]; ++ StorageLive(_8); ++ StorageLive(_25); ++ StorageLive(_9); ++ StorageLive(_11); ++ _11 = &((*_6).0: alloc::raw_vec::RawVec); ++ StorageLive(_18); ++ _18 = ((((*_6).0: alloc::raw_vec::RawVec).0: std::ptr::Unique).0: std::ptr::NonNull); ++ StorageLive(_14); ++ StorageLive(_12); ++ StorageLive(_13); ++ _14 = (_18.0: *const A); ++ StorageLive(_15); ++ _15 = _14 as *const u8 (PtrToPtr); ++ StorageLive(_16); ++ StorageLive(_17); ++ _17 = _15 as *const () (PtrToPtr); ++ _16 = move _17 as usize (Transmute); ++ StorageDead(_17); ++ _13 = Eq(move _16, const 0_usize); ++ StorageDead(_16); ++ StorageDead(_15); ++ _12 = Not(move _13); ++ StorageDead(_13); ++ assume(move _12); ++ StorageDead(_12); ++ _9 = _14 as *mut A (PtrToPtr); ++ StorageDead(_14); ++ StorageDead(_18); ++ StorageDead(_11); ++ StorageLive(_10); ++ _10 = ((*_6).1: usize); ++ StorageLive(_19); ++ _19 = _9 as *mut () (PtrToPtr); ++ StorageLive(_20); ++ StorageLive(_21); ++ StorageLive(_22); ++ _22 = _19 as *const () (PointerCoercion(MutToConstPointer)); ++ _21 = std::ptr::metadata::PtrComponents::<[A]> { data_address: move _22, metadata: _10 }; ++ StorageDead(_22); ++ _20 = std::ptr::metadata::PtrRepr::<[A]> { const_ptr: move _21 }; ++ StorageDead(_21); ++ _8 = (_20.1: *mut [A]); ++ StorageDead(_20); ++ StorageDead(_19); ++ StorageDead(_10); ++ StorageDead(_9); ++ StorageLive(_23); ++ StorageLive(_24); ++ StorageLive(_26); ++ _23 = Len((*_8)); ++ _24 = const 0_usize; ++ goto -> bb4; } bb1: { @@ -40,25 +161,41 @@ StorageLive(_5); _5 = _2; - _0 = std::ptr::drop_in_place::>(move _5) -> [return: bb2, unwind unreachable]; -+ StorageLive(_8); -+ StorageLive(_9); -+ _8 = discriminant((*_5)); -+ switchInt(move _8) -> [0: bb3, otherwise: bb4]; ++ StorageLive(_27); ++ StorageLive(_28); ++ _27 = discriminant((*_5)); ++ switchInt(move _27) -> [0: bb5, otherwise: bb6]; } bb2: { ++ StorageDead(_26); ++ StorageDead(_24); ++ StorageDead(_23); ++ StorageDead(_25); ++ StorageDead(_8); + drop(((*_4).0: alloc::raw_vec::RawVec)) -> [return: bb1, unwind unreachable]; + } + + bb3: { -+ StorageDead(_9); -+ StorageDead(_8); ++ _25 = &raw mut (*_8)[_24]; ++ _24 = Add(move _24, const 1_usize); ++ drop((*_25)) -> [return: bb4, unwind unreachable]; ++ } ++ ++ bb4: { ++ _26 = Eq(_24, _23); ++ switchInt(move _26) -> [0: bb3, otherwise: bb2]; ++ } ++ ++ bb5: { ++ StorageDead(_28); ++ StorageDead(_27); StorageDead(_5); return; + } + -+ bb4: { -+ drop((((*_5) as Some).0: B)) -> [return: bb3, unwind unreachable]; ++ bb6: { ++ drop((((*_5) as Some).0: B)) -> [return: bb5, unwind unreachable]; } } diff --git a/tests/mir-opt/pre-codegen/checked_ops.step_forward.PreCodegen.after.mir b/tests/mir-opt/pre-codegen/checked_ops.step_forward.PreCodegen.after.mir index cf7feef00514a..9c5a6864d2afc 100644 --- a/tests/mir-opt/pre-codegen/checked_ops.step_forward.PreCodegen.after.mir +++ b/tests/mir-opt/pre-codegen/checked_ops.step_forward.PreCodegen.after.mir @@ -7,63 +7,180 @@ fn step_forward(_1: u32, _2: usize) -> u32 { scope 1 (inlined ::forward) { debug start => _1; debug n => _2; - let _3: std::option::Option; - let mut _4: &std::option::Option; - let mut _7: bool; - let mut _8: u32; + let _12: std::option::Option; + let mut _13: &std::option::Option; + let mut _16: bool; + let mut _17: u32; scope 2 { } - scope 3 (inlined Option::::is_none) { - debug self => _4; - let mut _6: bool; - scope 4 (inlined Option::::is_some) { - debug self => _4; - let mut _5: isize; + scope 3 (inlined ::forward_checked) { + debug start => _1; + debug n => _2; + let mut _5: std::result::Result; + let mut _6: isize; + let _7: u32; + scope 4 { + debug n => _7; + scope 6 (inlined core::num::::checked_add) { + debug self => _1; + debug rhs => _7; + let mut _11: bool; + scope 7 { + debug a => _9; + debug b => _10; + } + scope 8 (inlined core::num::::overflowing_add) { + debug self => _1; + debug rhs => _7; + let mut _8: (u32, bool); + let _9: u32; + let _10: bool; + scope 9 { + debug a => _9; + debug b => _10; + } + } + } + } + scope 5 (inlined convert::num::ptr_try_from_impls:: for u32>::try_from) { + debug u => _2; + let mut _3: bool; + let mut _4: u32; + } + } + scope 10 (inlined Option::::is_none) { + debug self => _13; + let mut _15: bool; + scope 11 (inlined Option::::is_some) { + debug self => _13; + let mut _14: isize; } } - scope 5 (inlined core::num::::wrapping_add) { + scope 12 (inlined core::num::::wrapping_add) { debug self => _1; - debug rhs => _8; + debug rhs => _17; } } bb0: { + StorageLive(_16); + StorageLive(_13); + StorageLive(_12); + StorageLive(_6); StorageLive(_7); - StorageLive(_4); + StorageLive(_5); StorageLive(_3); - _3 = ::forward_checked(_1, _2) -> [return: bb1, unwind continue]; + _3 = Gt(_2, const 4294967295_usize); + switchInt(move _3) -> [0: bb1, otherwise: bb2]; } bb1: { - _4 = &_3; - StorageLive(_6); - StorageLive(_5); - _5 = discriminant(_3); - _6 = Eq(_5, const 1_isize); - StorageDead(_5); - _7 = Not(move _6); - StorageDead(_6); - switchInt(move _7) -> [0: bb2, otherwise: bb3]; + StorageLive(_4); + _4 = _2 as u32 (IntToInt); + _5 = Result::::Ok(move _4); + StorageDead(_4); + goto -> bb3; } bb2: { - StorageDead(_3); - StorageDead(_4); - goto -> bb4; + _5 = const Result::::Err(TryFromIntError(())); + goto -> bb3; } bb3: { StorageDead(_3); - StorageDead(_4); - assert(!const true, "attempt to compute `{} + {}`, which would overflow", const _, const 1_u32) -> [success: bb4, unwind continue]; + _6 = discriminant(_5); + switchInt(move _6) -> [0: bb4, 1: bb9, otherwise: bb14]; } bb4: { - StorageDead(_7); + _7 = ((_5 as Ok).0: u32); + StorageLive(_9); + StorageLive(_10); StorageLive(_8); - _8 = _2 as u32 (IntToInt); - _0 = Add(_1, _8); + _8 = CheckedAdd(_1, _7); + _9 = (_8.0: u32); + _10 = (_8.1: bool); StorageDead(_8); + StorageLive(_11); + _11 = unlikely(move _10) -> [return: bb5, unwind unreachable]; + } + + bb5: { + switchInt(move _11) -> [0: bb6, otherwise: bb7]; + } + + bb6: { + _12 = Option::::Some(_9); + goto -> bb8; + } + + bb7: { + _12 = const Option::::None; + goto -> bb8; + } + + bb8: { + StorageDead(_11); + StorageDead(_10); + StorageDead(_9); + goto -> bb10; + } + + bb9: { + _12 = const Option::::None; + goto -> bb10; + } + + bb10: { + StorageDead(_5); + StorageDead(_7); + StorageDead(_6); + _13 = &_12; + StorageLive(_15); + StorageLive(_14); + _14 = discriminant(_12); + _15 = Eq(_14, const 1_isize); + StorageDead(_14); + _16 = Not(move _15); + StorageDead(_15); + switchInt(move _16) -> [0: bb11, otherwise: bb12]; + } + + bb11: { + StorageDead(_12); + StorageDead(_13); + goto -> bb13; + } + + bb12: { + StorageDead(_12); + StorageDead(_13); + assert(!const true, "attempt to compute `{} + {}`, which would overflow", const _, const 1_u32) -> [success: bb13, unwind continue]; + } + + bb13: { + StorageDead(_16); + StorageLive(_17); + _17 = _2 as u32 (IntToInt); + _0 = Add(_1, _17); + StorageDead(_17); return; } + + bb14: { + unreachable; + } +} + +ALLOC0 (size: 8, align: 4) { + 00 00 00 00 __ __ __ __ │ ....░░░░ +} + +ALLOC1 (size: 8, align: 4) { + 01 00 00 00 __ __ __ __ │ ....░░░░ +} + +ALLOC2 (size: 8, align: 4) { + 00 00 00 00 __ __ __ __ │ ....░░░░ } diff --git a/tests/mir-opt/pre-codegen/issue_117368_print_invalid_constant.main.GVN.32bit.panic-abort.diff b/tests/mir-opt/pre-codegen/issue_117368_print_invalid_constant.main.GVN.32bit.panic-abort.diff index 47e0d402347d3..e23ab5f2930bc 100644 --- a/tests/mir-opt/pre-codegen/issue_117368_print_invalid_constant.main.GVN.32bit.panic-abort.diff +++ b/tests/mir-opt/pre-codegen/issue_117368_print_invalid_constant.main.GVN.32bit.panic-abort.diff @@ -38,7 +38,30 @@ } scope 9 (inlined NonNull::<[u8]>::as_ptr) { debug self => _5; - let mut _18: *const [u8]; + let mut _18: bool; + let mut _19: bool; + let mut _20: *const [u8]; + scope 10 { + scope 11 (inlined std::ptr::const_ptr::::is_null) { + debug self => _20; + let mut _21: *const u8; + scope 12 { + scope 13 (inlined std::ptr::const_ptr::::is_null::runtime_impl) { + debug ptr => _21; + let mut _22: usize; + scope 14 (inlined std::ptr::const_ptr::::addr) { + debug self => _21; + let mut _23: *const (); + scope 15 { + scope 16 (inlined std::ptr::const_ptr::::cast::<()>) { + debug self => _21; + } + } + } + } + } + } + } } } scope 3 (inlined #[track_caller] Option::::unwrap) { @@ -101,10 +124,26 @@ StorageDead(_15); StorageDead(_12); StorageDead(_6); + StorageLive(_20); StorageLive(_18); - _18 = (_5.0: *const [u8]); - _4 = move _18 as *mut [u8] (PtrToPtr); + StorageLive(_19); + _20 = (_5.0: *const [u8]); + StorageLive(_21); + _21 = _20 as *const u8 (PtrToPtr); + StorageLive(_22); + StorageLive(_23); + _23 = _21 as *const () (PtrToPtr); + _22 = move _23 as usize (Transmute); + StorageDead(_23); + _19 = Eq(move _22, const 0_usize); + StorageDead(_22); + StorageDead(_21); + _18 = Not(move _19); + StorageDead(_19); + assume(move _18); StorageDead(_18); + _4 = _20 as *mut [u8] (PtrToPtr); + StorageDead(_20); StorageDead(_5); _3 = move _4 as *mut u8 (PtrToPtr); StorageDead(_4); diff --git a/tests/mir-opt/pre-codegen/issue_117368_print_invalid_constant.main.GVN.32bit.panic-unwind.diff b/tests/mir-opt/pre-codegen/issue_117368_print_invalid_constant.main.GVN.32bit.panic-unwind.diff index dee57ce6c27bb..fb3fda8f906f8 100644 --- a/tests/mir-opt/pre-codegen/issue_117368_print_invalid_constant.main.GVN.32bit.panic-unwind.diff +++ b/tests/mir-opt/pre-codegen/issue_117368_print_invalid_constant.main.GVN.32bit.panic-unwind.diff @@ -23,7 +23,30 @@ } scope 6 (inlined NonNull::<[u8]>::as_ptr) { debug self => _5; - let mut _12: *const [u8]; + let mut _12: bool; + let mut _13: bool; + let mut _14: *const [u8]; + scope 7 { + scope 8 (inlined std::ptr::const_ptr::::is_null) { + debug self => _14; + let mut _15: *const u8; + scope 9 { + scope 10 (inlined std::ptr::const_ptr::::is_null::runtime_impl) { + debug ptr => _15; + let mut _16: usize; + scope 11 (inlined std::ptr::const_ptr::::addr) { + debug self => _15; + let mut _17: *const (); + scope 12 { + scope 13 (inlined std::ptr::const_ptr::::cast::<()>) { + debug self => _15; + } + } + } + } + } + } + } } } scope 3 (inlined #[track_caller] Option::::unwrap) { @@ -48,10 +71,26 @@ bb1: { StorageDead(_6); + StorageLive(_14); StorageLive(_12); - _12 = (_5.0: *const [u8]); - _4 = move _12 as *mut [u8] (PtrToPtr); + StorageLive(_13); + _14 = (_5.0: *const [u8]); + StorageLive(_15); + _15 = _14 as *const u8 (PtrToPtr); + StorageLive(_16); + StorageLive(_17); + _17 = _15 as *const () (PtrToPtr); + _16 = move _17 as usize (Transmute); + StorageDead(_17); + _13 = Eq(move _16, const 0_usize); + StorageDead(_16); + StorageDead(_15); + _12 = Not(move _13); + StorageDead(_13); + assume(move _12); StorageDead(_12); + _4 = _14 as *mut [u8] (PtrToPtr); + StorageDead(_14); StorageDead(_5); _3 = move _4 as *mut u8 (PtrToPtr); StorageDead(_4); diff --git a/tests/mir-opt/pre-codegen/issue_117368_print_invalid_constant.main.GVN.64bit.panic-abort.diff b/tests/mir-opt/pre-codegen/issue_117368_print_invalid_constant.main.GVN.64bit.panic-abort.diff index a255b15920cba..2b185163ad6f0 100644 --- a/tests/mir-opt/pre-codegen/issue_117368_print_invalid_constant.main.GVN.64bit.panic-abort.diff +++ b/tests/mir-opt/pre-codegen/issue_117368_print_invalid_constant.main.GVN.64bit.panic-abort.diff @@ -38,7 +38,30 @@ } scope 9 (inlined NonNull::<[u8]>::as_ptr) { debug self => _5; - let mut _18: *const [u8]; + let mut _18: bool; + let mut _19: bool; + let mut _20: *const [u8]; + scope 10 { + scope 11 (inlined std::ptr::const_ptr::::is_null) { + debug self => _20; + let mut _21: *const u8; + scope 12 { + scope 13 (inlined std::ptr::const_ptr::::is_null::runtime_impl) { + debug ptr => _21; + let mut _22: usize; + scope 14 (inlined std::ptr::const_ptr::::addr) { + debug self => _21; + let mut _23: *const (); + scope 15 { + scope 16 (inlined std::ptr::const_ptr::::cast::<()>) { + debug self => _21; + } + } + } + } + } + } + } } } scope 3 (inlined #[track_caller] Option::::unwrap) { @@ -101,10 +124,26 @@ StorageDead(_15); StorageDead(_12); StorageDead(_6); + StorageLive(_20); StorageLive(_18); - _18 = (_5.0: *const [u8]); - _4 = move _18 as *mut [u8] (PtrToPtr); + StorageLive(_19); + _20 = (_5.0: *const [u8]); + StorageLive(_21); + _21 = _20 as *const u8 (PtrToPtr); + StorageLive(_22); + StorageLive(_23); + _23 = _21 as *const () (PtrToPtr); + _22 = move _23 as usize (Transmute); + StorageDead(_23); + _19 = Eq(move _22, const 0_usize); + StorageDead(_22); + StorageDead(_21); + _18 = Not(move _19); + StorageDead(_19); + assume(move _18); StorageDead(_18); + _4 = _20 as *mut [u8] (PtrToPtr); + StorageDead(_20); StorageDead(_5); _3 = move _4 as *mut u8 (PtrToPtr); StorageDead(_4); diff --git a/tests/mir-opt/pre-codegen/issue_117368_print_invalid_constant.main.GVN.64bit.panic-unwind.diff b/tests/mir-opt/pre-codegen/issue_117368_print_invalid_constant.main.GVN.64bit.panic-unwind.diff index 192ffea259157..88c6af9f89b7a 100644 --- a/tests/mir-opt/pre-codegen/issue_117368_print_invalid_constant.main.GVN.64bit.panic-unwind.diff +++ b/tests/mir-opt/pre-codegen/issue_117368_print_invalid_constant.main.GVN.64bit.panic-unwind.diff @@ -23,7 +23,30 @@ } scope 6 (inlined NonNull::<[u8]>::as_ptr) { debug self => _5; - let mut _12: *const [u8]; + let mut _12: bool; + let mut _13: bool; + let mut _14: *const [u8]; + scope 7 { + scope 8 (inlined std::ptr::const_ptr::::is_null) { + debug self => _14; + let mut _15: *const u8; + scope 9 { + scope 10 (inlined std::ptr::const_ptr::::is_null::runtime_impl) { + debug ptr => _15; + let mut _16: usize; + scope 11 (inlined std::ptr::const_ptr::::addr) { + debug self => _15; + let mut _17: *const (); + scope 12 { + scope 13 (inlined std::ptr::const_ptr::::cast::<()>) { + debug self => _15; + } + } + } + } + } + } + } } } scope 3 (inlined #[track_caller] Option::::unwrap) { @@ -48,10 +71,26 @@ bb1: { StorageDead(_6); + StorageLive(_14); StorageLive(_12); - _12 = (_5.0: *const [u8]); - _4 = move _12 as *mut [u8] (PtrToPtr); + StorageLive(_13); + _14 = (_5.0: *const [u8]); + StorageLive(_15); + _15 = _14 as *const u8 (PtrToPtr); + StorageLive(_16); + StorageLive(_17); + _17 = _15 as *const () (PtrToPtr); + _16 = move _17 as usize (Transmute); + StorageDead(_17); + _13 = Eq(move _16, const 0_usize); + StorageDead(_16); + StorageDead(_15); + _12 = Not(move _13); + StorageDead(_13); + assume(move _12); StorageDead(_12); + _4 = _14 as *mut [u8] (PtrToPtr); + StorageDead(_14); StorageDead(_5); _3 = move _4 as *mut u8 (PtrToPtr); StorageDead(_4); diff --git a/tests/mir-opt/pre-codegen/loops.mapped.PreCodegen.after.mir b/tests/mir-opt/pre-codegen/loops.mapped.PreCodegen.after.mir index 30bdc13109089..11a1b3e66f6c2 100644 --- a/tests/mir-opt/pre-codegen/loops.mapped.PreCodegen.after.mir +++ b/tests/mir-opt/pre-codegen/loops.mapped.PreCodegen.after.mir @@ -7,14 +7,31 @@ fn mapped(_1: impl Iterator, _2: impl Fn(T) -> U) -> () { let mut _3: std::iter::Map, impl Fn(T) -> U>; let mut _4: std::iter::Map, impl Fn(T) -> U>; let mut _5: &mut std::iter::Map, impl Fn(T) -> U>; - let mut _6: std::option::Option; - let mut _7: isize; - let _9: (); + let mut _10: std::option::Option; + let mut _14: isize; + let _16: (); scope 1 { debug iter => _4; - let _8: U; + let _15: U; scope 2 { - debug x => _8; + debug x => _15; + } + scope 4 (inlined , impl Fn(T) -> U> as Iterator>::next) { + debug self => _5; + let mut _6: &mut impl Iterator; + let mut _7: std::option::Option; + let mut _8: &mut impl Fn(T) -> U; + scope 5 (inlined Option::::map:: U>) { + debug self => _7; + debug f => _8; + let mut _9: isize; + let _11: T; + let mut _12: (T,); + let mut _13: U; + scope 6 { + debug x => _11; + } + } } } scope 3 (inlined , impl Fn(T) -> U> as IntoIterator>::into_iter) { @@ -32,47 +49,82 @@ fn mapped(_1: impl Iterator, _2: impl Fn(T) -> U) -> () { } bb2: { - StorageLive(_6); - StorageLive(_5); + StorageLive(_10); _5 = &mut _4; - _6 = , impl Fn(T) -> U> as Iterator>::next(move _5) -> [return: bb3, unwind: bb9]; + StorageLive(_8); + StorageLive(_7); + StorageLive(_6); + _6 = &mut (_4.0: impl Iterator); + _7 = as Iterator>::next(move _6) -> [return: bb3, unwind: bb13]; } bb3: { - StorageDead(_5); - _7 = discriminant(_6); - switchInt(move _7) -> [0: bb4, 1: bb6, otherwise: bb8]; + StorageDead(_6); + _8 = &mut (_4.1: impl Fn(T) -> U); + StorageLive(_9); + StorageLive(_11); + _9 = discriminant(_7); + switchInt(move _9) -> [0: bb4, 1: bb5, otherwise: bb12]; } bb4: { - StorageDead(_6); - drop(_4) -> [return: bb5, unwind continue]; + _10 = Option::::None; + goto -> bb7; } bb5: { - StorageDead(_4); - return; + _11 = move ((_7 as Some).0: T); + StorageLive(_13); + StorageLive(_12); + _12 = (move _11,); + _13 = <&mut impl Fn(T) -> U as FnOnce<(T,)>>::call_once(move _8, move _12) -> [return: bb6, unwind: bb13]; } bb6: { - _8 = move ((_6 as Some).0: U); - _9 = opaque::(move _8) -> [return: bb7, unwind: bb9]; + StorageDead(_12); + _10 = Option::::Some(move _13); + StorageDead(_13); + goto -> bb7; } bb7: { - StorageDead(_6); - goto -> bb2; + StorageDead(_11); + StorageDead(_9); + StorageDead(_7); + StorageDead(_8); + _14 = discriminant(_10); + switchInt(move _14) -> [0: bb8, 1: bb10, otherwise: bb12]; } bb8: { + StorageDead(_10); + drop(_4) -> [return: bb9, unwind continue]; + } + + bb9: { + StorageDead(_4); + return; + } + + bb10: { + _15 = move ((_10 as Some).0: U); + _16 = opaque::(move _15) -> [return: bb11, unwind: bb13]; + } + + bb11: { + StorageDead(_10); + goto -> bb2; + } + + bb12: { unreachable; } - bb9 (cleanup): { - drop(_4) -> [return: bb10, unwind terminate(cleanup)]; + bb13 (cleanup): { + drop(_4) -> [return: bb14, unwind terminate(cleanup)]; } - bb10 (cleanup): { + bb14 (cleanup): { resume; } } diff --git a/tests/mir-opt/pre-codegen/loops.vec_move.PreCodegen.after.mir b/tests/mir-opt/pre-codegen/loops.vec_move.PreCodegen.after.mir index cb29473d7627f..3d7c07d268e23 100644 --- a/tests/mir-opt/pre-codegen/loops.vec_move.PreCodegen.after.mir +++ b/tests/mir-opt/pre-codegen/loops.vec_move.PreCodegen.after.mir @@ -3,74 +3,760 @@ fn vec_move(_1: Vec) -> () { debug v => _1; let mut _0: (); - let mut _2: std::vec::IntoIter; - let mut _3: std::vec::IntoIter; - let mut _4: &mut std::vec::IntoIter; - let mut _5: std::option::Option; - let mut _6: isize; - let _8: (); + let mut _47: std::vec::IntoIter; + let mut _48: std::vec::IntoIter; + let mut _49: &mut std::vec::IntoIter; + let mut _58: std::option::Option; + let mut _76: isize; + let _78: (); scope 1 { - debug iter => _3; - let _7: impl Sized; + debug iter => _48; + let _77: impl Sized; scope 2 { - debug x => _7; + debug x => _77; + } + scope 66 (inlined as Iterator>::next) { + debug self => _49; + let mut _50: *const impl Sized; + let mut _51: *const impl Sized; + let mut _52: bool; + let mut _53: bool; + let _54: *const impl Sized; + let mut _55: *const impl Sized; + let mut _56: *const impl Sized; + let mut _57: impl Sized; + let mut _59: *const impl Sized; + let mut _65: *const impl Sized; + let mut _75: impl Sized; + scope 67 { + scope 83 (inlined #[track_caller] zeroed::) { + let _66: (); + let mut _72: std::mem::MaybeUninit; + scope 84 { + scope 85 (inlined MaybeUninit::::zeroed) { + let mut _67: std::mem::MaybeUninit; + let mut _68: &mut std::mem::MaybeUninit; + let mut _70: *mut impl Sized; + let _71: (); + scope 86 { + debug u => _67; + scope 87 { + scope 89 (inlined MaybeUninit::::as_mut_ptr) { + debug self => _68; + let mut _69: *mut std::mem::MaybeUninit; + } + scope 90 (inlined std::ptr::mut_ptr::::write_bytes) { + debug self => _70; + debug val => const 0_u8; + debug count => const 1_usize; + scope 91 { + scope 92 (inlined write_bytes::) { + debug dst => _70; + debug val => const 0_u8; + debug count => const 1_usize; + scope 93 { + scope 94 (inlined write_bytes::runtime::) { + debug dst => _70; + let mut _81: *const impl Sized; + scope 95 (inlined intrinsics::is_aligned_and_not_null::) { + debug ptr => _81; + scope 96 (inlined std::ptr::const_ptr::::is_null) { + debug self => _81; + let mut _82: *const u8; + scope 97 { + scope 98 (inlined std::ptr::const_ptr::::is_null::runtime_impl) { + debug ptr => _82; + scope 99 (inlined std::ptr::const_ptr::::addr) { + debug self => _82; + scope 100 { + scope 101 (inlined std::ptr::const_ptr::::cast::<()>) { + debug self => _82; + } + } + } + } + } + } + scope 102 (inlined std::ptr::const_ptr::::is_aligned) { + debug self => _81; + scope 103 (inlined align_of::) { + } + } + } + } + } + } + } + } + } + } + scope 88 (inlined MaybeUninit::::uninit) { + } + } + scope 104 (inlined #[track_caller] MaybeUninit::::assume_init) { + debug self => _72; + let _73: (); + let mut _74: std::mem::ManuallyDrop; + scope 105 { + scope 106 (inlined ManuallyDrop::::into_inner) { + debug slot => _74; + } + } + } + } + } + } + scope 68 { + debug old => _54; + scope 69 { + scope 107 (inlined std::ptr::const_ptr::::add) { + debug self => _55; + debug count => const 1_usize; + scope 108 { + } + } + } + scope 70 { + scope 109 (inlined std::ptr::read::) { + debug src => _54; + scope 110 { + scope 111 (inlined std::ptr::read::runtime::) { + debug src => _54; + scope 112 (inlined intrinsics::is_aligned_and_not_null::) { + debug ptr => _54; + scope 113 (inlined std::ptr::const_ptr::::is_null) { + debug self => _54; + let mut _83: *const u8; + scope 114 { + scope 115 (inlined std::ptr::const_ptr::::is_null::runtime_impl) { + debug ptr => _83; + scope 116 (inlined std::ptr::const_ptr::::addr) { + debug self => _83; + scope 117 { + scope 118 (inlined std::ptr::const_ptr::::cast::<()>) { + debug self => _83; + } + } + } + } + } + } + scope 119 (inlined std::ptr::const_ptr::::is_aligned) { + debug self => _54; + scope 120 (inlined align_of::) { + } + } + } + } + } + } + } + } + scope 71 (inlined std::ptr::const_ptr::::wrapping_byte_sub) { + debug self => _59; + debug count => const 1_usize; + let mut _60: *const u8; + let mut _61: *const u8; + scope 72 (inlined std::ptr::const_ptr::::cast::) { + debug self => _59; + } + scope 73 (inlined std::ptr::const_ptr::::wrapping_sub) { + debug self => _60; + debug count => const 1_usize; + scope 74 (inlined core::num::::wrapping_neg) { + debug self => const 1_isize; + scope 75 (inlined core::num::::wrapping_sub) { + debug self => const 0_isize; + debug rhs => const 1_isize; + } + } + scope 76 (inlined std::ptr::const_ptr::::wrapping_offset) { + debug self => _60; + debug count => const -1_isize; + scope 77 { + } + } + } + scope 78 (inlined std::ptr::const_ptr::::with_metadata_of::) { + debug self => _61; + debug meta => _59; + let mut _62: *const (); + scope 79 (inlined std::ptr::metadata::) { + debug ptr => _59; + scope 80 { + } + } + scope 81 (inlined std::ptr::from_raw_parts::) { + debug data_address => _62; + debug metadata => const (); + let mut _63: std::ptr::metadata::PtrComponents; + let mut _64: std::ptr::metadata::PtrRepr; + scope 82 { + } + } + } + } + } + } + scope 3 (inlined as IntoIterator>::into_iter) { + debug self => _1; + let mut _3: &std::mem::ManuallyDrop>; + let mut _4: &std::vec::Vec; + let mut _6: *const std::alloc::Global; + let mut _7: &mut std::mem::ManuallyDrop>; + let mut _8: &mut std::vec::Vec; + let mut _18: bool; + let mut _19: &std::mem::ManuallyDrop>; + let mut _20: &std::vec::Vec; + let mut _21: usize; + let mut _22: *mut impl Sized; + let mut _23: *const impl Sized; + let mut _25: &std::mem::ManuallyDrop>; + let mut _26: &std::vec::Vec; + let mut _27: usize; + let mut _38: *mut impl Sized; + let mut _39: &std::mem::ManuallyDrop>; + let mut _40: &alloc::raw_vec::RawVec; + let mut _44: std::ptr::NonNull; + let mut _45: usize; + let mut _46: *const impl Sized; + scope 4 { + let mut _2: std::mem::ManuallyDrop>; + scope 5 { + debug me => _2; + scope 6 { + debug alloc => const ManuallyDrop:: {{ value: std::alloc::Global }}; + let _17: *mut impl Sized; + scope 7 { + debug begin => _17; + let _24: *const impl Sized; + scope 8 { + debug end => _24; + let _42: usize; + scope 9 { + debug cap => _42; + scope 57 (inlined NonNull::::new_unchecked) { + debug ptr => _17; + let mut _43: *const impl Sized; + scope 58 { + scope 59 (inlined NonNull::::new_unchecked::runtime::) { + debug ptr => _17; + scope 60 (inlined std::ptr::mut_ptr::::is_null) { + debug self => _17; + let mut _80: *mut u8; + scope 61 { + scope 62 (inlined std::ptr::mut_ptr::::is_null::runtime_impl) { + debug ptr => _80; + scope 63 (inlined std::ptr::mut_ptr::::addr) { + debug self => _80; + scope 64 { + scope 65 (inlined std::ptr::mut_ptr::::cast::<()>) { + debug self => _80; + } + } + } + } + } + } + } + } + } + } + scope 55 (inlined > as Deref>::deref) { + debug self => _39; + } + scope 56 (inlined alloc::raw_vec::RawVec::::capacity) { + debug self => _40; + let mut _41: bool; + } + } + scope 39 (inlined > as Deref>::deref) { + debug self => _25; + } + scope 40 (inlined Vec::::len) { + debug self => _26; + } + scope 41 (inlined std::ptr::mut_ptr::::wrapping_byte_add) { + debug self => _17; + debug count => _27; + let mut _28: *mut u8; + let mut _32: *mut u8; + let mut _33: *const impl Sized; + scope 42 (inlined std::ptr::mut_ptr::::cast::) { + debug self => _17; + } + scope 43 (inlined std::ptr::mut_ptr::::wrapping_add) { + debug self => _28; + debug count => _27; + let mut _29: isize; + scope 44 (inlined std::ptr::mut_ptr::::wrapping_offset) { + debug self => _28; + debug count => _29; + let mut _30: *const u8; + let mut _31: *const u8; + scope 45 { + } + } + } + scope 46 (inlined std::ptr::mut_ptr::::with_metadata_of::) { + debug self => _32; + debug meta => _33; + let mut _34: *mut (); + scope 47 (inlined std::ptr::metadata::) { + debug ptr => _33; + scope 48 { + } + } + scope 49 (inlined std::ptr::from_raw_parts_mut::) { + debug data_address => _34; + debug metadata => const (); + let mut _35: *const (); + let mut _36: std::ptr::metadata::PtrComponents; + let mut _37: std::ptr::metadata::PtrRepr; + scope 50 { + } + } + } + } + scope 51 (inlined > as Deref>::deref) { + debug self => _19; + } + scope 52 (inlined Vec::::len) { + debug self => _20; + } + scope 53 (inlined std::ptr::mut_ptr::::add) { + debug self => _17; + debug count => _21; + scope 54 { + } + } + } + scope 27 (inlined > as DerefMut>::deref_mut) { + debug self => _7; + } + scope 28 (inlined Vec::::as_mut_ptr) { + debug self => _8; + let mut _9: &alloc::raw_vec::RawVec; + scope 29 (inlined alloc::raw_vec::RawVec::::ptr) { + debug self => _9; + let mut _10: std::ptr::NonNull; + scope 30 (inlined Unique::::as_ptr) { + debug ((self: Unique).0: std::ptr::NonNull) => _10; + debug ((self: Unique).1: std::marker::PhantomData) => const ZeroSized: PhantomData; + scope 31 (inlined NonNull::::as_ptr) { + debug self => _10; + let mut _11: *const impl Sized; + let mut _15: bool; + let mut _16: bool; + scope 32 { + scope 33 (inlined std::ptr::const_ptr::::is_null) { + debug self => _11; + let mut _12: *const u8; + scope 34 { + scope 35 (inlined std::ptr::const_ptr::::is_null::runtime_impl) { + debug ptr => _12; + let mut _14: usize; + scope 36 (inlined std::ptr::const_ptr::::addr) { + debug self => _12; + let mut _13: *const (); + scope 37 { + scope 38 (inlined std::ptr::const_ptr::::cast::<()>) { + debug self => _12; + } + } + } + } + } + } + } + } + } + } + } + } + scope 11 (inlined > as Deref>::deref) { + debug self => _3; + } + scope 12 (inlined Vec::::allocator) { + debug self => _4; + let mut _5: &alloc::raw_vec::RawVec; + scope 13 (inlined alloc::raw_vec::RawVec::::allocator) { + debug self => _5; + } + } + scope 14 (inlined std::ptr::read::) { + debug src => _6; + scope 15 { + scope 16 (inlined std::ptr::read::runtime::) { + debug src => _6; + scope 17 (inlined intrinsics::is_aligned_and_not_null::) { + debug ptr => _6; + scope 18 (inlined std::ptr::const_ptr::::is_null) { + debug self => _6; + let mut _79: *const u8; + scope 19 { + scope 20 (inlined std::ptr::const_ptr::::is_null::runtime_impl) { + debug ptr => _79; + scope 21 (inlined std::ptr::const_ptr::::addr) { + debug self => _79; + scope 22 { + scope 23 (inlined std::ptr::const_ptr::::cast::<()>) { + debug self => _79; + } + } + } + } + } + } + scope 24 (inlined std::ptr::const_ptr::::is_aligned) { + debug self => _6; + scope 25 (inlined align_of::) { + } + } + } + } + } + } + scope 26 (inlined ManuallyDrop::::new) { + debug value => const std::alloc::Global; + } + } + scope 10 (inlined ManuallyDrop::>::new) { + debug value => _1; + } } } bb0: { + StorageLive(_47); + StorageLive(_17); + StorageLive(_8); + StorageLive(_7); + StorageLive(_43); StorageLive(_2); - _2 = as IntoIterator>::into_iter(move _1) -> [return: bb1, unwind continue]; + _2 = ManuallyDrop::> { value: move _1 }; + StorageLive(_6); + StorageLive(_4); + StorageLive(_3); + _3 = &_2; + _4 = &(_2.0: std::vec::Vec); + StorageDead(_3); + StorageLive(_5); + _5 = &((_2.0: std::vec::Vec).0: alloc::raw_vec::RawVec); + StorageDead(_5); + _6 = &raw const (((_2.0: std::vec::Vec).0: alloc::raw_vec::RawVec).2: std::alloc::Global); + StorageDead(_4); + StorageLive(_79); + StorageDead(_79); + StorageDead(_6); + _7 = &mut _2; + _8 = &mut (_2.0: std::vec::Vec); + StorageLive(_9); + _9 = &((_2.0: std::vec::Vec).0: alloc::raw_vec::RawVec); + StorageLive(_10); + _10 = ((((_2.0: std::vec::Vec).0: alloc::raw_vec::RawVec).0: std::ptr::Unique).0: std::ptr::NonNull); + StorageLive(_11); + StorageLive(_16); + StorageLive(_15); + _11 = (_10.0: *const impl Sized); + StorageLive(_12); + _12 = _11 as *const u8 (PtrToPtr); + StorageLive(_14); + StorageLive(_13); + _13 = _12 as *const () (PtrToPtr); + _14 = move _13 as usize (Transmute); + StorageDead(_13); + _15 = Eq(move _14, const 0_usize); + StorageDead(_14); + StorageDead(_12); + _16 = Not(move _15); + StorageDead(_15); + assume(move _16); + StorageDead(_16); + _17 = _11 as *mut impl Sized (PtrToPtr); + StorageDead(_11); + StorageDead(_10); + StorageDead(_9); + StorageLive(_24); + StorageLive(_18); + _18 = const _; + switchInt(move _18) -> [0: bb1, otherwise: bb2]; } bb1: { - StorageLive(_3); - _3 = move _2; - goto -> bb2; + StorageLive(_23); + StorageLive(_22); + StorageLive(_21); + StorageLive(_20); + StorageLive(_19); + _19 = &_2; + _20 = &(_2.0: std::vec::Vec); + StorageDead(_19); + _21 = ((_2.0: std::vec::Vec).1: usize); + StorageDead(_20); + _22 = Offset(_17, _21); + _23 = move _22 as *const impl Sized (PointerCoercion(MutToConstPointer)); + StorageDead(_21); + StorageDead(_22); + _24 = move _23; + StorageDead(_23); + goto -> bb4; } bb2: { - StorageLive(_5); - StorageLive(_4); - _4 = &mut _3; - _5 = as Iterator>::next(move _4) -> [return: bb3, unwind: bb9]; + StorageLive(_38); + StorageLive(_27); + StorageLive(_26); + StorageLive(_25); + _25 = &_2; + _26 = &(_2.0: std::vec::Vec); + StorageDead(_25); + _27 = ((_2.0: std::vec::Vec).1: usize); + StorageDead(_26); + StorageLive(_32); + StorageLive(_28); + _28 = _17 as *mut u8 (PtrToPtr); + StorageLive(_29); + _29 = _27 as isize (IntToInt); + StorageLive(_31); + StorageLive(_30); + _30 = _28 as *const u8 (PointerCoercion(MutToConstPointer)); + _31 = arith_offset::(move _30, move _29) -> [return: bb3, unwind unreachable]; } bb3: { - StorageDead(_4); - _6 = discriminant(_5); - switchInt(move _6) -> [0: bb4, 1: bb6, otherwise: bb8]; + StorageDead(_30); + _32 = move _31 as *mut u8 (PtrToPtr); + StorageDead(_31); + StorageDead(_29); + StorageDead(_28); + StorageLive(_33); + _33 = _17 as *const impl Sized (PointerCoercion(MutToConstPointer)); + StorageLive(_34); + _34 = _32 as *mut () (PtrToPtr); + StorageLive(_37); + StorageLive(_36); + StorageLive(_35); + _35 = _34 as *const () (PointerCoercion(MutToConstPointer)); + _36 = std::ptr::metadata::PtrComponents:: { data_address: move _35, metadata: const () }; + StorageDead(_35); + _37 = std::ptr::metadata::PtrRepr:: { const_ptr: move _36 }; + StorageDead(_36); + _38 = (_37.1: *mut impl Sized); + StorageDead(_37); + StorageDead(_34); + StorageDead(_33); + StorageDead(_32); + StorageDead(_27); + _24 = move _38 as *const impl Sized (PointerCoercion(MutToConstPointer)); + StorageDead(_38); + goto -> bb4; } bb4: { - StorageDead(_5); - drop(_3) -> [return: bb5, unwind continue]; + StorageDead(_18); + StorageLive(_42); + StorageLive(_40); + StorageLive(_39); + _39 = &_2; + StorageDead(_39); + _40 = &((_2.0: std::vec::Vec).0: alloc::raw_vec::RawVec); + StorageLive(_41); + _41 = const _; + switchInt(move _41) -> [0: bb5, otherwise: bb6]; } bb5: { - StorageDead(_3); - StorageDead(_2); - return; + _42 = ((((_2.0: std::vec::Vec).0: alloc::raw_vec::RawVec).1: alloc::raw_vec::Cap).0: usize); + goto -> bb7; } bb6: { - _7 = move ((_5 as Some).0: impl Sized); - _8 = opaque::(move _7) -> [return: bb7, unwind: bb9]; + _42 = const _; + goto -> bb7; } bb7: { - StorageDead(_5); - goto -> bb2; + StorageDead(_41); + StorageDead(_40); + StorageLive(_44); + StorageLive(_80); + _43 = _17 as *const impl Sized (PointerCoercion(MutToConstPointer)); + _44 = NonNull:: { pointer: _43 }; + StorageDead(_80); + StorageLive(_45); + _45 = _42; + StorageLive(_46); + _46 = _24; + _47 = std::vec::IntoIter:: { buf: move _44, phantom: const ZeroSized: PhantomData, cap: move _45, alloc: const ManuallyDrop:: {{ value: std::alloc::Global }}, ptr: _43, end: move _46 }; + StorageDead(_46); + StorageDead(_45); + StorageDead(_44); + StorageDead(_42); + StorageDead(_24); + StorageDead(_2); + StorageDead(_43); + StorageDead(_7); + StorageDead(_8); + StorageDead(_17); + StorageLive(_48); + _48 = move _47; + goto -> bb8; } bb8: { - unreachable; + StorageLive(_58); + _49 = &mut _48; + StorageLive(_52); + StorageLive(_50); + _50 = (_48.4: *const impl Sized); + StorageLive(_51); + _51 = (_48.5: *const impl Sized); + _52 = Eq(move _50, move _51); + switchInt(move _52) -> [0: bb9, otherwise: bb17]; + } + + bb9: { + StorageDead(_51); + StorageDead(_50); + StorageLive(_53); + _53 = const _; + switchInt(move _53) -> [0: bb10, otherwise: bb11]; + } + + bb10: { + _54 = (_48.4: *const impl Sized); + StorageLive(_56); + StorageLive(_55); + _55 = (_48.4: *const impl Sized); + _56 = Offset(_55, const 1_usize); + StorageDead(_55); + (_48.4: *const impl Sized) = move _56; + StorageDead(_56); + StorageLive(_57); + StorageLive(_83); + _57 = (*_54); + StorageDead(_83); + _58 = Option::::Some(move _57); + StorageDead(_57); + goto -> bb16; + } + + bb11: { + StorageLive(_65); + StorageLive(_59); + _59 = (_48.5: *const impl Sized); + StorageLive(_61); + StorageLive(_60); + _60 = _59 as *const u8 (PtrToPtr); + _61 = arith_offset::(move _60, const -1_isize) -> [return: bb12, unwind unreachable]; } - bb9 (cleanup): { - drop(_3) -> [return: bb10, unwind terminate(cleanup)]; + bb12: { + StorageDead(_60); + StorageLive(_62); + _62 = _61 as *const () (PtrToPtr); + StorageLive(_64); + StorageLive(_63); + _63 = std::ptr::metadata::PtrComponents:: { data_address: _62, metadata: const () }; + _64 = std::ptr::metadata::PtrRepr:: { const_ptr: move _63 }; + StorageDead(_63); + _65 = (_64.0: *const impl Sized); + StorageDead(_64); + StorageDead(_62); + StorageDead(_61); + StorageDead(_59); + (_48.5: *const impl Sized) = move _65; + StorageDead(_65); + StorageLive(_75); + _66 = assert_zero_valid::() -> [return: bb13, unwind unreachable]; } - bb10 (cleanup): { + bb13: { + StorageLive(_72); + StorageLive(_67); + _67 = MaybeUninit:: { uninit: const () }; + StorageLive(_70); + StorageLive(_68); + _68 = &mut _67; + StorageLive(_69); + _69 = &raw mut _67; + _70 = _69 as *mut impl Sized (PtrToPtr); + StorageDead(_69); + StorageDead(_68); + StorageLive(_81); + StorageLive(_82); + _71 = write_bytes::write_bytes::(move _70, const 0_u8, const 1_usize) -> [return: bb14, unwind unreachable]; + } + + bb14: { + StorageDead(_82); + StorageDead(_81); + StorageDead(_70); + _72 = move _67; + StorageDead(_67); + _73 = assert_inhabited::() -> [return: bb15, unwind unreachable]; + } + + bb15: { + StorageLive(_74); + _74 = move (_72.1: std::mem::ManuallyDrop); + _75 = move (_74.0: impl Sized); + StorageDead(_74); + StorageDead(_72); + _58 = Option::::Some(move _75); + StorageDead(_75); + goto -> bb16; + } + + bb16: { + StorageDead(_53); + goto -> bb18; + } + + bb17: { + StorageDead(_51); + StorageDead(_50); + _58 = Option::::None; + goto -> bb18; + } + + bb18: { + StorageDead(_52); + _76 = discriminant(_58); + switchInt(move _76) -> [0: bb19, 1: bb21, otherwise: bb25]; + } + + bb19: { + StorageDead(_58); + drop(_48) -> [return: bb20, unwind continue]; + } + + bb20: { + StorageDead(_48); + StorageDead(_47); + return; + } + + bb21: { + _77 = move ((_58 as Some).0: impl Sized); + _78 = opaque::(move _77) -> [return: bb22, unwind: bb23]; + } + + bb22: { + StorageDead(_58); + goto -> bb8; + } + + bb23 (cleanup): { + drop(_48) -> [return: bb24, unwind terminate(cleanup)]; + } + + bb24 (cleanup): { resume; } + + bb25: { + unreachable; + } } 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 index 713d6cc558acc..0434faafe65e2 100644 --- 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 @@ -14,6 +14,35 @@ fn mem_replace(_1: &mut u32, _2: u32) -> u32 { debug dst => _1; debug src => _2; scope 17 { + scope 18 (inlined std::ptr::write::runtime::) { + debug dst => _1; + let mut _4: *const u32; + scope 19 (inlined intrinsics::is_aligned_and_not_null::) { + debug ptr => _4; + scope 20 (inlined std::ptr::const_ptr::::is_null) { + debug self => _4; + let mut _5: *const u8; + scope 21 { + scope 22 (inlined std::ptr::const_ptr::::is_null::runtime_impl) { + debug ptr => _5; + scope 23 (inlined std::ptr::const_ptr::::addr) { + debug self => _5; + scope 24 { + scope 25 (inlined std::ptr::const_ptr::::cast::<()>) { + debug self => _5; + } + } + } + } + } + } + scope 26 (inlined std::ptr::const_ptr::::is_aligned) { + debug self => _4; + scope 27 (inlined align_of::) { + } + } + } + } } } } @@ -57,7 +86,11 @@ fn mem_replace(_1: &mut u32, _2: u32) -> u32 { StorageLive(_3); _0 = (*_1); StorageDead(_3); + StorageLive(_4); + StorageLive(_5); (*_1) = _2; + StorageDead(_5); + StorageDead(_4); return; } } diff --git a/tests/mir-opt/pre-codegen/slice_index.slice_index_range.PreCodegen.after.panic-abort.mir b/tests/mir-opt/pre-codegen/slice_index.slice_index_range.PreCodegen.after.panic-abort.mir index d97c96ac8a088..ea706cfcb8d7f 100644 --- a/tests/mir-opt/pre-codegen/slice_index.slice_index_range.PreCodegen.after.panic-abort.mir +++ b/tests/mir-opt/pre-codegen/slice_index.slice_index_range.PreCodegen.after.panic-abort.mir @@ -4,16 +4,129 @@ fn slice_index_range(_1: &[u32], _2: std::ops::Range) -> &[u32] { debug slice => _1; debug index => _2; let mut _0: &[u32]; + let mut _3: usize; + let mut _4: usize; scope 1 (inlined #[track_caller] core::slice::index::> for [u32]>::index) { debug self => _1; - debug index => _2; + debug ((index: std::ops::Range).0: usize) => _3; + debug ((index: std::ops::Range).1: usize) => _4; + scope 2 (inlined #[track_caller] as SliceIndex<[u32]>>::index) { + debug ((self: std::ops::Range).0: usize) => _3; + debug ((self: std::ops::Range).1: usize) => _4; + debug slice => _1; + let mut _5: bool; + let mut _6: usize; + let mut _7: bool; + let mut _8: *const [u32]; + let _15: *const [u32]; + let _16: !; + let _17: !; + scope 3 { + scope 4 (inlined as SliceIndex<[u32]>>::get_unchecked) { + debug ((self: std::ops::Range).0: usize) => _3; + debug ((self: std::ops::Range).1: usize) => _4; + debug slice => _1; + let mut _10: *const u32; + let mut _11: *const u32; + let mut _18: &[&str]; + scope 5 { + let _9: usize; + scope 6 { + debug new_len => _9; + scope 11 (inlined std::ptr::const_ptr::::as_ptr) { + debug self => _1; + } + scope 12 (inlined std::ptr::const_ptr::::add) { + debug self => _10; + debug count => _3; + scope 13 { + } + } + scope 14 (inlined slice_from_raw_parts::) { + debug data => _11; + debug len => _9; + let mut _12: *const (); + scope 15 (inlined std::ptr::const_ptr::::cast::<()>) { + debug self => _11; + } + scope 16 (inlined std::ptr::from_raw_parts::<[u32]>) { + debug data_address => _12; + debug metadata => _9; + let mut _13: std::ptr::metadata::PtrComponents<[u32]>; + let mut _14: std::ptr::metadata::PtrRepr<[u32]>; + scope 17 { + } + } + } + } + } + scope 7 (inlined std::ptr::const_ptr::::len) { + debug self => _1; + scope 8 (inlined std::ptr::metadata::<[u32]>) { + debug ptr => _1; + scope 9 { + } + } + } + scope 10 (inlined Arguments::<'_>::new_const) { + debug pieces => _18; + } + } + } + } } bb0: { - _0 = as SliceIndex<[u32]>>::index(move _2, move _1) -> [return: bb1, unwind unreachable]; + _3 = move (_2.0: usize); + _4 = move (_2.1: usize); + StorageLive(_5); + _5 = Gt(_3, _4); + switchInt(move _5) -> [0: bb1, otherwise: bb4]; } bb1: { + StorageLive(_7); + _6 = Len((*_1)); + _7 = Gt(_4, _6); + switchInt(move _7) -> [0: bb2, otherwise: bb3]; + } + + bb2: { + StorageDead(_7); + StorageDead(_5); + StorageLive(_8); + _8 = &raw const (*_1); + StorageLive(_18); + StorageLive(_9); + _9 = SubUnchecked(_4, _3); + StorageLive(_11); + StorageLive(_10); + _10 = _8 as *const u32 (PtrToPtr); + _11 = Offset(_10, _3); + StorageDead(_10); + StorageLive(_12); + _12 = _11 as *const () (PtrToPtr); + StorageLive(_14); + StorageLive(_13); + _13 = std::ptr::metadata::PtrComponents::<[u32]> { data_address: _12, metadata: _9 }; + _14 = std::ptr::metadata::PtrRepr::<[u32]> { const_ptr: move _13 }; + StorageDead(_13); + _15 = (_14.0: *const [u32]); + StorageDead(_14); + StorageDead(_12); + StorageDead(_11); + StorageDead(_9); + StorageDead(_18); + StorageDead(_8); + _0 = &(*_15); return; } + + bb3: { + _16 = core::slice::index::slice_end_index_len_fail(move _4, move _6) -> unwind unreachable; + } + + bb4: { + _17 = core::slice::index::slice_index_order_fail(move _3, move _4) -> unwind unreachable; + } } diff --git a/tests/mir-opt/pre-codegen/slice_index.slice_index_range.PreCodegen.after.panic-unwind.mir b/tests/mir-opt/pre-codegen/slice_index.slice_index_range.PreCodegen.after.panic-unwind.mir index 4a976002fa5a8..8846ada65cfb1 100644 --- a/tests/mir-opt/pre-codegen/slice_index.slice_index_range.PreCodegen.after.panic-unwind.mir +++ b/tests/mir-opt/pre-codegen/slice_index.slice_index_range.PreCodegen.after.panic-unwind.mir @@ -4,16 +4,129 @@ fn slice_index_range(_1: &[u32], _2: std::ops::Range) -> &[u32] { debug slice => _1; debug index => _2; let mut _0: &[u32]; + let mut _3: usize; + let mut _4: usize; scope 1 (inlined #[track_caller] core::slice::index::> for [u32]>::index) { debug self => _1; - debug index => _2; + debug ((index: std::ops::Range).0: usize) => _3; + debug ((index: std::ops::Range).1: usize) => _4; + scope 2 (inlined #[track_caller] as SliceIndex<[u32]>>::index) { + debug ((self: std::ops::Range).0: usize) => _3; + debug ((self: std::ops::Range).1: usize) => _4; + debug slice => _1; + let mut _5: bool; + let mut _6: usize; + let mut _7: bool; + let mut _8: *const [u32]; + let _15: *const [u32]; + let _16: !; + let _17: !; + scope 3 { + scope 4 (inlined as SliceIndex<[u32]>>::get_unchecked) { + debug ((self: std::ops::Range).0: usize) => _3; + debug ((self: std::ops::Range).1: usize) => _4; + debug slice => _1; + let mut _10: *const u32; + let mut _11: *const u32; + let mut _18: &[&str]; + scope 5 { + let _9: usize; + scope 6 { + debug new_len => _9; + scope 11 (inlined std::ptr::const_ptr::::as_ptr) { + debug self => _1; + } + scope 12 (inlined std::ptr::const_ptr::::add) { + debug self => _10; + debug count => _3; + scope 13 { + } + } + scope 14 (inlined slice_from_raw_parts::) { + debug data => _11; + debug len => _9; + let mut _12: *const (); + scope 15 (inlined std::ptr::const_ptr::::cast::<()>) { + debug self => _11; + } + scope 16 (inlined std::ptr::from_raw_parts::<[u32]>) { + debug data_address => _12; + debug metadata => _9; + let mut _13: std::ptr::metadata::PtrComponents<[u32]>; + let mut _14: std::ptr::metadata::PtrRepr<[u32]>; + scope 17 { + } + } + } + } + } + scope 7 (inlined std::ptr::const_ptr::::len) { + debug self => _1; + scope 8 (inlined std::ptr::metadata::<[u32]>) { + debug ptr => _1; + scope 9 { + } + } + } + scope 10 (inlined Arguments::<'_>::new_const) { + debug pieces => _18; + } + } + } + } } bb0: { - _0 = as SliceIndex<[u32]>>::index(move _2, move _1) -> [return: bb1, unwind continue]; + _3 = move (_2.0: usize); + _4 = move (_2.1: usize); + StorageLive(_5); + _5 = Gt(_3, _4); + switchInt(move _5) -> [0: bb1, otherwise: bb4]; } bb1: { + StorageLive(_7); + _6 = Len((*_1)); + _7 = Gt(_4, _6); + switchInt(move _7) -> [0: bb2, otherwise: bb3]; + } + + bb2: { + StorageDead(_7); + StorageDead(_5); + StorageLive(_8); + _8 = &raw const (*_1); + StorageLive(_18); + StorageLive(_9); + _9 = SubUnchecked(_4, _3); + StorageLive(_11); + StorageLive(_10); + _10 = _8 as *const u32 (PtrToPtr); + _11 = Offset(_10, _3); + StorageDead(_10); + StorageLive(_12); + _12 = _11 as *const () (PtrToPtr); + StorageLive(_14); + StorageLive(_13); + _13 = std::ptr::metadata::PtrComponents::<[u32]> { data_address: _12, metadata: _9 }; + _14 = std::ptr::metadata::PtrRepr::<[u32]> { const_ptr: move _13 }; + StorageDead(_13); + _15 = (_14.0: *const [u32]); + StorageDead(_14); + StorageDead(_12); + StorageDead(_11); + StorageDead(_9); + StorageDead(_18); + StorageDead(_8); + _0 = &(*_15); return; } + + bb3: { + _16 = core::slice::index::slice_end_index_len_fail(move _4, move _6) -> unwind continue; + } + + bb4: { + _17 = core::slice::index::slice_index_order_fail(move _3, move _4) -> unwind continue; + } } 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 c58b630a0c365..2ed7e36648a85 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 @@ -8,18 +8,245 @@ fn enumerated_loop(_1: &[T], _2: impl Fn(usize, &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 _76: std::option::Option<(usize, &T)>; + let mut _77: isize; + let mut _80: &impl Fn(usize, &T); + let mut _81: (usize, &T); + let _82: (); scope 1 { debug iter => _15; - let _19: usize; - let _20: &T; + let _78: usize; + let _79: &T; scope 2 { - debug i => _19; - debug x => _20; + debug i => _78; + debug x => _79; + } + scope 25 (inlined > as Iterator>::next) { + debug self => _16; + let mut _17: &mut std::slice::Iter<'_, T>; + let mut _67: std::option::Option<&T>; + let mut _69: std::ops::ControlFlow, &T>; + let mut _71: isize; + let _72: &T; + let mut _74: (usize, bool); + let mut _75: (usize, &T); + scope 26 { + debug a => _72; + let _73: usize; + scope 31 { + debug i => _73; + } + } + scope 27 { + debug residual => const Option::::None; + scope 28 { + scope 34 (inlined as FromResidual>::from_residual) { + debug residual => const Option::::None; + } + } + } + scope 29 { + debug val => _72; + scope 30 { + } + } + scope 32 (inlined as Try>::branch) { + debug self => _67; + let mut _68: isize; + let _70: &T; + scope 33 { + debug v => _70; + } + } + scope 35 (inlined as Iterator>::next) { + debug self => _17; + let mut _18: bool; + let mut _19: *const *const T; + let mut _20: *const std::ptr::NonNull; + let mut _22: &std::ptr::NonNull; + let mut _23: &std::ptr::NonNull; + let mut _40: bool; + let mut _41: *const T; + let _44: std::ptr::NonNull; + let mut _56: &std::ptr::NonNull; + let mut _66: &T; + scope 36 { + scope 37 { + let _21: std::ptr::NonNull; + let _43: usize; + scope 38 { + debug len => _43; + } + scope 39 { + debug end => _21; + scope 45 (inlined as PartialEq>::eq) { + debug self => _22; + debug other => _23; + let mut _24: std::ptr::NonNull; + let mut _31: *mut T; + let mut _32: std::ptr::NonNull; + let mut _39: *mut T; + scope 46 (inlined NonNull::::as_ptr) { + debug self => _24; + let mut _25: *const T; + let mut _29: bool; + let mut _30: bool; + scope 47 { + scope 48 (inlined std::ptr::const_ptr::::is_null) { + debug self => _25; + let mut _26: *const u8; + scope 49 { + scope 50 (inlined std::ptr::const_ptr::::is_null::runtime_impl) { + debug ptr => _26; + let mut _28: usize; + scope 51 (inlined std::ptr::const_ptr::::addr) { + debug self => _26; + let mut _27: *const (); + scope 52 { + scope 53 (inlined std::ptr::const_ptr::::cast::<()>) { + debug self => _26; + } + } + } + } + } + } + } + } + scope 54 (inlined NonNull::::as_ptr) { + debug self => _32; + let mut _33: *const T; + let mut _37: bool; + let mut _38: bool; + scope 55 { + scope 56 (inlined std::ptr::const_ptr::::is_null) { + debug self => _33; + let mut _34: *const u8; + scope 57 { + scope 58 (inlined std::ptr::const_ptr::::is_null::runtime_impl) { + debug ptr => _34; + let mut _36: usize; + scope 59 (inlined std::ptr::const_ptr::::addr) { + debug self => _34; + let mut _35: *const (); + scope 60 { + scope 61 (inlined std::ptr::const_ptr::::cast::<()>) { + debug self => _34; + } + } + } + } + } + } + } + } + } + } + scope 40 { + scope 44 (inlined std::ptr::const_ptr::::cast::>) { + debug self => _19; + } + } + scope 41 (inlined std::ptr::const_ptr::::addr) { + debug self => _41; + let mut _42: *const (); + scope 42 { + scope 43 (inlined std::ptr::const_ptr::::cast::<()>) { + debug self => _41; + } + } + } + } + scope 62 (inlined std::slice::Iter::<'_, T>::post_inc_start) { + debug self => _17; + debug offset => const 1_usize; + let mut _45: bool; + let mut _46: *mut *const T; + let mut _47: *mut std::ptr::NonNull; + let mut _48: std::ptr::NonNull; + let mut _51: std::ptr::NonNull; + let mut _52: *mut *const T; + let mut _53: *mut usize; + let mut _54: usize; + let mut _55: usize; + scope 63 { + debug old => _44; + scope 64 { + scope 65 { + scope 66 { + debug len => _53; + scope 71 (inlined core::num::::unchecked_sub) { + debug self => _54; + debug rhs => const 1_usize; + scope 72 { + } + } + } + scope 67 { + scope 70 (inlined std::ptr::mut_ptr::::cast::) { + debug self => _52; + } + } + scope 68 { + debug _end => _47; + scope 74 (inlined NonNull::::add) { + debug self => _48; + debug count => const 1_usize; + let mut _49: *const T; + let mut _50: *const T; + scope 75 { + } + } + } + scope 69 { + scope 73 (inlined std::ptr::mut_ptr::::cast::>) { + debug self => _46; + } + } + } + } + } + } + scope 76 (inlined NonNull::::as_ref::<'_>) { + debug self => _56; + let mut _57: std::ptr::NonNull; + let mut _64: *mut T; + let _65: *const T; + scope 77 { + scope 78 (inlined NonNull::::as_ptr) { + debug self => _57; + let mut _58: *const T; + let mut _62: bool; + let mut _63: bool; + scope 79 { + scope 80 (inlined std::ptr::const_ptr::::is_null) { + debug self => _58; + let mut _59: *const u8; + scope 81 { + scope 82 (inlined std::ptr::const_ptr::::is_null::runtime_impl) { + debug ptr => _59; + let mut _61: usize; + scope 83 (inlined std::ptr::const_ptr::::addr) { + debug self => _59; + let mut _60: *const (); + scope 84 { + scope 85 (inlined std::ptr::const_ptr::::cast::<()>) { + debug self => _59; + } + } + } + } + } + } + } + } + scope 86 (inlined std::ptr::mut_ptr::::cast_const) { + debug self => _64; + } + } + } + } + } } } scope 3 (inlined core::slice::::iter) { @@ -47,15 +274,15 @@ fn enumerated_loop(_1: &[T], _2: impl Fn(usize, &T)) -> () { debug ptr => _9; scope 16 (inlined std::ptr::mut_ptr::::is_null) { debug self => _9; - let mut _24: *mut u8; + let mut _83: *mut u8; scope 17 { scope 18 (inlined std::ptr::mut_ptr::::is_null::runtime_impl) { - debug ptr => _24; + debug ptr => _83; scope 19 (inlined std::ptr::mut_ptr::::addr) { - debug self => _24; + debug self => _83; scope 20 { scope 21 (inlined std::ptr::mut_ptr::::cast::<()>) { - debug self => _24; + debug self => _83; } } } @@ -130,10 +357,10 @@ fn enumerated_loop(_1: &[T], _2: impl Fn(usize, &T)) -> () { StorageLive(_9); _9 = _4 as *mut T (PtrToPtr); StorageLive(_10); - StorageLive(_24); + StorageLive(_83); _10 = _9 as *const T (PointerCoercion(MutToConstPointer)); _11 = NonNull:: { pointer: _10 }; - StorageDead(_24); + StorageDead(_83); StorageDead(_10); StorageDead(_9); StorageLive(_12); @@ -151,46 +378,291 @@ fn enumerated_loop(_1: &[T], _2: impl Fn(usize, &T)) -> () { } bb4: { - StorageLive(_17); - StorageLive(_16); + StorageLive(_76); _16 = &mut _15; - _17 = > as Iterator>::next(move _16) -> [return: bb5, unwind unreachable]; + StorageLive(_71); + StorageLive(_72); + StorageLive(_73); + StorageLive(_74); + StorageLive(_69); + StorageLive(_67); + StorageLive(_17); + _17 = &mut (_15.0: std::slice::Iter<'_, T>); + StorageLive(_43); + StorageLive(_40); + StorageLive(_18); + _18 = const _; + switchInt(move _18) -> [0: bb5, otherwise: bb6]; } bb5: { - StorageDead(_16); - _18 = discriminant(_17); - switchInt(move _18) -> [0: bb6, 1: bb8, otherwise: bb10]; + StorageLive(_21); + StorageLive(_19); + _19 = &raw const ((_15.0: std::slice::Iter<'_, T>).1: *const T); + _20 = _19 as *const std::ptr::NonNull (PtrToPtr); + StorageDead(_19); + _21 = (*_20); + StorageLive(_22); + _22 = &((_15.0: std::slice::Iter<'_, T>).0: std::ptr::NonNull); + StorageLive(_23); + _23 = &_21; + StorageLive(_31); + StorageLive(_24); + _24 = ((_15.0: std::slice::Iter<'_, T>).0: std::ptr::NonNull); + StorageLive(_25); + StorageLive(_30); + StorageLive(_29); + _25 = (_24.0: *const T); + StorageLive(_26); + _26 = _25 as *const u8 (PtrToPtr); + StorageLive(_28); + StorageLive(_27); + _27 = _26 as *const () (PtrToPtr); + _28 = move _27 as usize (Transmute); + StorageDead(_27); + _29 = Eq(move _28, const 0_usize); + StorageDead(_28); + StorageDead(_26); + _30 = Not(move _29); + StorageDead(_29); + assume(move _30); + StorageDead(_30); + _31 = _25 as *mut T (PtrToPtr); + StorageDead(_25); + StorageDead(_24); + StorageLive(_39); + StorageLive(_32); + _32 = _21; + StorageLive(_33); + StorageLive(_38); + StorageLive(_37); + _33 = (_32.0: *const T); + StorageLive(_34); + _34 = _33 as *const u8 (PtrToPtr); + StorageLive(_36); + StorageLive(_35); + _35 = _34 as *const () (PtrToPtr); + _36 = move _35 as usize (Transmute); + StorageDead(_35); + _37 = Eq(move _36, const 0_usize); + StorageDead(_36); + StorageDead(_34); + _38 = Not(move _37); + StorageDead(_37); + assume(move _38); + StorageDead(_38); + _39 = _33 as *mut T (PtrToPtr); + StorageDead(_33); + StorageDead(_32); + _40 = Eq(move _31, move _39); + StorageDead(_39); + StorageDead(_31); + StorageDead(_23); + StorageDead(_22); + StorageDead(_21); + goto -> bb7; } bb6: { - StorageDead(_17); - StorageDead(_15); - drop(_2) -> [return: bb7, unwind unreachable]; + StorageLive(_41); + _41 = ((_15.0: std::slice::Iter<'_, T>).1: *const T); + StorageLive(_42); + _42 = _41 as *const () (PtrToPtr); + _43 = move _42 as usize (Transmute); + StorageDead(_42); + StorageDead(_41); + _40 = Eq(_43, const 0_usize); + goto -> bb7; } bb7: { - return; + StorageDead(_18); + switchInt(move _40) -> [0: bb8, otherwise: bb12]; } 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]; + StorageLive(_66); + StorageLive(_56); + StorageLive(_44); + StorageLive(_47); + _44 = ((_15.0: std::slice::Iter<'_, T>).0: std::ptr::NonNull); + StorageLive(_45); + _45 = const _; + switchInt(move _45) -> [0: bb9, otherwise: bb10]; } bb9: { - StorageDead(_22); - StorageDead(_21); + StorageLive(_46); + _46 = &raw mut ((_15.0: std::slice::Iter<'_, T>).1: *const T); + _47 = _46 as *mut std::ptr::NonNull (PtrToPtr); + StorageDead(_46); + StorageLive(_51); + StorageLive(_48); + _48 = ((_15.0: std::slice::Iter<'_, T>).0: std::ptr::NonNull); + StorageLive(_50); + StorageLive(_49); + _49 = (_48.0: *const T); + _50 = Offset(move _49, const 1_usize); + StorageDead(_49); + _51 = NonNull:: { pointer: move _50 }; + StorageDead(_50); + StorageDead(_48); + ((_15.0: std::slice::Iter<'_, T>).0: std::ptr::NonNull) = move _51; + StorageDead(_51); + goto -> bb11; + } + + bb10: { + StorageLive(_52); + _52 = &raw mut ((_15.0: std::slice::Iter<'_, T>).1: *const T); + _53 = _52 as *mut usize (PtrToPtr); + StorageDead(_52); + StorageLive(_55); + StorageLive(_54); + _54 = (*_53); + _55 = SubUnchecked(_54, const 1_usize); + StorageDead(_54); + (*_53) = move _55; + StorageDead(_55); + goto -> bb11; + } + + bb11: { + StorageDead(_45); + StorageDead(_47); + _56 = &_44; + StorageLive(_64); + StorageLive(_57); + _57 = _44; + StorageLive(_58); + StorageLive(_63); + StorageLive(_62); + _58 = (_57.0: *const T); + StorageLive(_59); + _59 = _58 as *const u8 (PtrToPtr); + StorageLive(_61); + StorageLive(_60); + _60 = _59 as *const () (PtrToPtr); + _61 = move _60 as usize (Transmute); + StorageDead(_60); + _62 = Eq(move _61, const 0_usize); + StorageDead(_61); + StorageDead(_59); + _63 = Not(move _62); + StorageDead(_62); + assume(move _63); + StorageDead(_63); + _64 = _58 as *mut T (PtrToPtr); + StorageDead(_58); + StorageDead(_57); + _65 = _64 as *const T (PointerCoercion(MutToConstPointer)); + StorageDead(_64); + _66 = &(*_65); + StorageDead(_56); + _67 = Option::<&T>::Some(move _66); + StorageDead(_66); + StorageDead(_44); + goto -> bb13; + } + + bb12: { + _67 = const {transmute(0x0000000000000000): Option<&T>}; + goto -> bb13; + } + + bb13: { + StorageDead(_40); + StorageDead(_43); StorageDead(_17); + StorageLive(_68); + StorageLive(_70); + _68 = discriminant(_67); + switchInt(move _68) -> [0: bb14, 1: bb15, otherwise: bb25]; + } + + bb14: { + _69 = const {transmute(0x0000000000000000): ControlFlow, &T>}; + goto -> bb16; + } + + bb15: { + _70 = move ((_67 as Some).0: &T); + _69 = ControlFlow::, &T>::Continue(move _70); + goto -> bb16; + } + + bb16: { + StorageDead(_70); + StorageDead(_68); + StorageDead(_67); + _71 = discriminant(_69); + switchInt(move _71) -> [0: bb17, 1: bb19, otherwise: bb25]; + } + + bb17: { + _72 = move ((_69 as Continue).0: &T); + StorageDead(_69); + _73 = (_15.1: usize); + _74 = CheckedAdd((_15.1: usize), const 1_usize); + assert(!move (_74.1: bool), "attempt to compute `{} + {}`, which would overflow", (_15.1: usize), const 1_usize) -> [success: bb18, unwind unreachable]; + } + + bb18: { + (_15.1: usize) = move (_74.0: usize); + StorageLive(_75); + _75 = (_73, move _72); + _76 = Option::<(usize, &T)>::Some(move _75); + StorageDead(_75); + goto -> bb20; + } + + bb19: { + _76 = const Indirect { alloc_id: ALLOC0, offset: Size(0 bytes) }: Option<(usize, &T)>; + StorageDead(_69); + goto -> bb20; + } + + bb20: { + StorageDead(_74); + StorageDead(_73); + StorageDead(_72); + StorageDead(_71); + _77 = discriminant(_76); + switchInt(move _77) -> [0: bb21, 1: bb23, otherwise: bb25]; + } + + bb21: { + StorageDead(_76); + StorageDead(_15); + drop(_2) -> [return: bb22, unwind unreachable]; + } + + bb22: { + return; + } + + bb23: { + _78 = (((_76 as Some).0: (usize, &T)).0: usize); + _79 = (((_76 as Some).0: (usize, &T)).1: &T); + StorageLive(_80); + _80 = &_2; + StorageLive(_81); + _81 = (_78, _79); + _82 = >::call(move _80, move _81) -> [return: bb24, unwind unreachable]; + } + + bb24: { + StorageDead(_81); + StorageDead(_80); + StorageDead(_76); goto -> bb4; } - bb10: { + bb25: { unreachable; } } + +ALLOC0 (size: 16, align: 8) { + __ __ __ __ __ __ __ __ 00 00 00 00 00 00 00 00 │ ░░░░░░░░........ +} 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 09075eed6a9cd..7df1f818d348f 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 @@ -7,16 +7,205 @@ fn forward_loop(_1: &[T], _2: impl Fn(&T)) -> () { 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 _65: std::option::Option<&T>; + let mut _66: isize; + let mut _68: &impl Fn(&T); + let mut _69: (&T,); + let _70: (); scope 1 { debug iter => _14; - let _18: &T; + let _67: &T; scope 2 { - debug x => _18; + debug x => _67; + } + scope 23 (inlined as Iterator>::next) { + debug self => _15; + let mut _16: bool; + let mut _17: *const *const T; + let mut _18: *const std::ptr::NonNull; + let mut _20: &std::ptr::NonNull; + let mut _21: &std::ptr::NonNull; + let mut _38: bool; + let mut _39: *const T; + let _42: std::ptr::NonNull; + let mut _54: &std::ptr::NonNull; + let mut _64: &T; + scope 24 { + scope 25 { + let _19: std::ptr::NonNull; + let _41: usize; + scope 26 { + debug len => _41; + } + scope 27 { + debug end => _19; + scope 33 (inlined as PartialEq>::eq) { + debug self => _20; + debug other => _21; + let mut _22: std::ptr::NonNull; + let mut _29: *mut T; + let mut _30: std::ptr::NonNull; + let mut _37: *mut T; + scope 34 (inlined NonNull::::as_ptr) { + debug self => _22; + let mut _23: *const T; + let mut _27: bool; + let mut _28: bool; + scope 35 { + scope 36 (inlined std::ptr::const_ptr::::is_null) { + debug self => _23; + let mut _24: *const u8; + scope 37 { + scope 38 (inlined std::ptr::const_ptr::::is_null::runtime_impl) { + debug ptr => _24; + let mut _26: usize; + scope 39 (inlined std::ptr::const_ptr::::addr) { + debug self => _24; + let mut _25: *const (); + scope 40 { + scope 41 (inlined std::ptr::const_ptr::::cast::<()>) { + debug self => _24; + } + } + } + } + } + } + } + } + scope 42 (inlined NonNull::::as_ptr) { + debug self => _30; + let mut _31: *const T; + let mut _35: bool; + let mut _36: bool; + scope 43 { + scope 44 (inlined std::ptr::const_ptr::::is_null) { + debug self => _31; + let mut _32: *const u8; + scope 45 { + scope 46 (inlined std::ptr::const_ptr::::is_null::runtime_impl) { + debug ptr => _32; + let mut _34: usize; + scope 47 (inlined std::ptr::const_ptr::::addr) { + debug self => _32; + let mut _33: *const (); + scope 48 { + scope 49 (inlined std::ptr::const_ptr::::cast::<()>) { + debug self => _32; + } + } + } + } + } + } + } + } + } + } + scope 28 { + scope 32 (inlined std::ptr::const_ptr::::cast::>) { + debug self => _17; + } + } + scope 29 (inlined std::ptr::const_ptr::::addr) { + debug self => _39; + let mut _40: *const (); + scope 30 { + scope 31 (inlined std::ptr::const_ptr::::cast::<()>) { + debug self => _39; + } + } + } + } + scope 50 (inlined std::slice::Iter::<'_, T>::post_inc_start) { + debug self => _15; + debug offset => const 1_usize; + let mut _43: bool; + let mut _44: *mut *const T; + let mut _45: *mut std::ptr::NonNull; + let mut _46: std::ptr::NonNull; + let mut _49: std::ptr::NonNull; + let mut _50: *mut *const T; + let mut _51: *mut usize; + let mut _52: usize; + let mut _53: usize; + scope 51 { + debug old => _42; + scope 52 { + scope 53 { + scope 54 { + debug len => _51; + scope 59 (inlined core::num::::unchecked_sub) { + debug self => _52; + debug rhs => const 1_usize; + scope 60 { + } + } + } + scope 55 { + scope 58 (inlined std::ptr::mut_ptr::::cast::) { + debug self => _50; + } + } + scope 56 { + debug _end => _45; + scope 62 (inlined NonNull::::add) { + debug self => _46; + debug count => const 1_usize; + let mut _47: *const T; + let mut _48: *const T; + scope 63 { + } + } + } + scope 57 { + scope 61 (inlined std::ptr::mut_ptr::::cast::>) { + debug self => _44; + } + } + } + } + } + } + scope 64 (inlined NonNull::::as_ref::<'_>) { + debug self => _54; + let mut _55: std::ptr::NonNull; + let mut _62: *mut T; + let _63: *const T; + scope 65 { + scope 66 (inlined NonNull::::as_ptr) { + debug self => _55; + let mut _56: *const T; + let mut _60: bool; + let mut _61: bool; + scope 67 { + scope 68 (inlined std::ptr::const_ptr::::is_null) { + debug self => _56; + let mut _57: *const u8; + scope 69 { + scope 70 (inlined std::ptr::const_ptr::::is_null::runtime_impl) { + debug ptr => _57; + let mut _59: usize; + scope 71 (inlined std::ptr::const_ptr::::addr) { + debug self => _57; + let mut _58: *const (); + scope 72 { + scope 73 (inlined std::ptr::const_ptr::::cast::<()>) { + debug self => _57; + } + } + } + } + } + } + } + } + scope 74 (inlined std::ptr::mut_ptr::::cast_const) { + debug self => _62; + } + } + } + } } } scope 3 (inlined core::slice::::iter) { @@ -44,15 +233,15 @@ fn forward_loop(_1: &[T], _2: impl Fn(&T)) -> () { debug ptr => _9; scope 16 (inlined std::ptr::mut_ptr::::is_null) { debug self => _9; - let mut _22: *mut u8; + let mut _71: *mut u8; scope 17 { scope 18 (inlined std::ptr::mut_ptr::::is_null::runtime_impl) { - debug ptr => _22; + debug ptr => _71; scope 19 (inlined std::ptr::mut_ptr::::addr) { - debug self => _22; + debug self => _71; scope 20 { scope 21 (inlined std::ptr::mut_ptr::::cast::<()>) { - debug self => _22; + debug self => _71; } } } @@ -120,10 +309,10 @@ fn forward_loop(_1: &[T], _2: impl Fn(&T)) -> () { StorageLive(_9); _9 = _4 as *mut T (PtrToPtr); StorageLive(_10); - StorageLive(_22); + StorageLive(_71); _10 = _9 as *const T (PointerCoercion(MutToConstPointer)); _11 = NonNull:: { pointer: _10 }; - StorageDead(_22); + StorageDead(_71); StorageDead(_10); StorageDead(_9); StorageLive(_12); @@ -139,45 +328,224 @@ fn forward_loop(_1: &[T], _2: impl Fn(&T)) -> () { } bb4: { - StorageLive(_16); - StorageLive(_15); + StorageLive(_65); _15 = &mut _14; - _16 = as Iterator>::next(move _15) -> [return: bb5, unwind unreachable]; + StorageLive(_41); + StorageLive(_38); + StorageLive(_16); + _16 = const _; + switchInt(move _16) -> [0: bb5, otherwise: bb6]; } bb5: { - StorageDead(_15); - _17 = discriminant(_16); - switchInt(move _17) -> [0: bb6, 1: bb8, otherwise: bb10]; + StorageLive(_19); + StorageLive(_17); + _17 = &raw const (_14.1: *const T); + _18 = _17 as *const std::ptr::NonNull (PtrToPtr); + StorageDead(_17); + _19 = (*_18); + StorageLive(_20); + _20 = &(_14.0: std::ptr::NonNull); + StorageLive(_21); + _21 = &_19; + StorageLive(_29); + StorageLive(_22); + _22 = (_14.0: std::ptr::NonNull); + StorageLive(_23); + StorageLive(_28); + StorageLive(_27); + _23 = (_22.0: *const T); + StorageLive(_24); + _24 = _23 as *const u8 (PtrToPtr); + StorageLive(_26); + StorageLive(_25); + _25 = _24 as *const () (PtrToPtr); + _26 = move _25 as usize (Transmute); + StorageDead(_25); + _27 = Eq(move _26, const 0_usize); + StorageDead(_26); + StorageDead(_24); + _28 = Not(move _27); + StorageDead(_27); + assume(move _28); + StorageDead(_28); + _29 = _23 as *mut T (PtrToPtr); + StorageDead(_23); + StorageDead(_22); + StorageLive(_37); + StorageLive(_30); + _30 = _19; + StorageLive(_31); + StorageLive(_36); + StorageLive(_35); + _31 = (_30.0: *const T); + StorageLive(_32); + _32 = _31 as *const u8 (PtrToPtr); + StorageLive(_34); + StorageLive(_33); + _33 = _32 as *const () (PtrToPtr); + _34 = move _33 as usize (Transmute); + StorageDead(_33); + _35 = Eq(move _34, const 0_usize); + StorageDead(_34); + StorageDead(_32); + _36 = Not(move _35); + StorageDead(_35); + assume(move _36); + StorageDead(_36); + _37 = _31 as *mut T (PtrToPtr); + StorageDead(_31); + StorageDead(_30); + _38 = Eq(move _29, move _37); + StorageDead(_37); + StorageDead(_29); + StorageDead(_21); + StorageDead(_20); + StorageDead(_19); + goto -> bb7; } bb6: { - StorageDead(_16); - StorageDead(_14); - drop(_2) -> [return: bb7, unwind unreachable]; + StorageLive(_39); + _39 = (_14.1: *const T); + StorageLive(_40); + _40 = _39 as *const () (PtrToPtr); + _41 = move _40 as usize (Transmute); + StorageDead(_40); + StorageDead(_39); + _38 = Eq(_41, const 0_usize); + goto -> bb7; } bb7: { - return; + StorageDead(_16); + switchInt(move _38) -> [0: bb8, otherwise: bb12]; } 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]; + StorageLive(_64); + StorageLive(_54); + StorageLive(_42); + StorageLive(_45); + _42 = (_14.0: std::ptr::NonNull); + StorageLive(_43); + _43 = const _; + switchInt(move _43) -> [0: bb9, otherwise: bb10]; } bb9: { - StorageDead(_20); - StorageDead(_19); - StorageDead(_16); - goto -> bb4; + StorageLive(_44); + _44 = &raw mut (_14.1: *const T); + _45 = _44 as *mut std::ptr::NonNull (PtrToPtr); + StorageDead(_44); + StorageLive(_49); + StorageLive(_46); + _46 = (_14.0: std::ptr::NonNull); + StorageLive(_48); + StorageLive(_47); + _47 = (_46.0: *const T); + _48 = Offset(move _47, const 1_usize); + StorageDead(_47); + _49 = NonNull:: { pointer: move _48 }; + StorageDead(_48); + StorageDead(_46); + (_14.0: std::ptr::NonNull) = move _49; + StorageDead(_49); + goto -> bb11; } bb10: { + StorageLive(_50); + _50 = &raw mut (_14.1: *const T); + _51 = _50 as *mut usize (PtrToPtr); + StorageDead(_50); + StorageLive(_53); + StorageLive(_52); + _52 = (*_51); + _53 = SubUnchecked(_52, const 1_usize); + StorageDead(_52); + (*_51) = move _53; + StorageDead(_53); + goto -> bb11; + } + + bb11: { + StorageDead(_43); + StorageDead(_45); + _54 = &_42; + StorageLive(_62); + StorageLive(_55); + _55 = _42; + StorageLive(_56); + StorageLive(_61); + StorageLive(_60); + _56 = (_55.0: *const T); + StorageLive(_57); + _57 = _56 as *const u8 (PtrToPtr); + StorageLive(_59); + StorageLive(_58); + _58 = _57 as *const () (PtrToPtr); + _59 = move _58 as usize (Transmute); + StorageDead(_58); + _60 = Eq(move _59, const 0_usize); + StorageDead(_59); + StorageDead(_57); + _61 = Not(move _60); + StorageDead(_60); + assume(move _61); + StorageDead(_61); + _62 = _56 as *mut T (PtrToPtr); + StorageDead(_56); + StorageDead(_55); + _63 = _62 as *const T (PointerCoercion(MutToConstPointer)); + StorageDead(_62); + _64 = &(*_63); + StorageDead(_54); + _65 = Option::<&T>::Some(move _64); + StorageDead(_64); + StorageDead(_42); + goto -> bb13; + } + + bb12: { + _65 = const {transmute(0x0000000000000000): Option<&T>}; + goto -> bb13; + } + + bb13: { + StorageDead(_38); + StorageDead(_41); + _66 = discriminant(_65); + switchInt(move _66) -> [0: bb14, 1: bb16, otherwise: bb18]; + } + + bb14: { + StorageDead(_65); + StorageDead(_14); + drop(_2) -> [return: bb15, unwind unreachable]; + } + + bb15: { + return; + } + + bb16: { + _67 = ((_65 as Some).0: &T); + StorageLive(_68); + _68 = &_2; + StorageLive(_69); + _69 = (_67,); + _70 = >::call(move _68, move _69) -> [return: bb17, unwind unreachable]; + } + + bb17: { + StorageDead(_69); + StorageDead(_68); + StorageDead(_65); + goto -> bb4; + } + + bb18: { 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 47b84746468a0..6b734d25b056d 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 @@ -7,16 +7,205 @@ fn forward_loop(_1: &[T], _2: impl Fn(&T)) -> () { 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 _65: std::option::Option<&T>; + let mut _66: isize; + let mut _68: &impl Fn(&T); + let mut _69: (&T,); + let _70: (); scope 1 { debug iter => _14; - let _18: &T; + let _67: &T; scope 2 { - debug x => _18; + debug x => _67; + } + scope 23 (inlined as Iterator>::next) { + debug self => _15; + let mut _16: bool; + let mut _17: *const *const T; + let mut _18: *const std::ptr::NonNull; + let mut _20: &std::ptr::NonNull; + let mut _21: &std::ptr::NonNull; + let mut _38: bool; + let mut _39: *const T; + let _42: std::ptr::NonNull; + let mut _54: &std::ptr::NonNull; + let mut _64: &T; + scope 24 { + scope 25 { + let _19: std::ptr::NonNull; + let _41: usize; + scope 26 { + debug len => _41; + } + scope 27 { + debug end => _19; + scope 33 (inlined as PartialEq>::eq) { + debug self => _20; + debug other => _21; + let mut _22: std::ptr::NonNull; + let mut _29: *mut T; + let mut _30: std::ptr::NonNull; + let mut _37: *mut T; + scope 34 (inlined NonNull::::as_ptr) { + debug self => _22; + let mut _23: *const T; + let mut _27: bool; + let mut _28: bool; + scope 35 { + scope 36 (inlined std::ptr::const_ptr::::is_null) { + debug self => _23; + let mut _24: *const u8; + scope 37 { + scope 38 (inlined std::ptr::const_ptr::::is_null::runtime_impl) { + debug ptr => _24; + let mut _26: usize; + scope 39 (inlined std::ptr::const_ptr::::addr) { + debug self => _24; + let mut _25: *const (); + scope 40 { + scope 41 (inlined std::ptr::const_ptr::::cast::<()>) { + debug self => _24; + } + } + } + } + } + } + } + } + scope 42 (inlined NonNull::::as_ptr) { + debug self => _30; + let mut _31: *const T; + let mut _35: bool; + let mut _36: bool; + scope 43 { + scope 44 (inlined std::ptr::const_ptr::::is_null) { + debug self => _31; + let mut _32: *const u8; + scope 45 { + scope 46 (inlined std::ptr::const_ptr::::is_null::runtime_impl) { + debug ptr => _32; + let mut _34: usize; + scope 47 (inlined std::ptr::const_ptr::::addr) { + debug self => _32; + let mut _33: *const (); + scope 48 { + scope 49 (inlined std::ptr::const_ptr::::cast::<()>) { + debug self => _32; + } + } + } + } + } + } + } + } + } + } + scope 28 { + scope 32 (inlined std::ptr::const_ptr::::cast::>) { + debug self => _17; + } + } + scope 29 (inlined std::ptr::const_ptr::::addr) { + debug self => _39; + let mut _40: *const (); + scope 30 { + scope 31 (inlined std::ptr::const_ptr::::cast::<()>) { + debug self => _39; + } + } + } + } + scope 50 (inlined std::slice::Iter::<'_, T>::post_inc_start) { + debug self => _15; + debug offset => const 1_usize; + let mut _43: bool; + let mut _44: *mut *const T; + let mut _45: *mut std::ptr::NonNull; + let mut _46: std::ptr::NonNull; + let mut _49: std::ptr::NonNull; + let mut _50: *mut *const T; + let mut _51: *mut usize; + let mut _52: usize; + let mut _53: usize; + scope 51 { + debug old => _42; + scope 52 { + scope 53 { + scope 54 { + debug len => _51; + scope 59 (inlined core::num::::unchecked_sub) { + debug self => _52; + debug rhs => const 1_usize; + scope 60 { + } + } + } + scope 55 { + scope 58 (inlined std::ptr::mut_ptr::::cast::) { + debug self => _50; + } + } + scope 56 { + debug _end => _45; + scope 62 (inlined NonNull::::add) { + debug self => _46; + debug count => const 1_usize; + let mut _47: *const T; + let mut _48: *const T; + scope 63 { + } + } + } + scope 57 { + scope 61 (inlined std::ptr::mut_ptr::::cast::>) { + debug self => _44; + } + } + } + } + } + } + scope 64 (inlined NonNull::::as_ref::<'_>) { + debug self => _54; + let mut _55: std::ptr::NonNull; + let mut _62: *mut T; + let _63: *const T; + scope 65 { + scope 66 (inlined NonNull::::as_ptr) { + debug self => _55; + let mut _56: *const T; + let mut _60: bool; + let mut _61: bool; + scope 67 { + scope 68 (inlined std::ptr::const_ptr::::is_null) { + debug self => _56; + let mut _57: *const u8; + scope 69 { + scope 70 (inlined std::ptr::const_ptr::::is_null::runtime_impl) { + debug ptr => _57; + let mut _59: usize; + scope 71 (inlined std::ptr::const_ptr::::addr) { + debug self => _57; + let mut _58: *const (); + scope 72 { + scope 73 (inlined std::ptr::const_ptr::::cast::<()>) { + debug self => _57; + } + } + } + } + } + } + } + } + scope 74 (inlined std::ptr::mut_ptr::::cast_const) { + debug self => _62; + } + } + } + } } } scope 3 (inlined core::slice::::iter) { @@ -44,15 +233,15 @@ fn forward_loop(_1: &[T], _2: impl Fn(&T)) -> () { debug ptr => _9; scope 16 (inlined std::ptr::mut_ptr::::is_null) { debug self => _9; - let mut _22: *mut u8; + let mut _71: *mut u8; scope 17 { scope 18 (inlined std::ptr::mut_ptr::::is_null::runtime_impl) { - debug ptr => _22; + debug ptr => _71; scope 19 (inlined std::ptr::mut_ptr::::addr) { - debug self => _22; + debug self => _71; scope 20 { scope 21 (inlined std::ptr::mut_ptr::::cast::<()>) { - debug self => _22; + debug self => _71; } } } @@ -120,10 +309,10 @@ fn forward_loop(_1: &[T], _2: impl Fn(&T)) -> () { StorageLive(_9); _9 = _4 as *mut T (PtrToPtr); StorageLive(_10); - StorageLive(_22); + StorageLive(_71); _10 = _9 as *const T (PointerCoercion(MutToConstPointer)); _11 = NonNull:: { pointer: _10 }; - StorageDead(_22); + StorageDead(_71); StorageDead(_10); StorageDead(_9); StorageLive(_12); @@ -139,53 +328,232 @@ fn forward_loop(_1: &[T], _2: impl Fn(&T)) -> () { } bb4: { - StorageLive(_16); - StorageLive(_15); + StorageLive(_65); _15 = &mut _14; - _16 = as Iterator>::next(move _15) -> [return: bb5, unwind: bb11]; + StorageLive(_41); + StorageLive(_38); + StorageLive(_16); + _16 = const _; + switchInt(move _16) -> [0: bb5, otherwise: bb6]; } bb5: { - StorageDead(_15); - _17 = discriminant(_16); - switchInt(move _17) -> [0: bb6, 1: bb8, otherwise: bb10]; + StorageLive(_19); + StorageLive(_17); + _17 = &raw const (_14.1: *const T); + _18 = _17 as *const std::ptr::NonNull (PtrToPtr); + StorageDead(_17); + _19 = (*_18); + StorageLive(_20); + _20 = &(_14.0: std::ptr::NonNull); + StorageLive(_21); + _21 = &_19; + StorageLive(_29); + StorageLive(_22); + _22 = (_14.0: std::ptr::NonNull); + StorageLive(_23); + StorageLive(_28); + StorageLive(_27); + _23 = (_22.0: *const T); + StorageLive(_24); + _24 = _23 as *const u8 (PtrToPtr); + StorageLive(_26); + StorageLive(_25); + _25 = _24 as *const () (PtrToPtr); + _26 = move _25 as usize (Transmute); + StorageDead(_25); + _27 = Eq(move _26, const 0_usize); + StorageDead(_26); + StorageDead(_24); + _28 = Not(move _27); + StorageDead(_27); + assume(move _28); + StorageDead(_28); + _29 = _23 as *mut T (PtrToPtr); + StorageDead(_23); + StorageDead(_22); + StorageLive(_37); + StorageLive(_30); + _30 = _19; + StorageLive(_31); + StorageLive(_36); + StorageLive(_35); + _31 = (_30.0: *const T); + StorageLive(_32); + _32 = _31 as *const u8 (PtrToPtr); + StorageLive(_34); + StorageLive(_33); + _33 = _32 as *const () (PtrToPtr); + _34 = move _33 as usize (Transmute); + StorageDead(_33); + _35 = Eq(move _34, const 0_usize); + StorageDead(_34); + StorageDead(_32); + _36 = Not(move _35); + StorageDead(_35); + assume(move _36); + StorageDead(_36); + _37 = _31 as *mut T (PtrToPtr); + StorageDead(_31); + StorageDead(_30); + _38 = Eq(move _29, move _37); + StorageDead(_37); + StorageDead(_29); + StorageDead(_21); + StorageDead(_20); + StorageDead(_19); + goto -> bb7; } bb6: { - StorageDead(_16); - StorageDead(_14); - drop(_2) -> [return: bb7, unwind continue]; + StorageLive(_39); + _39 = (_14.1: *const T); + StorageLive(_40); + _40 = _39 as *const () (PtrToPtr); + _41 = move _40 as usize (Transmute); + StorageDead(_40); + StorageDead(_39); + _38 = Eq(_41, const 0_usize); + goto -> bb7; } bb7: { - return; + StorageDead(_16); + switchInt(move _38) -> [0: bb8, otherwise: bb12]; } 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]; + StorageLive(_64); + StorageLive(_54); + StorageLive(_42); + StorageLive(_45); + _42 = (_14.0: std::ptr::NonNull); + StorageLive(_43); + _43 = const _; + switchInt(move _43) -> [0: bb9, otherwise: bb10]; } bb9: { - StorageDead(_20); - StorageDead(_19); - StorageDead(_16); - goto -> bb4; + StorageLive(_44); + _44 = &raw mut (_14.1: *const T); + _45 = _44 as *mut std::ptr::NonNull (PtrToPtr); + StorageDead(_44); + StorageLive(_49); + StorageLive(_46); + _46 = (_14.0: std::ptr::NonNull); + StorageLive(_48); + StorageLive(_47); + _47 = (_46.0: *const T); + _48 = Offset(move _47, const 1_usize); + StorageDead(_47); + _49 = NonNull:: { pointer: move _48 }; + StorageDead(_48); + StorageDead(_46); + (_14.0: std::ptr::NonNull) = move _49; + StorageDead(_49); + goto -> bb11; } bb10: { - unreachable; + StorageLive(_50); + _50 = &raw mut (_14.1: *const T); + _51 = _50 as *mut usize (PtrToPtr); + StorageDead(_50); + StorageLive(_53); + StorageLive(_52); + _52 = (*_51); + _53 = SubUnchecked(_52, const 1_usize); + StorageDead(_52); + (*_51) = move _53; + StorageDead(_53); + goto -> bb11; + } + + bb11: { + StorageDead(_43); + StorageDead(_45); + _54 = &_42; + StorageLive(_62); + StorageLive(_55); + _55 = _42; + StorageLive(_56); + StorageLive(_61); + StorageLive(_60); + _56 = (_55.0: *const T); + StorageLive(_57); + _57 = _56 as *const u8 (PtrToPtr); + StorageLive(_59); + StorageLive(_58); + _58 = _57 as *const () (PtrToPtr); + _59 = move _58 as usize (Transmute); + StorageDead(_58); + _60 = Eq(move _59, const 0_usize); + StorageDead(_59); + StorageDead(_57); + _61 = Not(move _60); + StorageDead(_60); + assume(move _61); + StorageDead(_61); + _62 = _56 as *mut T (PtrToPtr); + StorageDead(_56); + StorageDead(_55); + _63 = _62 as *const T (PointerCoercion(MutToConstPointer)); + StorageDead(_62); + _64 = &(*_63); + StorageDead(_54); + _65 = Option::<&T>::Some(move _64); + StorageDead(_64); + StorageDead(_42); + goto -> bb13; + } + + bb12: { + _65 = const {transmute(0x0000000000000000): Option<&T>}; + goto -> bb13; + } + + bb13: { + StorageDead(_38); + StorageDead(_41); + _66 = discriminant(_65); + switchInt(move _66) -> [0: bb14, 1: bb16, otherwise: bb20]; } - bb11 (cleanup): { - drop(_2) -> [return: bb12, unwind terminate(cleanup)]; + bb14: { + StorageDead(_65); + StorageDead(_14); + drop(_2) -> [return: bb15, unwind continue]; } - bb12 (cleanup): { + bb15: { + return; + } + + bb16: { + _67 = ((_65 as Some).0: &T); + StorageLive(_68); + _68 = &_2; + StorageLive(_69); + _69 = (_67,); + _70 = >::call(move _68, move _69) -> [return: bb17, unwind: bb18]; + } + + bb17: { + StorageDead(_69); + StorageDead(_68); + StorageDead(_65); + goto -> bb4; + } + + bb18 (cleanup): { + drop(_2) -> [return: bb19, unwind terminate(cleanup)]; + } + + bb19 (cleanup): { resume; } + + bb20: { + unreachable; + } } 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 5ed7ca5e2b86f..f1ff3e6d2b385 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 @@ -8,20 +8,215 @@ fn reverse_loop(_1: &[T], _2: impl Fn(&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 _68: std::option::Option<&T>; + let mut _69: isize; + let mut _71: &impl Fn(&T); + let mut _72: (&T,); + let _73: (); scope 1 { debug iter => _15; - let _20: &T; + let _70: &T; scope 2 { - debug x => _20; + debug x => _70; } scope 25 (inlined > as Iterator>::next) { debug self => _16; let mut _17: &mut std::slice::Iter<'_, T>; + scope 26 (inlined as DoubleEndedIterator>::next_back) { + debug self => _17; + let mut _18: bool; + let mut _19: *const *const T; + let mut _20: *const std::ptr::NonNull; + let mut _22: &std::ptr::NonNull; + let mut _23: &std::ptr::NonNull; + let mut _40: bool; + let mut _41: *const T; + let _52: std::ptr::NonNull; + let mut _57: &std::ptr::NonNull; + let mut _67: &T; + scope 27 { + scope 28 { + let _21: std::ptr::NonNull; + let _43: usize; + scope 29 { + debug len => _43; + } + scope 30 { + debug end => _21; + scope 36 (inlined as PartialEq>::eq) { + debug self => _22; + debug other => _23; + let mut _24: std::ptr::NonNull; + let mut _31: *mut T; + let mut _32: std::ptr::NonNull; + let mut _39: *mut T; + scope 37 (inlined NonNull::::as_ptr) { + debug self => _24; + let mut _25: *const T; + let mut _29: bool; + let mut _30: bool; + scope 38 { + scope 39 (inlined std::ptr::const_ptr::::is_null) { + debug self => _25; + let mut _26: *const u8; + scope 40 { + scope 41 (inlined std::ptr::const_ptr::::is_null::runtime_impl) { + debug ptr => _26; + let mut _28: usize; + scope 42 (inlined std::ptr::const_ptr::::addr) { + debug self => _26; + let mut _27: *const (); + scope 43 { + scope 44 (inlined std::ptr::const_ptr::::cast::<()>) { + debug self => _26; + } + } + } + } + } + } + } + } + scope 45 (inlined NonNull::::as_ptr) { + debug self => _32; + let mut _33: *const T; + let mut _37: bool; + let mut _38: bool; + scope 46 { + scope 47 (inlined std::ptr::const_ptr::::is_null) { + debug self => _33; + let mut _34: *const u8; + scope 48 { + scope 49 (inlined std::ptr::const_ptr::::is_null::runtime_impl) { + debug ptr => _34; + let mut _36: usize; + scope 50 (inlined std::ptr::const_ptr::::addr) { + debug self => _34; + let mut _35: *const (); + scope 51 { + scope 52 (inlined std::ptr::const_ptr::::cast::<()>) { + debug self => _34; + } + } + } + } + } + } + } + } + } + } + scope 31 { + scope 35 (inlined std::ptr::const_ptr::::cast::>) { + debug self => _19; + } + } + scope 32 (inlined std::ptr::const_ptr::::addr) { + debug self => _41; + let mut _42: *const (); + scope 33 { + scope 34 (inlined std::ptr::const_ptr::::cast::<()>) { + debug self => _41; + } + } + } + } + scope 53 (inlined std::slice::Iter::<'_, T>::pre_dec_end) { + debug self => _17; + debug offset => const 1_usize; + let mut _44: bool; + let mut _45: *mut *const T; + let mut _46: *mut std::ptr::NonNull; + let mut _47: std::ptr::NonNull; + let mut _51: std::ptr::NonNull; + let mut _53: *mut *const T; + let mut _54: *mut usize; + let mut _55: usize; + let mut _56: usize; + scope 54 { + scope 55 { + debug len => _54; + scope 57 { + scope 62 (inlined core::num::::unchecked_sub) { + debug self => _55; + debug rhs => const 1_usize; + scope 63 { + } + } + } + } + scope 56 { + scope 61 (inlined std::ptr::mut_ptr::::cast::) { + debug self => _53; + } + } + scope 58 { + debug end => _46; + scope 60 { + scope 65 (inlined NonNull::::sub) { + debug self => _47; + debug count => const 1_usize; + let mut _48: bool; + scope 66 { + scope 67 (inlined NonNull::::offset) { + debug self => _47; + debug count => const -1_isize; + let mut _49: *const T; + let mut _50: *const T; + scope 68 { + } + } + } + } + } + } + scope 59 { + scope 64 (inlined std::ptr::mut_ptr::::cast::>) { + debug self => _45; + } + } + } + } + scope 69 (inlined NonNull::::as_ref::<'_>) { + debug self => _57; + let mut _58: std::ptr::NonNull; + let mut _65: *mut T; + let _66: *const T; + scope 70 { + scope 71 (inlined NonNull::::as_ptr) { + debug self => _58; + let mut _59: *const T; + let mut _63: bool; + let mut _64: bool; + scope 72 { + scope 73 (inlined std::ptr::const_ptr::::is_null) { + debug self => _59; + let mut _60: *const u8; + scope 74 { + scope 75 (inlined std::ptr::const_ptr::::is_null::runtime_impl) { + debug ptr => _60; + let mut _62: usize; + scope 76 (inlined std::ptr::const_ptr::::addr) { + debug self => _60; + let mut _61: *const (); + scope 77 { + scope 78 (inlined std::ptr::const_ptr::::cast::<()>) { + debug self => _60; + } + } + } + } + } + } + } + } + scope 79 (inlined std::ptr::mut_ptr::::cast_const) { + debug self => _65; + } + } + } + } + } } } scope 3 (inlined core::slice::::iter) { @@ -49,15 +244,15 @@ fn reverse_loop(_1: &[T], _2: impl Fn(&T)) -> () { debug ptr => _9; scope 16 (inlined std::ptr::mut_ptr::::is_null) { debug self => _9; - let mut _24: *mut u8; + let mut _74: *mut u8; scope 17 { scope 18 (inlined std::ptr::mut_ptr::::is_null::runtime_impl) { - debug ptr => _24; + debug ptr => _74; scope 19 (inlined std::ptr::mut_ptr::::addr) { - debug self => _24; + debug self => _74; scope 20 { scope 21 (inlined std::ptr::mut_ptr::::cast::<()>) { - debug self => _24; + debug self => _74; } } } @@ -132,10 +327,10 @@ fn reverse_loop(_1: &[T], _2: impl Fn(&T)) -> () { StorageLive(_9); _9 = _4 as *mut T (PtrToPtr); StorageLive(_10); - StorageLive(_24); + StorageLive(_74); _10 = _9 as *const T (PointerCoercion(MutToConstPointer)); _11 = NonNull:: { pointer: _10 }; - StorageDead(_24); + StorageDead(_74); StorageDead(_10); StorageDead(_9); StorageLive(_12); @@ -153,46 +348,240 @@ fn reverse_loop(_1: &[T], _2: impl Fn(&T)) -> () { } bb4: { - StorageLive(_18); + StorageLive(_68); _16 = &mut _15; StorageLive(_17); _17 = &mut (_15.0: std::slice::Iter<'_, T>); - _18 = as DoubleEndedIterator>::next_back(move _17) -> [return: bb5, unwind unreachable]; + StorageLive(_43); + StorageLive(_40); + StorageLive(_18); + _18 = const _; + switchInt(move _18) -> [0: bb5, otherwise: bb6]; } bb5: { - StorageDead(_17); - _19 = discriminant(_18); - switchInt(move _19) -> [0: bb6, 1: bb8, otherwise: bb10]; + StorageLive(_21); + StorageLive(_19); + _19 = &raw const ((_15.0: std::slice::Iter<'_, T>).1: *const T); + _20 = _19 as *const std::ptr::NonNull (PtrToPtr); + StorageDead(_19); + _21 = (*_20); + StorageLive(_22); + _22 = &((_15.0: std::slice::Iter<'_, T>).0: std::ptr::NonNull); + StorageLive(_23); + _23 = &_21; + StorageLive(_31); + StorageLive(_24); + _24 = ((_15.0: std::slice::Iter<'_, T>).0: std::ptr::NonNull); + StorageLive(_25); + StorageLive(_30); + StorageLive(_29); + _25 = (_24.0: *const T); + StorageLive(_26); + _26 = _25 as *const u8 (PtrToPtr); + StorageLive(_28); + StorageLive(_27); + _27 = _26 as *const () (PtrToPtr); + _28 = move _27 as usize (Transmute); + StorageDead(_27); + _29 = Eq(move _28, const 0_usize); + StorageDead(_28); + StorageDead(_26); + _30 = Not(move _29); + StorageDead(_29); + assume(move _30); + StorageDead(_30); + _31 = _25 as *mut T (PtrToPtr); + StorageDead(_25); + StorageDead(_24); + StorageLive(_39); + StorageLive(_32); + _32 = _21; + StorageLive(_33); + StorageLive(_38); + StorageLive(_37); + _33 = (_32.0: *const T); + StorageLive(_34); + _34 = _33 as *const u8 (PtrToPtr); + StorageLive(_36); + StorageLive(_35); + _35 = _34 as *const () (PtrToPtr); + _36 = move _35 as usize (Transmute); + StorageDead(_35); + _37 = Eq(move _36, const 0_usize); + StorageDead(_36); + StorageDead(_34); + _38 = Not(move _37); + StorageDead(_37); + assume(move _38); + StorageDead(_38); + _39 = _33 as *mut T (PtrToPtr); + StorageDead(_33); + StorageDead(_32); + _40 = Eq(move _31, move _39); + StorageDead(_39); + StorageDead(_31); + StorageDead(_23); + StorageDead(_22); + StorageDead(_21); + goto -> bb7; } bb6: { - StorageDead(_18); - StorageDead(_15); - drop(_2) -> [return: bb7, unwind unreachable]; + StorageLive(_41); + _41 = ((_15.0: std::slice::Iter<'_, T>).1: *const T); + StorageLive(_42); + _42 = _41 as *const () (PtrToPtr); + _43 = move _42 as usize (Transmute); + StorageDead(_42); + StorageDead(_41); + _40 = Eq(_43, const 0_usize); + goto -> bb7; } bb7: { - return; + StorageDead(_18); + switchInt(move _40) -> [0: bb8, otherwise: bb15]; } 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]; + StorageLive(_67); + StorageLive(_57); + StorageLive(_52); + StorageLive(_44); + _44 = const _; + switchInt(move _44) -> [0: bb9, otherwise: bb13]; } bb9: { - StorageDead(_22); - StorageDead(_21); - StorageDead(_18); - goto -> bb4; + StorageLive(_45); + _45 = &raw mut ((_15.0: std::slice::Iter<'_, T>).1: *const T); + _46 = _45 as *mut std::ptr::NonNull (PtrToPtr); + StorageDead(_45); + StorageLive(_51); + _47 = (*_46); + StorageLive(_48); + _48 = const _; + switchInt(move _48) -> [0: bb10, otherwise: bb11]; } bb10: { + StorageLive(_50); + StorageLive(_49); + _49 = (_47.0: *const T); + _50 = Offset(move _49, const -1_isize); + StorageDead(_49); + _51 = NonNull:: { pointer: move _50 }; + StorageDead(_50); + goto -> bb12; + } + + bb11: { + _51 = _47; + goto -> bb12; + } + + bb12: { + StorageDead(_48); + (*_46) = move _51; + StorageDead(_51); + _52 = (*_46); + goto -> bb14; + } + + bb13: { + StorageLive(_53); + _53 = &raw mut ((_15.0: std::slice::Iter<'_, T>).1: *const T); + _54 = _53 as *mut usize (PtrToPtr); + StorageDead(_53); + StorageLive(_56); + StorageLive(_55); + _55 = (*_54); + _56 = SubUnchecked(_55, const 1_usize); + StorageDead(_55); + (*_54) = move _56; + StorageDead(_56); + _52 = ((_15.0: std::slice::Iter<'_, T>).0: std::ptr::NonNull); + goto -> bb14; + } + + bb14: { + StorageDead(_44); + _57 = &_52; + StorageLive(_65); + StorageLive(_58); + _58 = _52; + StorageLive(_59); + StorageLive(_64); + StorageLive(_63); + _59 = (_58.0: *const T); + StorageLive(_60); + _60 = _59 as *const u8 (PtrToPtr); + StorageLive(_62); + StorageLive(_61); + _61 = _60 as *const () (PtrToPtr); + _62 = move _61 as usize (Transmute); + StorageDead(_61); + _63 = Eq(move _62, const 0_usize); + StorageDead(_62); + StorageDead(_60); + _64 = Not(move _63); + StorageDead(_63); + assume(move _64); + StorageDead(_64); + _65 = _59 as *mut T (PtrToPtr); + StorageDead(_59); + StorageDead(_58); + _66 = _65 as *const T (PointerCoercion(MutToConstPointer)); + StorageDead(_65); + _67 = &(*_66); + StorageDead(_57); + _68 = Option::<&T>::Some(move _67); + StorageDead(_67); + StorageDead(_52); + goto -> bb16; + } + + bb15: { + _68 = const {transmute(0x0000000000000000): Option<&T>}; + goto -> bb16; + } + + bb16: { + StorageDead(_40); + StorageDead(_43); + StorageDead(_17); + _69 = discriminant(_68); + switchInt(move _69) -> [0: bb17, 1: bb19, otherwise: bb21]; + } + + bb17: { + StorageDead(_68); + StorageDead(_15); + drop(_2) -> [return: bb18, unwind unreachable]; + } + + bb18: { + return; + } + + bb19: { + _70 = ((_68 as Some).0: &T); + StorageLive(_71); + _71 = &_2; + StorageLive(_72); + _72 = (_70,); + _73 = >::call(move _71, move _72) -> [return: bb20, unwind unreachable]; + } + + bb20: { + StorageDead(_72); + StorageDead(_71); + StorageDead(_68); + goto -> bb4; + } + + bb21: { 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 bbb979d23b36a..042ace881bee3 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 @@ -8,20 +8,215 @@ fn reverse_loop(_1: &[T], _2: impl Fn(&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 _68: std::option::Option<&T>; + let mut _69: isize; + let mut _71: &impl Fn(&T); + let mut _72: (&T,); + let _73: (); scope 1 { debug iter => _15; - let _20: &T; + let _70: &T; scope 2 { - debug x => _20; + debug x => _70; } scope 25 (inlined > as Iterator>::next) { debug self => _16; let mut _17: &mut std::slice::Iter<'_, T>; + scope 26 (inlined as DoubleEndedIterator>::next_back) { + debug self => _17; + let mut _18: bool; + let mut _19: *const *const T; + let mut _20: *const std::ptr::NonNull; + let mut _22: &std::ptr::NonNull; + let mut _23: &std::ptr::NonNull; + let mut _40: bool; + let mut _41: *const T; + let _52: std::ptr::NonNull; + let mut _57: &std::ptr::NonNull; + let mut _67: &T; + scope 27 { + scope 28 { + let _21: std::ptr::NonNull; + let _43: usize; + scope 29 { + debug len => _43; + } + scope 30 { + debug end => _21; + scope 36 (inlined as PartialEq>::eq) { + debug self => _22; + debug other => _23; + let mut _24: std::ptr::NonNull; + let mut _31: *mut T; + let mut _32: std::ptr::NonNull; + let mut _39: *mut T; + scope 37 (inlined NonNull::::as_ptr) { + debug self => _24; + let mut _25: *const T; + let mut _29: bool; + let mut _30: bool; + scope 38 { + scope 39 (inlined std::ptr::const_ptr::::is_null) { + debug self => _25; + let mut _26: *const u8; + scope 40 { + scope 41 (inlined std::ptr::const_ptr::::is_null::runtime_impl) { + debug ptr => _26; + let mut _28: usize; + scope 42 (inlined std::ptr::const_ptr::::addr) { + debug self => _26; + let mut _27: *const (); + scope 43 { + scope 44 (inlined std::ptr::const_ptr::::cast::<()>) { + debug self => _26; + } + } + } + } + } + } + } + } + scope 45 (inlined NonNull::::as_ptr) { + debug self => _32; + let mut _33: *const T; + let mut _37: bool; + let mut _38: bool; + scope 46 { + scope 47 (inlined std::ptr::const_ptr::::is_null) { + debug self => _33; + let mut _34: *const u8; + scope 48 { + scope 49 (inlined std::ptr::const_ptr::::is_null::runtime_impl) { + debug ptr => _34; + let mut _36: usize; + scope 50 (inlined std::ptr::const_ptr::::addr) { + debug self => _34; + let mut _35: *const (); + scope 51 { + scope 52 (inlined std::ptr::const_ptr::::cast::<()>) { + debug self => _34; + } + } + } + } + } + } + } + } + } + } + scope 31 { + scope 35 (inlined std::ptr::const_ptr::::cast::>) { + debug self => _19; + } + } + scope 32 (inlined std::ptr::const_ptr::::addr) { + debug self => _41; + let mut _42: *const (); + scope 33 { + scope 34 (inlined std::ptr::const_ptr::::cast::<()>) { + debug self => _41; + } + } + } + } + scope 53 (inlined std::slice::Iter::<'_, T>::pre_dec_end) { + debug self => _17; + debug offset => const 1_usize; + let mut _44: bool; + let mut _45: *mut *const T; + let mut _46: *mut std::ptr::NonNull; + let mut _47: std::ptr::NonNull; + let mut _51: std::ptr::NonNull; + let mut _53: *mut *const T; + let mut _54: *mut usize; + let mut _55: usize; + let mut _56: usize; + scope 54 { + scope 55 { + debug len => _54; + scope 57 { + scope 62 (inlined core::num::::unchecked_sub) { + debug self => _55; + debug rhs => const 1_usize; + scope 63 { + } + } + } + } + scope 56 { + scope 61 (inlined std::ptr::mut_ptr::::cast::) { + debug self => _53; + } + } + scope 58 { + debug end => _46; + scope 60 { + scope 65 (inlined NonNull::::sub) { + debug self => _47; + debug count => const 1_usize; + let mut _48: bool; + scope 66 { + scope 67 (inlined NonNull::::offset) { + debug self => _47; + debug count => const -1_isize; + let mut _49: *const T; + let mut _50: *const T; + scope 68 { + } + } + } + } + } + } + scope 59 { + scope 64 (inlined std::ptr::mut_ptr::::cast::>) { + debug self => _45; + } + } + } + } + scope 69 (inlined NonNull::::as_ref::<'_>) { + debug self => _57; + let mut _58: std::ptr::NonNull; + let mut _65: *mut T; + let _66: *const T; + scope 70 { + scope 71 (inlined NonNull::::as_ptr) { + debug self => _58; + let mut _59: *const T; + let mut _63: bool; + let mut _64: bool; + scope 72 { + scope 73 (inlined std::ptr::const_ptr::::is_null) { + debug self => _59; + let mut _60: *const u8; + scope 74 { + scope 75 (inlined std::ptr::const_ptr::::is_null::runtime_impl) { + debug ptr => _60; + let mut _62: usize; + scope 76 (inlined std::ptr::const_ptr::::addr) { + debug self => _60; + let mut _61: *const (); + scope 77 { + scope 78 (inlined std::ptr::const_ptr::::cast::<()>) { + debug self => _60; + } + } + } + } + } + } + } + } + scope 79 (inlined std::ptr::mut_ptr::::cast_const) { + debug self => _65; + } + } + } + } + } } } scope 3 (inlined core::slice::::iter) { @@ -49,15 +244,15 @@ fn reverse_loop(_1: &[T], _2: impl Fn(&T)) -> () { debug ptr => _9; scope 16 (inlined std::ptr::mut_ptr::::is_null) { debug self => _9; - let mut _24: *mut u8; + let mut _74: *mut u8; scope 17 { scope 18 (inlined std::ptr::mut_ptr::::is_null::runtime_impl) { - debug ptr => _24; + debug ptr => _74; scope 19 (inlined std::ptr::mut_ptr::::addr) { - debug self => _24; + debug self => _74; scope 20 { scope 21 (inlined std::ptr::mut_ptr::::cast::<()>) { - debug self => _24; + debug self => _74; } } } @@ -132,10 +327,10 @@ fn reverse_loop(_1: &[T], _2: impl Fn(&T)) -> () { StorageLive(_9); _9 = _4 as *mut T (PtrToPtr); StorageLive(_10); - StorageLive(_24); + StorageLive(_74); _10 = _9 as *const T (PointerCoercion(MutToConstPointer)); _11 = NonNull:: { pointer: _10 }; - StorageDead(_24); + StorageDead(_74); StorageDead(_10); StorageDead(_9); StorageLive(_12); @@ -153,54 +348,248 @@ fn reverse_loop(_1: &[T], _2: impl Fn(&T)) -> () { } bb4: { - StorageLive(_18); + StorageLive(_68); _16 = &mut _15; StorageLive(_17); _17 = &mut (_15.0: std::slice::Iter<'_, T>); - _18 = as DoubleEndedIterator>::next_back(move _17) -> [return: bb5, unwind: bb11]; + StorageLive(_43); + StorageLive(_40); + StorageLive(_18); + _18 = const _; + switchInt(move _18) -> [0: bb5, otherwise: bb6]; } bb5: { - StorageDead(_17); - _19 = discriminant(_18); - switchInt(move _19) -> [0: bb6, 1: bb8, otherwise: bb10]; + StorageLive(_21); + StorageLive(_19); + _19 = &raw const ((_15.0: std::slice::Iter<'_, T>).1: *const T); + _20 = _19 as *const std::ptr::NonNull (PtrToPtr); + StorageDead(_19); + _21 = (*_20); + StorageLive(_22); + _22 = &((_15.0: std::slice::Iter<'_, T>).0: std::ptr::NonNull); + StorageLive(_23); + _23 = &_21; + StorageLive(_31); + StorageLive(_24); + _24 = ((_15.0: std::slice::Iter<'_, T>).0: std::ptr::NonNull); + StorageLive(_25); + StorageLive(_30); + StorageLive(_29); + _25 = (_24.0: *const T); + StorageLive(_26); + _26 = _25 as *const u8 (PtrToPtr); + StorageLive(_28); + StorageLive(_27); + _27 = _26 as *const () (PtrToPtr); + _28 = move _27 as usize (Transmute); + StorageDead(_27); + _29 = Eq(move _28, const 0_usize); + StorageDead(_28); + StorageDead(_26); + _30 = Not(move _29); + StorageDead(_29); + assume(move _30); + StorageDead(_30); + _31 = _25 as *mut T (PtrToPtr); + StorageDead(_25); + StorageDead(_24); + StorageLive(_39); + StorageLive(_32); + _32 = _21; + StorageLive(_33); + StorageLive(_38); + StorageLive(_37); + _33 = (_32.0: *const T); + StorageLive(_34); + _34 = _33 as *const u8 (PtrToPtr); + StorageLive(_36); + StorageLive(_35); + _35 = _34 as *const () (PtrToPtr); + _36 = move _35 as usize (Transmute); + StorageDead(_35); + _37 = Eq(move _36, const 0_usize); + StorageDead(_36); + StorageDead(_34); + _38 = Not(move _37); + StorageDead(_37); + assume(move _38); + StorageDead(_38); + _39 = _33 as *mut T (PtrToPtr); + StorageDead(_33); + StorageDead(_32); + _40 = Eq(move _31, move _39); + StorageDead(_39); + StorageDead(_31); + StorageDead(_23); + StorageDead(_22); + StorageDead(_21); + goto -> bb7; } bb6: { - StorageDead(_18); - StorageDead(_15); - drop(_2) -> [return: bb7, unwind continue]; + StorageLive(_41); + _41 = ((_15.0: std::slice::Iter<'_, T>).1: *const T); + StorageLive(_42); + _42 = _41 as *const () (PtrToPtr); + _43 = move _42 as usize (Transmute); + StorageDead(_42); + StorageDead(_41); + _40 = Eq(_43, const 0_usize); + goto -> bb7; } bb7: { - return; + StorageDead(_18); + switchInt(move _40) -> [0: bb8, otherwise: bb15]; } 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]; + StorageLive(_67); + StorageLive(_57); + StorageLive(_52); + StorageLive(_44); + _44 = const _; + switchInt(move _44) -> [0: bb9, otherwise: bb13]; } bb9: { - StorageDead(_22); - StorageDead(_21); - StorageDead(_18); - goto -> bb4; + StorageLive(_45); + _45 = &raw mut ((_15.0: std::slice::Iter<'_, T>).1: *const T); + _46 = _45 as *mut std::ptr::NonNull (PtrToPtr); + StorageDead(_45); + StorageLive(_51); + _47 = (*_46); + StorageLive(_48); + _48 = const _; + switchInt(move _48) -> [0: bb10, otherwise: bb11]; } bb10: { - unreachable; + StorageLive(_50); + StorageLive(_49); + _49 = (_47.0: *const T); + _50 = Offset(move _49, const -1_isize); + StorageDead(_49); + _51 = NonNull:: { pointer: move _50 }; + StorageDead(_50); + goto -> bb12; + } + + bb11: { + _51 = _47; + goto -> bb12; } - bb11 (cleanup): { - drop(_2) -> [return: bb12, unwind terminate(cleanup)]; + bb12: { + StorageDead(_48); + (*_46) = move _51; + StorageDead(_51); + _52 = (*_46); + goto -> bb14; } - bb12 (cleanup): { + bb13: { + StorageLive(_53); + _53 = &raw mut ((_15.0: std::slice::Iter<'_, T>).1: *const T); + _54 = _53 as *mut usize (PtrToPtr); + StorageDead(_53); + StorageLive(_56); + StorageLive(_55); + _55 = (*_54); + _56 = SubUnchecked(_55, const 1_usize); + StorageDead(_55); + (*_54) = move _56; + StorageDead(_56); + _52 = ((_15.0: std::slice::Iter<'_, T>).0: std::ptr::NonNull); + goto -> bb14; + } + + bb14: { + StorageDead(_44); + _57 = &_52; + StorageLive(_65); + StorageLive(_58); + _58 = _52; + StorageLive(_59); + StorageLive(_64); + StorageLive(_63); + _59 = (_58.0: *const T); + StorageLive(_60); + _60 = _59 as *const u8 (PtrToPtr); + StorageLive(_62); + StorageLive(_61); + _61 = _60 as *const () (PtrToPtr); + _62 = move _61 as usize (Transmute); + StorageDead(_61); + _63 = Eq(move _62, const 0_usize); + StorageDead(_62); + StorageDead(_60); + _64 = Not(move _63); + StorageDead(_63); + assume(move _64); + StorageDead(_64); + _65 = _59 as *mut T (PtrToPtr); + StorageDead(_59); + StorageDead(_58); + _66 = _65 as *const T (PointerCoercion(MutToConstPointer)); + StorageDead(_65); + _67 = &(*_66); + StorageDead(_57); + _68 = Option::<&T>::Some(move _67); + StorageDead(_67); + StorageDead(_52); + goto -> bb16; + } + + bb15: { + _68 = const {transmute(0x0000000000000000): Option<&T>}; + goto -> bb16; + } + + bb16: { + StorageDead(_40); + StorageDead(_43); + StorageDead(_17); + _69 = discriminant(_68); + switchInt(move _69) -> [0: bb17, 1: bb19, otherwise: bb23]; + } + + bb17: { + StorageDead(_68); + StorageDead(_15); + drop(_2) -> [return: bb18, unwind continue]; + } + + bb18: { + return; + } + + bb19: { + _70 = ((_68 as Some).0: &T); + StorageLive(_71); + _71 = &_2; + StorageLive(_72); + _72 = (_70,); + _73 = >::call(move _71, move _72) -> [return: bb20, unwind: bb21]; + } + + bb20: { + StorageDead(_72); + StorageDead(_71); + StorageDead(_68); + goto -> bb4; + } + + bb21 (cleanup): { + drop(_2) -> [return: bb22, unwind terminate(cleanup)]; + } + + bb22 (cleanup): { resume; } + + bb23: { + unreachable; + } } diff --git a/tests/mir-opt/pre-codegen/slice_iter.slice_iter_mut_next_back.PreCodegen.after.panic-abort.mir b/tests/mir-opt/pre-codegen/slice_iter.slice_iter_mut_next_back.PreCodegen.after.panic-abort.mir index 78f96bf419559..733c398dcdcd9 100644 --- a/tests/mir-opt/pre-codegen/slice_iter.slice_iter_mut_next_back.PreCodegen.after.panic-abort.mir +++ b/tests/mir-opt/pre-codegen/slice_iter.slice_iter_mut_next_back.PreCodegen.after.panic-abort.mir @@ -3,12 +3,394 @@ fn slice_iter_mut_next_back(_1: &mut std::slice::IterMut<'_, T>) -> Option<&mut T> { debug it => _1; let mut _0: std::option::Option<&mut T>; + scope 1 (inlined as DoubleEndedIterator>::next_back) { + debug self => _1; + let mut _2: bool; + let mut _3: *const *mut T; + let mut _4: *const std::ptr::NonNull; + let mut _6: &std::ptr::NonNull; + let mut _7: &std::ptr::NonNull; + let mut _24: bool; + let mut _25: *mut T; + let mut _36: std::ptr::NonNull; + let mut _41: &mut std::ptr::NonNull; + let mut _50: &mut T; + scope 2 { + scope 3 { + let _5: std::ptr::NonNull; + let _27: usize; + scope 4 { + debug len => _27; + } + scope 5 { + debug end => _5; + scope 11 (inlined as PartialEq>::eq) { + debug self => _6; + debug other => _7; + let mut _8: std::ptr::NonNull; + let mut _15: *mut T; + let mut _16: std::ptr::NonNull; + let mut _23: *mut T; + scope 12 (inlined NonNull::::as_ptr) { + debug self => _8; + let mut _9: *const T; + let mut _13: bool; + let mut _14: bool; + scope 13 { + scope 14 (inlined std::ptr::const_ptr::::is_null) { + debug self => _9; + let mut _10: *const u8; + scope 15 { + scope 16 (inlined std::ptr::const_ptr::::is_null::runtime_impl) { + debug ptr => _10; + let mut _12: usize; + scope 17 (inlined std::ptr::const_ptr::::addr) { + debug self => _10; + let mut _11: *const (); + scope 18 { + scope 19 (inlined std::ptr::const_ptr::::cast::<()>) { + debug self => _10; + } + } + } + } + } + } + } + } + scope 20 (inlined NonNull::::as_ptr) { + debug self => _16; + let mut _17: *const T; + let mut _21: bool; + let mut _22: bool; + scope 21 { + scope 22 (inlined std::ptr::const_ptr::::is_null) { + debug self => _17; + let mut _18: *const u8; + scope 23 { + scope 24 (inlined std::ptr::const_ptr::::is_null::runtime_impl) { + debug ptr => _18; + let mut _20: usize; + scope 25 (inlined std::ptr::const_ptr::::addr) { + debug self => _18; + let mut _19: *const (); + scope 26 { + scope 27 (inlined std::ptr::const_ptr::::cast::<()>) { + debug self => _18; + } + } + } + } + } + } + } + } + } + } + scope 6 { + scope 10 (inlined std::ptr::const_ptr::::cast::>) { + debug self => _3; + } + } + scope 7 (inlined std::ptr::mut_ptr::::addr) { + debug self => _25; + let mut _26: *mut (); + scope 8 { + scope 9 (inlined std::ptr::mut_ptr::::cast::<()>) { + debug self => _25; + } + } + } + } + scope 28 (inlined std::slice::IterMut::<'_, T>::pre_dec_end) { + debug self => _1; + debug offset => const 1_usize; + let mut _28: bool; + let mut _29: *mut *mut T; + let mut _30: *mut std::ptr::NonNull; + let mut _31: std::ptr::NonNull; + let mut _35: std::ptr::NonNull; + let mut _37: *mut *mut T; + let mut _38: *mut usize; + let mut _39: usize; + let mut _40: usize; + scope 29 { + scope 30 { + debug len => _38; + scope 32 { + scope 37 (inlined core::num::::unchecked_sub) { + debug self => _39; + debug rhs => const 1_usize; + scope 38 { + } + } + } + } + scope 31 { + scope 36 (inlined std::ptr::mut_ptr::::cast::) { + debug self => _37; + } + } + scope 33 { + debug end => _30; + scope 35 { + scope 40 (inlined NonNull::::sub) { + debug self => _31; + debug count => const 1_usize; + let mut _32: bool; + scope 41 { + scope 42 (inlined NonNull::::offset) { + debug self => _31; + debug count => const -1_isize; + let mut _33: *const T; + let mut _34: *const T; + scope 43 { + } + } + } + } + } + } + scope 34 { + scope 39 (inlined std::ptr::mut_ptr::::cast::>) { + debug self => _29; + } + } + } + } + scope 44 (inlined NonNull::::as_mut::<'_>) { + debug self => _41; + let mut _42: std::ptr::NonNull; + let mut _49: *mut T; + scope 45 { + scope 46 (inlined NonNull::::as_ptr) { + debug self => _42; + let mut _43: *const T; + let mut _47: bool; + let mut _48: bool; + scope 47 { + scope 48 (inlined std::ptr::const_ptr::::is_null) { + debug self => _43; + let mut _44: *const u8; + scope 49 { + scope 50 (inlined std::ptr::const_ptr::::is_null::runtime_impl) { + debug ptr => _44; + let mut _46: usize; + scope 51 (inlined std::ptr::const_ptr::::addr) { + debug self => _44; + let mut _45: *const (); + scope 52 { + scope 53 (inlined std::ptr::const_ptr::::cast::<()>) { + debug self => _44; + } + } + } + } + } + } + } + } + } + } + } + } bb0: { - _0 = as DoubleEndedIterator>::next_back(move _1) -> [return: bb1, unwind unreachable]; + StorageLive(_27); + StorageLive(_24); + StorageLive(_2); + _2 = const _; + switchInt(move _2) -> [0: bb1, otherwise: bb2]; } bb1: { + StorageLive(_5); + StorageLive(_3); + _3 = &raw const ((*_1).1: *mut T); + _4 = _3 as *const std::ptr::NonNull (PtrToPtr); + StorageDead(_3); + _5 = (*_4); + StorageLive(_6); + _6 = &((*_1).0: std::ptr::NonNull); + StorageLive(_7); + _7 = &_5; + StorageLive(_15); + StorageLive(_8); + _8 = ((*_1).0: std::ptr::NonNull); + StorageLive(_9); + StorageLive(_14); + StorageLive(_13); + _9 = (_8.0: *const T); + StorageLive(_10); + _10 = _9 as *const u8 (PtrToPtr); + StorageLive(_12); + StorageLive(_11); + _11 = _10 as *const () (PtrToPtr); + _12 = move _11 as usize (Transmute); + StorageDead(_11); + _13 = Eq(move _12, const 0_usize); + StorageDead(_12); + StorageDead(_10); + _14 = Not(move _13); + StorageDead(_13); + assume(move _14); + StorageDead(_14); + _15 = _9 as *mut T (PtrToPtr); + StorageDead(_9); + StorageDead(_8); + StorageLive(_23); + StorageLive(_16); + _16 = _5; + StorageLive(_17); + StorageLive(_22); + StorageLive(_21); + _17 = (_16.0: *const T); + StorageLive(_18); + _18 = _17 as *const u8 (PtrToPtr); + StorageLive(_20); + StorageLive(_19); + _19 = _18 as *const () (PtrToPtr); + _20 = move _19 as usize (Transmute); + StorageDead(_19); + _21 = Eq(move _20, const 0_usize); + StorageDead(_20); + StorageDead(_18); + _22 = Not(move _21); + StorageDead(_21); + assume(move _22); + StorageDead(_22); + _23 = _17 as *mut T (PtrToPtr); + StorageDead(_17); + StorageDead(_16); + _24 = Eq(move _15, move _23); + StorageDead(_23); + StorageDead(_15); + StorageDead(_7); + StorageDead(_6); + StorageDead(_5); + goto -> bb3; + } + + bb2: { + StorageLive(_25); + _25 = ((*_1).1: *mut T); + StorageLive(_26); + _26 = _25 as *mut () (PtrToPtr); + _27 = move _26 as usize (Transmute); + StorageDead(_26); + StorageDead(_25); + _24 = Eq(_27, const 0_usize); + goto -> bb3; + } + + bb3: { + StorageDead(_2); + switchInt(move _24) -> [0: bb4, otherwise: bb11]; + } + + bb4: { + StorageLive(_50); + StorageLive(_41); + StorageLive(_36); + StorageLive(_28); + _28 = const _; + switchInt(move _28) -> [0: bb5, otherwise: bb9]; + } + + bb5: { + StorageLive(_29); + _29 = &raw mut ((*_1).1: *mut T); + _30 = _29 as *mut std::ptr::NonNull (PtrToPtr); + StorageDead(_29); + StorageLive(_35); + _31 = (*_30); + StorageLive(_32); + _32 = const _; + switchInt(move _32) -> [0: bb6, otherwise: bb7]; + } + + bb6: { + StorageLive(_34); + StorageLive(_33); + _33 = (_31.0: *const T); + _34 = Offset(move _33, const -1_isize); + StorageDead(_33); + _35 = NonNull:: { pointer: move _34 }; + StorageDead(_34); + goto -> bb8; + } + + bb7: { + _35 = _31; + goto -> bb8; + } + + bb8: { + StorageDead(_32); + (*_30) = move _35; + StorageDead(_35); + _36 = (*_30); + goto -> bb10; + } + + bb9: { + StorageLive(_37); + _37 = &raw mut ((*_1).1: *mut T); + _38 = _37 as *mut usize (PtrToPtr); + StorageDead(_37); + StorageLive(_40); + StorageLive(_39); + _39 = (*_38); + _40 = SubUnchecked(_39, const 1_usize); + StorageDead(_39); + (*_38) = move _40; + StorageDead(_40); + _36 = ((*_1).0: std::ptr::NonNull); + goto -> bb10; + } + + bb10: { + StorageDead(_28); + _41 = &mut _36; + StorageLive(_42); + _42 = _36; + StorageLive(_43); + StorageLive(_48); + StorageLive(_47); + _43 = (_42.0: *const T); + StorageLive(_44); + _44 = _43 as *const u8 (PtrToPtr); + StorageLive(_46); + StorageLive(_45); + _45 = _44 as *const () (PtrToPtr); + _46 = move _45 as usize (Transmute); + StorageDead(_45); + _47 = Eq(move _46, const 0_usize); + StorageDead(_46); + StorageDead(_44); + _48 = Not(move _47); + StorageDead(_47); + assume(move _48); + StorageDead(_48); + _49 = _43 as *mut T (PtrToPtr); + StorageDead(_43); + StorageDead(_42); + _50 = &mut (*_49); + StorageDead(_41); + _0 = Option::<&mut T>::Some(move _50); + StorageDead(_50); + StorageDead(_36); + goto -> bb12; + } + + bb11: { + _0 = const {transmute(0x0000000000000000): Option<&mut T>}; + goto -> bb12; + } + + bb12: { + StorageDead(_24); + StorageDead(_27); return; } } diff --git a/tests/mir-opt/pre-codegen/slice_iter.slice_iter_mut_next_back.PreCodegen.after.panic-unwind.mir b/tests/mir-opt/pre-codegen/slice_iter.slice_iter_mut_next_back.PreCodegen.after.panic-unwind.mir index dfe5e206fadaf..733c398dcdcd9 100644 --- a/tests/mir-opt/pre-codegen/slice_iter.slice_iter_mut_next_back.PreCodegen.after.panic-unwind.mir +++ b/tests/mir-opt/pre-codegen/slice_iter.slice_iter_mut_next_back.PreCodegen.after.panic-unwind.mir @@ -3,12 +3,394 @@ fn slice_iter_mut_next_back(_1: &mut std::slice::IterMut<'_, T>) -> Option<&mut T> { debug it => _1; let mut _0: std::option::Option<&mut T>; + scope 1 (inlined as DoubleEndedIterator>::next_back) { + debug self => _1; + let mut _2: bool; + let mut _3: *const *mut T; + let mut _4: *const std::ptr::NonNull; + let mut _6: &std::ptr::NonNull; + let mut _7: &std::ptr::NonNull; + let mut _24: bool; + let mut _25: *mut T; + let mut _36: std::ptr::NonNull; + let mut _41: &mut std::ptr::NonNull; + let mut _50: &mut T; + scope 2 { + scope 3 { + let _5: std::ptr::NonNull; + let _27: usize; + scope 4 { + debug len => _27; + } + scope 5 { + debug end => _5; + scope 11 (inlined as PartialEq>::eq) { + debug self => _6; + debug other => _7; + let mut _8: std::ptr::NonNull; + let mut _15: *mut T; + let mut _16: std::ptr::NonNull; + let mut _23: *mut T; + scope 12 (inlined NonNull::::as_ptr) { + debug self => _8; + let mut _9: *const T; + let mut _13: bool; + let mut _14: bool; + scope 13 { + scope 14 (inlined std::ptr::const_ptr::::is_null) { + debug self => _9; + let mut _10: *const u8; + scope 15 { + scope 16 (inlined std::ptr::const_ptr::::is_null::runtime_impl) { + debug ptr => _10; + let mut _12: usize; + scope 17 (inlined std::ptr::const_ptr::::addr) { + debug self => _10; + let mut _11: *const (); + scope 18 { + scope 19 (inlined std::ptr::const_ptr::::cast::<()>) { + debug self => _10; + } + } + } + } + } + } + } + } + scope 20 (inlined NonNull::::as_ptr) { + debug self => _16; + let mut _17: *const T; + let mut _21: bool; + let mut _22: bool; + scope 21 { + scope 22 (inlined std::ptr::const_ptr::::is_null) { + debug self => _17; + let mut _18: *const u8; + scope 23 { + scope 24 (inlined std::ptr::const_ptr::::is_null::runtime_impl) { + debug ptr => _18; + let mut _20: usize; + scope 25 (inlined std::ptr::const_ptr::::addr) { + debug self => _18; + let mut _19: *const (); + scope 26 { + scope 27 (inlined std::ptr::const_ptr::::cast::<()>) { + debug self => _18; + } + } + } + } + } + } + } + } + } + } + scope 6 { + scope 10 (inlined std::ptr::const_ptr::::cast::>) { + debug self => _3; + } + } + scope 7 (inlined std::ptr::mut_ptr::::addr) { + debug self => _25; + let mut _26: *mut (); + scope 8 { + scope 9 (inlined std::ptr::mut_ptr::::cast::<()>) { + debug self => _25; + } + } + } + } + scope 28 (inlined std::slice::IterMut::<'_, T>::pre_dec_end) { + debug self => _1; + debug offset => const 1_usize; + let mut _28: bool; + let mut _29: *mut *mut T; + let mut _30: *mut std::ptr::NonNull; + let mut _31: std::ptr::NonNull; + let mut _35: std::ptr::NonNull; + let mut _37: *mut *mut T; + let mut _38: *mut usize; + let mut _39: usize; + let mut _40: usize; + scope 29 { + scope 30 { + debug len => _38; + scope 32 { + scope 37 (inlined core::num::::unchecked_sub) { + debug self => _39; + debug rhs => const 1_usize; + scope 38 { + } + } + } + } + scope 31 { + scope 36 (inlined std::ptr::mut_ptr::::cast::) { + debug self => _37; + } + } + scope 33 { + debug end => _30; + scope 35 { + scope 40 (inlined NonNull::::sub) { + debug self => _31; + debug count => const 1_usize; + let mut _32: bool; + scope 41 { + scope 42 (inlined NonNull::::offset) { + debug self => _31; + debug count => const -1_isize; + let mut _33: *const T; + let mut _34: *const T; + scope 43 { + } + } + } + } + } + } + scope 34 { + scope 39 (inlined std::ptr::mut_ptr::::cast::>) { + debug self => _29; + } + } + } + } + scope 44 (inlined NonNull::::as_mut::<'_>) { + debug self => _41; + let mut _42: std::ptr::NonNull; + let mut _49: *mut T; + scope 45 { + scope 46 (inlined NonNull::::as_ptr) { + debug self => _42; + let mut _43: *const T; + let mut _47: bool; + let mut _48: bool; + scope 47 { + scope 48 (inlined std::ptr::const_ptr::::is_null) { + debug self => _43; + let mut _44: *const u8; + scope 49 { + scope 50 (inlined std::ptr::const_ptr::::is_null::runtime_impl) { + debug ptr => _44; + let mut _46: usize; + scope 51 (inlined std::ptr::const_ptr::::addr) { + debug self => _44; + let mut _45: *const (); + scope 52 { + scope 53 (inlined std::ptr::const_ptr::::cast::<()>) { + debug self => _44; + } + } + } + } + } + } + } + } + } + } + } + } bb0: { - _0 = as DoubleEndedIterator>::next_back(move _1) -> [return: bb1, unwind continue]; + StorageLive(_27); + StorageLive(_24); + StorageLive(_2); + _2 = const _; + switchInt(move _2) -> [0: bb1, otherwise: bb2]; } bb1: { + StorageLive(_5); + StorageLive(_3); + _3 = &raw const ((*_1).1: *mut T); + _4 = _3 as *const std::ptr::NonNull (PtrToPtr); + StorageDead(_3); + _5 = (*_4); + StorageLive(_6); + _6 = &((*_1).0: std::ptr::NonNull); + StorageLive(_7); + _7 = &_5; + StorageLive(_15); + StorageLive(_8); + _8 = ((*_1).0: std::ptr::NonNull); + StorageLive(_9); + StorageLive(_14); + StorageLive(_13); + _9 = (_8.0: *const T); + StorageLive(_10); + _10 = _9 as *const u8 (PtrToPtr); + StorageLive(_12); + StorageLive(_11); + _11 = _10 as *const () (PtrToPtr); + _12 = move _11 as usize (Transmute); + StorageDead(_11); + _13 = Eq(move _12, const 0_usize); + StorageDead(_12); + StorageDead(_10); + _14 = Not(move _13); + StorageDead(_13); + assume(move _14); + StorageDead(_14); + _15 = _9 as *mut T (PtrToPtr); + StorageDead(_9); + StorageDead(_8); + StorageLive(_23); + StorageLive(_16); + _16 = _5; + StorageLive(_17); + StorageLive(_22); + StorageLive(_21); + _17 = (_16.0: *const T); + StorageLive(_18); + _18 = _17 as *const u8 (PtrToPtr); + StorageLive(_20); + StorageLive(_19); + _19 = _18 as *const () (PtrToPtr); + _20 = move _19 as usize (Transmute); + StorageDead(_19); + _21 = Eq(move _20, const 0_usize); + StorageDead(_20); + StorageDead(_18); + _22 = Not(move _21); + StorageDead(_21); + assume(move _22); + StorageDead(_22); + _23 = _17 as *mut T (PtrToPtr); + StorageDead(_17); + StorageDead(_16); + _24 = Eq(move _15, move _23); + StorageDead(_23); + StorageDead(_15); + StorageDead(_7); + StorageDead(_6); + StorageDead(_5); + goto -> bb3; + } + + bb2: { + StorageLive(_25); + _25 = ((*_1).1: *mut T); + StorageLive(_26); + _26 = _25 as *mut () (PtrToPtr); + _27 = move _26 as usize (Transmute); + StorageDead(_26); + StorageDead(_25); + _24 = Eq(_27, const 0_usize); + goto -> bb3; + } + + bb3: { + StorageDead(_2); + switchInt(move _24) -> [0: bb4, otherwise: bb11]; + } + + bb4: { + StorageLive(_50); + StorageLive(_41); + StorageLive(_36); + StorageLive(_28); + _28 = const _; + switchInt(move _28) -> [0: bb5, otherwise: bb9]; + } + + bb5: { + StorageLive(_29); + _29 = &raw mut ((*_1).1: *mut T); + _30 = _29 as *mut std::ptr::NonNull (PtrToPtr); + StorageDead(_29); + StorageLive(_35); + _31 = (*_30); + StorageLive(_32); + _32 = const _; + switchInt(move _32) -> [0: bb6, otherwise: bb7]; + } + + bb6: { + StorageLive(_34); + StorageLive(_33); + _33 = (_31.0: *const T); + _34 = Offset(move _33, const -1_isize); + StorageDead(_33); + _35 = NonNull:: { pointer: move _34 }; + StorageDead(_34); + goto -> bb8; + } + + bb7: { + _35 = _31; + goto -> bb8; + } + + bb8: { + StorageDead(_32); + (*_30) = move _35; + StorageDead(_35); + _36 = (*_30); + goto -> bb10; + } + + bb9: { + StorageLive(_37); + _37 = &raw mut ((*_1).1: *mut T); + _38 = _37 as *mut usize (PtrToPtr); + StorageDead(_37); + StorageLive(_40); + StorageLive(_39); + _39 = (*_38); + _40 = SubUnchecked(_39, const 1_usize); + StorageDead(_39); + (*_38) = move _40; + StorageDead(_40); + _36 = ((*_1).0: std::ptr::NonNull); + goto -> bb10; + } + + bb10: { + StorageDead(_28); + _41 = &mut _36; + StorageLive(_42); + _42 = _36; + StorageLive(_43); + StorageLive(_48); + StorageLive(_47); + _43 = (_42.0: *const T); + StorageLive(_44); + _44 = _43 as *const u8 (PtrToPtr); + StorageLive(_46); + StorageLive(_45); + _45 = _44 as *const () (PtrToPtr); + _46 = move _45 as usize (Transmute); + StorageDead(_45); + _47 = Eq(move _46, const 0_usize); + StorageDead(_46); + StorageDead(_44); + _48 = Not(move _47); + StorageDead(_47); + assume(move _48); + StorageDead(_48); + _49 = _43 as *mut T (PtrToPtr); + StorageDead(_43); + StorageDead(_42); + _50 = &mut (*_49); + StorageDead(_41); + _0 = Option::<&mut T>::Some(move _50); + StorageDead(_50); + StorageDead(_36); + goto -> bb12; + } + + bb11: { + _0 = const {transmute(0x0000000000000000): Option<&mut T>}; + goto -> bb12; + } + + bb12: { + StorageDead(_24); + StorageDead(_27); return; } } diff --git a/tests/mir-opt/pre-codegen/slice_iter.slice_iter_next.PreCodegen.after.panic-abort.mir b/tests/mir-opt/pre-codegen/slice_iter.slice_iter_next.PreCodegen.after.panic-abort.mir index 8edac638ccdd6..7293c7649c630 100644 --- a/tests/mir-opt/pre-codegen/slice_iter.slice_iter_next.PreCodegen.after.panic-abort.mir +++ b/tests/mir-opt/pre-codegen/slice_iter.slice_iter_next.PreCodegen.after.panic-abort.mir @@ -3,12 +3,382 @@ fn slice_iter_next(_1: &mut std::slice::Iter<'_, T>) -> Option<&T> { debug it => _1; let mut _0: std::option::Option<&T>; + scope 1 (inlined as Iterator>::next) { + debug self => _1; + let mut _2: bool; + let mut _3: *const *const T; + let mut _4: *const std::ptr::NonNull; + let mut _6: &std::ptr::NonNull; + let mut _7: &std::ptr::NonNull; + let mut _24: bool; + let mut _25: *const T; + let _28: std::ptr::NonNull; + let mut _40: &std::ptr::NonNull; + let mut _50: &T; + scope 2 { + scope 3 { + let _5: std::ptr::NonNull; + let _27: usize; + scope 4 { + debug len => _27; + } + scope 5 { + debug end => _5; + scope 11 (inlined as PartialEq>::eq) { + debug self => _6; + debug other => _7; + let mut _8: std::ptr::NonNull; + let mut _15: *mut T; + let mut _16: std::ptr::NonNull; + let mut _23: *mut T; + scope 12 (inlined NonNull::::as_ptr) { + debug self => _8; + let mut _9: *const T; + let mut _13: bool; + let mut _14: bool; + scope 13 { + scope 14 (inlined std::ptr::const_ptr::::is_null) { + debug self => _9; + let mut _10: *const u8; + scope 15 { + scope 16 (inlined std::ptr::const_ptr::::is_null::runtime_impl) { + debug ptr => _10; + let mut _12: usize; + scope 17 (inlined std::ptr::const_ptr::::addr) { + debug self => _10; + let mut _11: *const (); + scope 18 { + scope 19 (inlined std::ptr::const_ptr::::cast::<()>) { + debug self => _10; + } + } + } + } + } + } + } + } + scope 20 (inlined NonNull::::as_ptr) { + debug self => _16; + let mut _17: *const T; + let mut _21: bool; + let mut _22: bool; + scope 21 { + scope 22 (inlined std::ptr::const_ptr::::is_null) { + debug self => _17; + let mut _18: *const u8; + scope 23 { + scope 24 (inlined std::ptr::const_ptr::::is_null::runtime_impl) { + debug ptr => _18; + let mut _20: usize; + scope 25 (inlined std::ptr::const_ptr::::addr) { + debug self => _18; + let mut _19: *const (); + scope 26 { + scope 27 (inlined std::ptr::const_ptr::::cast::<()>) { + debug self => _18; + } + } + } + } + } + } + } + } + } + } + scope 6 { + scope 10 (inlined std::ptr::const_ptr::::cast::>) { + debug self => _3; + } + } + scope 7 (inlined std::ptr::const_ptr::::addr) { + debug self => _25; + let mut _26: *const (); + scope 8 { + scope 9 (inlined std::ptr::const_ptr::::cast::<()>) { + debug self => _25; + } + } + } + } + scope 28 (inlined std::slice::Iter::<'_, T>::post_inc_start) { + debug self => _1; + debug offset => const 1_usize; + let mut _29: bool; + let mut _30: *mut *const T; + let mut _31: *mut std::ptr::NonNull; + let mut _32: std::ptr::NonNull; + let mut _35: std::ptr::NonNull; + let mut _36: *mut *const T; + let mut _37: *mut usize; + let mut _38: usize; + let mut _39: usize; + scope 29 { + debug old => _28; + scope 30 { + scope 31 { + scope 32 { + debug len => _37; + scope 37 (inlined core::num::::unchecked_sub) { + debug self => _38; + debug rhs => const 1_usize; + scope 38 { + } + } + } + scope 33 { + scope 36 (inlined std::ptr::mut_ptr::::cast::) { + debug self => _36; + } + } + scope 34 { + debug _end => _31; + scope 40 (inlined NonNull::::add) { + debug self => _32; + debug count => const 1_usize; + let mut _33: *const T; + let mut _34: *const T; + scope 41 { + } + } + } + scope 35 { + scope 39 (inlined std::ptr::mut_ptr::::cast::>) { + debug self => _30; + } + } + } + } + } + } + scope 42 (inlined NonNull::::as_ref::<'_>) { + debug self => _40; + let mut _41: std::ptr::NonNull; + let mut _48: *mut T; + let _49: *const T; + scope 43 { + scope 44 (inlined NonNull::::as_ptr) { + debug self => _41; + let mut _42: *const T; + let mut _46: bool; + let mut _47: bool; + scope 45 { + scope 46 (inlined std::ptr::const_ptr::::is_null) { + debug self => _42; + let mut _43: *const u8; + scope 47 { + scope 48 (inlined std::ptr::const_ptr::::is_null::runtime_impl) { + debug ptr => _43; + let mut _45: usize; + scope 49 (inlined std::ptr::const_ptr::::addr) { + debug self => _43; + let mut _44: *const (); + scope 50 { + scope 51 (inlined std::ptr::const_ptr::::cast::<()>) { + debug self => _43; + } + } + } + } + } + } + } + } + scope 52 (inlined std::ptr::mut_ptr::::cast_const) { + debug self => _48; + } + } + } + } + } bb0: { - _0 = as Iterator>::next(move _1) -> [return: bb1, unwind unreachable]; + StorageLive(_27); + StorageLive(_24); + StorageLive(_2); + _2 = const _; + switchInt(move _2) -> [0: bb1, otherwise: bb2]; } bb1: { + StorageLive(_5); + StorageLive(_3); + _3 = &raw const ((*_1).1: *const T); + _4 = _3 as *const std::ptr::NonNull (PtrToPtr); + StorageDead(_3); + _5 = (*_4); + StorageLive(_6); + _6 = &((*_1).0: std::ptr::NonNull); + StorageLive(_7); + _7 = &_5; + StorageLive(_15); + StorageLive(_8); + _8 = ((*_1).0: std::ptr::NonNull); + StorageLive(_9); + StorageLive(_14); + StorageLive(_13); + _9 = (_8.0: *const T); + StorageLive(_10); + _10 = _9 as *const u8 (PtrToPtr); + StorageLive(_12); + StorageLive(_11); + _11 = _10 as *const () (PtrToPtr); + _12 = move _11 as usize (Transmute); + StorageDead(_11); + _13 = Eq(move _12, const 0_usize); + StorageDead(_12); + StorageDead(_10); + _14 = Not(move _13); + StorageDead(_13); + assume(move _14); + StorageDead(_14); + _15 = _9 as *mut T (PtrToPtr); + StorageDead(_9); + StorageDead(_8); + StorageLive(_23); + StorageLive(_16); + _16 = _5; + StorageLive(_17); + StorageLive(_22); + StorageLive(_21); + _17 = (_16.0: *const T); + StorageLive(_18); + _18 = _17 as *const u8 (PtrToPtr); + StorageLive(_20); + StorageLive(_19); + _19 = _18 as *const () (PtrToPtr); + _20 = move _19 as usize (Transmute); + StorageDead(_19); + _21 = Eq(move _20, const 0_usize); + StorageDead(_20); + StorageDead(_18); + _22 = Not(move _21); + StorageDead(_21); + assume(move _22); + StorageDead(_22); + _23 = _17 as *mut T (PtrToPtr); + StorageDead(_17); + StorageDead(_16); + _24 = Eq(move _15, move _23); + StorageDead(_23); + StorageDead(_15); + StorageDead(_7); + StorageDead(_6); + StorageDead(_5); + goto -> bb3; + } + + bb2: { + StorageLive(_25); + _25 = ((*_1).1: *const T); + StorageLive(_26); + _26 = _25 as *const () (PtrToPtr); + _27 = move _26 as usize (Transmute); + StorageDead(_26); + StorageDead(_25); + _24 = Eq(_27, const 0_usize); + goto -> bb3; + } + + bb3: { + StorageDead(_2); + switchInt(move _24) -> [0: bb4, otherwise: bb8]; + } + + bb4: { + StorageLive(_50); + StorageLive(_40); + StorageLive(_28); + StorageLive(_31); + _28 = ((*_1).0: std::ptr::NonNull); + StorageLive(_29); + _29 = const _; + switchInt(move _29) -> [0: bb5, otherwise: bb6]; + } + + bb5: { + StorageLive(_30); + _30 = &raw mut ((*_1).1: *const T); + _31 = _30 as *mut std::ptr::NonNull (PtrToPtr); + StorageDead(_30); + StorageLive(_35); + StorageLive(_32); + _32 = ((*_1).0: std::ptr::NonNull); + StorageLive(_34); + StorageLive(_33); + _33 = (_32.0: *const T); + _34 = Offset(move _33, const 1_usize); + StorageDead(_33); + _35 = NonNull:: { pointer: move _34 }; + StorageDead(_34); + StorageDead(_32); + ((*_1).0: std::ptr::NonNull) = move _35; + StorageDead(_35); + goto -> bb7; + } + + bb6: { + StorageLive(_36); + _36 = &raw mut ((*_1).1: *const T); + _37 = _36 as *mut usize (PtrToPtr); + StorageDead(_36); + StorageLive(_39); + StorageLive(_38); + _38 = (*_37); + _39 = SubUnchecked(_38, const 1_usize); + StorageDead(_38); + (*_37) = move _39; + StorageDead(_39); + goto -> bb7; + } + + bb7: { + StorageDead(_29); + StorageDead(_31); + _40 = &_28; + StorageLive(_48); + StorageLive(_41); + _41 = _28; + StorageLive(_42); + StorageLive(_47); + StorageLive(_46); + _42 = (_41.0: *const T); + StorageLive(_43); + _43 = _42 as *const u8 (PtrToPtr); + StorageLive(_45); + StorageLive(_44); + _44 = _43 as *const () (PtrToPtr); + _45 = move _44 as usize (Transmute); + StorageDead(_44); + _46 = Eq(move _45, const 0_usize); + StorageDead(_45); + StorageDead(_43); + _47 = Not(move _46); + StorageDead(_46); + assume(move _47); + StorageDead(_47); + _48 = _42 as *mut T (PtrToPtr); + StorageDead(_42); + StorageDead(_41); + _49 = _48 as *const T (PointerCoercion(MutToConstPointer)); + StorageDead(_48); + _50 = &(*_49); + StorageDead(_40); + _0 = Option::<&T>::Some(move _50); + StorageDead(_50); + StorageDead(_28); + goto -> bb9; + } + + bb8: { + _0 = const {transmute(0x0000000000000000): Option<&T>}; + goto -> bb9; + } + + bb9: { + StorageDead(_24); + StorageDead(_27); return; } } diff --git a/tests/mir-opt/pre-codegen/slice_iter.slice_iter_next.PreCodegen.after.panic-unwind.mir b/tests/mir-opt/pre-codegen/slice_iter.slice_iter_next.PreCodegen.after.panic-unwind.mir index fdde07173437b..7293c7649c630 100644 --- a/tests/mir-opt/pre-codegen/slice_iter.slice_iter_next.PreCodegen.after.panic-unwind.mir +++ b/tests/mir-opt/pre-codegen/slice_iter.slice_iter_next.PreCodegen.after.panic-unwind.mir @@ -3,12 +3,382 @@ fn slice_iter_next(_1: &mut std::slice::Iter<'_, T>) -> Option<&T> { debug it => _1; let mut _0: std::option::Option<&T>; + scope 1 (inlined as Iterator>::next) { + debug self => _1; + let mut _2: bool; + let mut _3: *const *const T; + let mut _4: *const std::ptr::NonNull; + let mut _6: &std::ptr::NonNull; + let mut _7: &std::ptr::NonNull; + let mut _24: bool; + let mut _25: *const T; + let _28: std::ptr::NonNull; + let mut _40: &std::ptr::NonNull; + let mut _50: &T; + scope 2 { + scope 3 { + let _5: std::ptr::NonNull; + let _27: usize; + scope 4 { + debug len => _27; + } + scope 5 { + debug end => _5; + scope 11 (inlined as PartialEq>::eq) { + debug self => _6; + debug other => _7; + let mut _8: std::ptr::NonNull; + let mut _15: *mut T; + let mut _16: std::ptr::NonNull; + let mut _23: *mut T; + scope 12 (inlined NonNull::::as_ptr) { + debug self => _8; + let mut _9: *const T; + let mut _13: bool; + let mut _14: bool; + scope 13 { + scope 14 (inlined std::ptr::const_ptr::::is_null) { + debug self => _9; + let mut _10: *const u8; + scope 15 { + scope 16 (inlined std::ptr::const_ptr::::is_null::runtime_impl) { + debug ptr => _10; + let mut _12: usize; + scope 17 (inlined std::ptr::const_ptr::::addr) { + debug self => _10; + let mut _11: *const (); + scope 18 { + scope 19 (inlined std::ptr::const_ptr::::cast::<()>) { + debug self => _10; + } + } + } + } + } + } + } + } + scope 20 (inlined NonNull::::as_ptr) { + debug self => _16; + let mut _17: *const T; + let mut _21: bool; + let mut _22: bool; + scope 21 { + scope 22 (inlined std::ptr::const_ptr::::is_null) { + debug self => _17; + let mut _18: *const u8; + scope 23 { + scope 24 (inlined std::ptr::const_ptr::::is_null::runtime_impl) { + debug ptr => _18; + let mut _20: usize; + scope 25 (inlined std::ptr::const_ptr::::addr) { + debug self => _18; + let mut _19: *const (); + scope 26 { + scope 27 (inlined std::ptr::const_ptr::::cast::<()>) { + debug self => _18; + } + } + } + } + } + } + } + } + } + } + scope 6 { + scope 10 (inlined std::ptr::const_ptr::::cast::>) { + debug self => _3; + } + } + scope 7 (inlined std::ptr::const_ptr::::addr) { + debug self => _25; + let mut _26: *const (); + scope 8 { + scope 9 (inlined std::ptr::const_ptr::::cast::<()>) { + debug self => _25; + } + } + } + } + scope 28 (inlined std::slice::Iter::<'_, T>::post_inc_start) { + debug self => _1; + debug offset => const 1_usize; + let mut _29: bool; + let mut _30: *mut *const T; + let mut _31: *mut std::ptr::NonNull; + let mut _32: std::ptr::NonNull; + let mut _35: std::ptr::NonNull; + let mut _36: *mut *const T; + let mut _37: *mut usize; + let mut _38: usize; + let mut _39: usize; + scope 29 { + debug old => _28; + scope 30 { + scope 31 { + scope 32 { + debug len => _37; + scope 37 (inlined core::num::::unchecked_sub) { + debug self => _38; + debug rhs => const 1_usize; + scope 38 { + } + } + } + scope 33 { + scope 36 (inlined std::ptr::mut_ptr::::cast::) { + debug self => _36; + } + } + scope 34 { + debug _end => _31; + scope 40 (inlined NonNull::::add) { + debug self => _32; + debug count => const 1_usize; + let mut _33: *const T; + let mut _34: *const T; + scope 41 { + } + } + } + scope 35 { + scope 39 (inlined std::ptr::mut_ptr::::cast::>) { + debug self => _30; + } + } + } + } + } + } + scope 42 (inlined NonNull::::as_ref::<'_>) { + debug self => _40; + let mut _41: std::ptr::NonNull; + let mut _48: *mut T; + let _49: *const T; + scope 43 { + scope 44 (inlined NonNull::::as_ptr) { + debug self => _41; + let mut _42: *const T; + let mut _46: bool; + let mut _47: bool; + scope 45 { + scope 46 (inlined std::ptr::const_ptr::::is_null) { + debug self => _42; + let mut _43: *const u8; + scope 47 { + scope 48 (inlined std::ptr::const_ptr::::is_null::runtime_impl) { + debug ptr => _43; + let mut _45: usize; + scope 49 (inlined std::ptr::const_ptr::::addr) { + debug self => _43; + let mut _44: *const (); + scope 50 { + scope 51 (inlined std::ptr::const_ptr::::cast::<()>) { + debug self => _43; + } + } + } + } + } + } + } + } + scope 52 (inlined std::ptr::mut_ptr::::cast_const) { + debug self => _48; + } + } + } + } + } bb0: { - _0 = as Iterator>::next(move _1) -> [return: bb1, unwind continue]; + StorageLive(_27); + StorageLive(_24); + StorageLive(_2); + _2 = const _; + switchInt(move _2) -> [0: bb1, otherwise: bb2]; } bb1: { + StorageLive(_5); + StorageLive(_3); + _3 = &raw const ((*_1).1: *const T); + _4 = _3 as *const std::ptr::NonNull (PtrToPtr); + StorageDead(_3); + _5 = (*_4); + StorageLive(_6); + _6 = &((*_1).0: std::ptr::NonNull); + StorageLive(_7); + _7 = &_5; + StorageLive(_15); + StorageLive(_8); + _8 = ((*_1).0: std::ptr::NonNull); + StorageLive(_9); + StorageLive(_14); + StorageLive(_13); + _9 = (_8.0: *const T); + StorageLive(_10); + _10 = _9 as *const u8 (PtrToPtr); + StorageLive(_12); + StorageLive(_11); + _11 = _10 as *const () (PtrToPtr); + _12 = move _11 as usize (Transmute); + StorageDead(_11); + _13 = Eq(move _12, const 0_usize); + StorageDead(_12); + StorageDead(_10); + _14 = Not(move _13); + StorageDead(_13); + assume(move _14); + StorageDead(_14); + _15 = _9 as *mut T (PtrToPtr); + StorageDead(_9); + StorageDead(_8); + StorageLive(_23); + StorageLive(_16); + _16 = _5; + StorageLive(_17); + StorageLive(_22); + StorageLive(_21); + _17 = (_16.0: *const T); + StorageLive(_18); + _18 = _17 as *const u8 (PtrToPtr); + StorageLive(_20); + StorageLive(_19); + _19 = _18 as *const () (PtrToPtr); + _20 = move _19 as usize (Transmute); + StorageDead(_19); + _21 = Eq(move _20, const 0_usize); + StorageDead(_20); + StorageDead(_18); + _22 = Not(move _21); + StorageDead(_21); + assume(move _22); + StorageDead(_22); + _23 = _17 as *mut T (PtrToPtr); + StorageDead(_17); + StorageDead(_16); + _24 = Eq(move _15, move _23); + StorageDead(_23); + StorageDead(_15); + StorageDead(_7); + StorageDead(_6); + StorageDead(_5); + goto -> bb3; + } + + bb2: { + StorageLive(_25); + _25 = ((*_1).1: *const T); + StorageLive(_26); + _26 = _25 as *const () (PtrToPtr); + _27 = move _26 as usize (Transmute); + StorageDead(_26); + StorageDead(_25); + _24 = Eq(_27, const 0_usize); + goto -> bb3; + } + + bb3: { + StorageDead(_2); + switchInt(move _24) -> [0: bb4, otherwise: bb8]; + } + + bb4: { + StorageLive(_50); + StorageLive(_40); + StorageLive(_28); + StorageLive(_31); + _28 = ((*_1).0: std::ptr::NonNull); + StorageLive(_29); + _29 = const _; + switchInt(move _29) -> [0: bb5, otherwise: bb6]; + } + + bb5: { + StorageLive(_30); + _30 = &raw mut ((*_1).1: *const T); + _31 = _30 as *mut std::ptr::NonNull (PtrToPtr); + StorageDead(_30); + StorageLive(_35); + StorageLive(_32); + _32 = ((*_1).0: std::ptr::NonNull); + StorageLive(_34); + StorageLive(_33); + _33 = (_32.0: *const T); + _34 = Offset(move _33, const 1_usize); + StorageDead(_33); + _35 = NonNull:: { pointer: move _34 }; + StorageDead(_34); + StorageDead(_32); + ((*_1).0: std::ptr::NonNull) = move _35; + StorageDead(_35); + goto -> bb7; + } + + bb6: { + StorageLive(_36); + _36 = &raw mut ((*_1).1: *const T); + _37 = _36 as *mut usize (PtrToPtr); + StorageDead(_36); + StorageLive(_39); + StorageLive(_38); + _38 = (*_37); + _39 = SubUnchecked(_38, const 1_usize); + StorageDead(_38); + (*_37) = move _39; + StorageDead(_39); + goto -> bb7; + } + + bb7: { + StorageDead(_29); + StorageDead(_31); + _40 = &_28; + StorageLive(_48); + StorageLive(_41); + _41 = _28; + StorageLive(_42); + StorageLive(_47); + StorageLive(_46); + _42 = (_41.0: *const T); + StorageLive(_43); + _43 = _42 as *const u8 (PtrToPtr); + StorageLive(_45); + StorageLive(_44); + _44 = _43 as *const () (PtrToPtr); + _45 = move _44 as usize (Transmute); + StorageDead(_44); + _46 = Eq(move _45, const 0_usize); + StorageDead(_45); + StorageDead(_43); + _47 = Not(move _46); + StorageDead(_46); + assume(move _47); + StorageDead(_47); + _48 = _42 as *mut T (PtrToPtr); + StorageDead(_42); + StorageDead(_41); + _49 = _48 as *const T (PointerCoercion(MutToConstPointer)); + StorageDead(_48); + _50 = &(*_49); + StorageDead(_40); + _0 = Option::<&T>::Some(move _50); + StorageDead(_50); + StorageDead(_28); + goto -> bb9; + } + + bb8: { + _0 = const {transmute(0x0000000000000000): Option<&T>}; + goto -> bb9; + } + + bb9: { + StorageDead(_24); + StorageDead(_27); return; } }