From c18718c9c28cc4c700312775c2b7f87cd79d3063 Mon Sep 17 00:00:00 2001 From: Scott McMurray Date: Fri, 10 Jan 2025 13:00:45 -0800 Subject: [PATCH] Less unsafe in `dangling`/`without_provenance` --- library/core/src/ptr/alignment.rs | 12 ++- library/core/src/ptr/mod.rs | 11 +-- library/core/src/ptr/non_null.rs | 16 ++-- ...n.DataflowConstProp.32bit.panic-abort.diff | 63 +++++---------- ....DataflowConstProp.32bit.panic-unwind.diff | 71 ++++++---------- ...n.DataflowConstProp.64bit.panic-abort.diff | 63 +++++---------- ....DataflowConstProp.64bit.panic-unwind.diff | 71 ++++++---------- ...oxed_slice.main.GVN.32bit.panic-abort.diff | 72 +++++------------ ...xed_slice.main.GVN.32bit.panic-unwind.diff | 80 ++++++------------- ...oxed_slice.main.GVN.64bit.panic-abort.diff | 72 +++++------------ ...xed_slice.main.GVN.64bit.panic-unwind.diff | 80 ++++++------------- .../gvn_ptr_eq_with_constant.main.GVN.diff | 30 +++++-- ...ated_loop.PreCodegen.after.panic-abort.mir | 32 ++++---- ...ted_loop.PreCodegen.after.panic-unwind.mir | 12 +-- ...ward_loop.PreCodegen.after.panic-abort.mir | 8 +- ...ard_loop.PreCodegen.after.panic-unwind.mir | 8 +- ...erse_loop.PreCodegen.after.panic-abort.mir | 14 ++-- ...rse_loop.PreCodegen.after.panic-unwind.mir | 14 ++-- 18 files changed, 272 insertions(+), 457 deletions(-) diff --git a/library/core/src/ptr/alignment.rs b/library/core/src/ptr/alignment.rs index 74a1d40f4e734..2da94e72566e9 100644 --- a/library/core/src/ptr/alignment.rs +++ b/library/core/src/ptr/alignment.rs @@ -42,9 +42,10 @@ impl Alignment { /// but in an `Alignment` instead of a `usize`. #[unstable(feature = "ptr_alignment_type", issue = "102070")] #[inline] + #[must_use] pub const fn of() -> Self { - // SAFETY: rustc ensures that type alignment is always a power of two. - unsafe { Alignment::new_unchecked(mem::align_of::()) } + // This can't actually panic since type alignment is always a power of two. + const { Alignment::new(mem::align_of::()).unwrap() } } /// Creates an `Alignment` from a `usize`, or returns `None` if it's @@ -95,8 +96,13 @@ impl Alignment { #[unstable(feature = "ptr_alignment_type", issue = "102070")] #[inline] pub const fn as_nonzero(self) -> NonZero { + // This transmutes directly to avoid the UbCheck in `NonZero::new_unchecked` + // since there's no way for the user to trip that check anyway -- the + // validity invariant of the type would have to have been broken earlier -- + // and emitting it in an otherwise simple method is bad for compile time. + // SAFETY: All the discriminants are non-zero. - unsafe { NonZero::new_unchecked(self.as_usize()) } + unsafe { mem::transmute::>(self) } } /// Returns the base-2 logarithm of the alignment. diff --git a/library/core/src/ptr/mod.rs b/library/core/src/ptr/mod.rs index f58c0e1241142..e1348552b65c3 100644 --- a/library/core/src/ptr/mod.rs +++ b/library/core/src/ptr/mod.rs @@ -596,12 +596,7 @@ pub const fn null_mut() -> *mut T { #[stable(feature = "strict_provenance", since = "1.84.0")] #[rustc_const_stable(feature = "strict_provenance", since = "1.84.0")] pub const fn without_provenance(addr: usize) -> *const T { - // An int-to-pointer transmute currently has exactly the intended semantics: it creates a - // pointer without provenance. Note that this is *not* a stable guarantee about transmute - // semantics, it relies on sysroot crates having special status. - // SAFETY: every valid integer is also a valid pointer (as long as you don't dereference that - // pointer). - unsafe { mem::transmute(addr) } + without_provenance_mut(addr) } /// Creates a new pointer that is dangling, but non-null and well-aligned. @@ -618,7 +613,7 @@ pub const fn without_provenance(addr: usize) -> *const T { #[stable(feature = "strict_provenance", since = "1.84.0")] #[rustc_const_stable(feature = "strict_provenance", since = "1.84.0")] pub const fn dangling() -> *const T { - without_provenance(mem::align_of::()) + dangling_mut() } /// Creates a pointer with the given address and no [provenance][crate::ptr#provenance]. @@ -661,7 +656,7 @@ pub const fn without_provenance_mut(addr: usize) -> *mut T { #[stable(feature = "strict_provenance", since = "1.84.0")] #[rustc_const_stable(feature = "strict_provenance", since = "1.84.0")] pub const fn dangling_mut() -> *mut T { - without_provenance_mut(mem::align_of::()) + NonNull::dangling().as_ptr() } /// Converts an address back to a pointer, picking up some previously 'exposed' diff --git a/library/core/src/ptr/non_null.rs b/library/core/src/ptr/non_null.rs index 2c9131254f7c4..d93069d384edd 100644 --- a/library/core/src/ptr/non_null.rs +++ b/library/core/src/ptr/non_null.rs @@ -91,12 +91,12 @@ impl NonNull { /// /// This is a [Strict Provenance][crate::ptr#strict-provenance] API. #[unstable(feature = "nonnull_provenance", issue = "135243")] + #[must_use] + #[inline] pub const fn without_provenance(addr: NonZero) -> Self { + let pointer = crate::ptr::without_provenance(addr.get()); // SAFETY: we know `addr` is non-zero. - unsafe { - let ptr = crate::ptr::without_provenance_mut(addr.get()); - NonNull::new_unchecked(ptr) - } + unsafe { NonNull { pointer } } } /// Creates a new `NonNull` that is dangling, but well-aligned. @@ -123,11 +123,8 @@ impl NonNull { #[must_use] #[inline] pub const fn dangling() -> Self { - // SAFETY: ptr::dangling_mut() returns a non-null well-aligned pointer. - unsafe { - let ptr = crate::ptr::dangling_mut::(); - NonNull::new_unchecked(ptr) - } + let align = crate::ptr::Alignment::of::(); + NonNull::without_provenance(align.as_nonzero()) } /// Converts an address back to a mutable pointer, picking up some previously 'exposed' @@ -137,6 +134,7 @@ impl NonNull { /// /// This is an [Exposed Provenance][crate::ptr#exposed-provenance] API. #[unstable(feature = "nonnull_provenance", issue = "135243")] + #[inline] pub fn with_exposed_provenance(addr: NonZero) -> Self { // SAFETY: we know `addr` is non-zero. unsafe { diff --git a/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.DataflowConstProp.32bit.panic-abort.diff b/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.DataflowConstProp.32bit.panic-abort.diff index 5ea9902b26251..5a830254f6199 100644 --- a/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.DataflowConstProp.32bit.panic-abort.diff +++ b/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.DataflowConstProp.32bit.panic-abort.diff @@ -16,25 +16,23 @@ scope 4 (inlined Unique::<[bool; 0]>::dangling) { let mut _5: std::ptr::NonNull<[bool; 0]>; scope 5 (inlined NonNull::<[bool; 0]>::dangling) { - let _6: *mut [bool; 0]; + let mut _6: std::num::NonZero; scope 6 { - scope 10 (inlined NonNull::<[bool; 0]>::new_unchecked) { - let mut _8: bool; - let _9: (); - let mut _10: *mut (); - let mut _11: *const [bool; 0]; - scope 11 (inlined core::ub_checks::check_language_ub) { - scope 12 (inlined core::ub_checks::check_language_ub::runtime) { + scope 8 (inlined std::ptr::Alignment::as_nonzero) { + } + scope 9 (inlined NonNull::<[bool; 0]>::without_provenance) { + let _7: *const [bool; 0]; + scope 10 { + } + scope 11 (inlined NonZero::::get) { + } + scope 12 (inlined without_provenance::<[bool; 0]>) { + scope 13 (inlined without_provenance_mut::<[bool; 0]>) { } } } } - scope 7 (inlined dangling_mut::<[bool; 0]>) { - let mut _7: usize; - scope 8 (inlined align_of::<[bool; 0]>) { - } - scope 9 (inlined without_provenance_mut::<[bool; 0]>) { - } + scope 7 (inlined std::ptr::Alignment::of::<[bool; 0]>) { } } } @@ -44,40 +42,13 @@ StorageLive(_1); StorageLive(_2); StorageLive(_3); - StorageLive(_9); StorageLive(_4); StorageLive(_5); StorageLive(_6); + _6 = const NonZero::(core::num::niche_types::NonZeroUsizeInner(1_usize)); StorageLive(_7); - _7 = const 1_usize; - _6 = const {0x1 as *mut [bool; 0]}; - StorageLive(_11); - StorageLive(_8); - _8 = UbChecks(); - switchInt(move _8) -> [0: bb4, otherwise: bb2]; - } - - bb1: { - StorageDead(_1); - return; - } - - bb2: { - StorageLive(_10); - _10 = const {0x1 as *mut ()}; - _9 = NonNull::::new_unchecked::precondition_check(const {0x1 as *mut ()}) -> [return: bb3, unwind unreachable]; - } - - bb3: { - StorageDead(_10); - goto -> bb4; - } - - bb4: { - StorageDead(_8); - _11 = const {0x1 as *const [bool; 0]}; + _7 = const {0x1 as *const [bool; 0]}; _5 = const NonNull::<[bool; 0]> {{ pointer: {0x1 as *const [bool; 0]} }}; - StorageDead(_11); StorageDead(_7); StorageDead(_6); _4 = const Unique::<[bool; 0]> {{ pointer: NonNull::<[bool; 0]> {{ pointer: {0x1 as *const [bool; 0]} }}, _marker: PhantomData::<[bool; 0]> }}; @@ -85,13 +56,17 @@ _3 = const Unique::<[bool]> {{ pointer: NonNull::<[bool]> {{ pointer: Indirect { alloc_id: ALLOC0, offset: Size(0 bytes) }: *const [bool] }}, _marker: PhantomData::<[bool]> }}; StorageDead(_4); _2 = const Box::<[bool]>(Unique::<[bool]> {{ pointer: NonNull::<[bool]> {{ pointer: Indirect { alloc_id: ALLOC1, offset: Size(0 bytes) }: *const [bool] }}, _marker: PhantomData::<[bool]> }}, std::alloc::Global); - StorageDead(_9); StorageDead(_3); _1 = const A {{ foo: Box::<[bool]>(Unique::<[bool]> {{ pointer: NonNull::<[bool]> {{ pointer: Indirect { alloc_id: ALLOC2, offset: Size(0 bytes) }: *const [bool] }}, _marker: PhantomData::<[bool]> }}, std::alloc::Global) }}; StorageDead(_2); _0 = const (); drop(_1) -> [return: bb1, unwind unreachable]; } + + bb1: { + StorageDead(_1); + return; + } } ALLOC2 (size: 8, align: 4) { .. } diff --git a/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.DataflowConstProp.32bit.panic-unwind.diff b/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.DataflowConstProp.32bit.panic-unwind.diff index cc5a41a7f63b1..c11368a347c57 100644 --- a/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.DataflowConstProp.32bit.panic-unwind.diff +++ b/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.DataflowConstProp.32bit.panic-unwind.diff @@ -16,25 +16,23 @@ scope 4 (inlined Unique::<[bool; 0]>::dangling) { let mut _5: std::ptr::NonNull<[bool; 0]>; scope 5 (inlined NonNull::<[bool; 0]>::dangling) { - let _6: *mut [bool; 0]; + let mut _6: std::num::NonZero; scope 6 { - scope 10 (inlined NonNull::<[bool; 0]>::new_unchecked) { - let mut _8: bool; - let _9: (); - let mut _10: *mut (); - let mut _11: *const [bool; 0]; - scope 11 (inlined core::ub_checks::check_language_ub) { - scope 12 (inlined core::ub_checks::check_language_ub::runtime) { + scope 8 (inlined std::ptr::Alignment::as_nonzero) { + } + scope 9 (inlined NonNull::<[bool; 0]>::without_provenance) { + let _7: *const [bool; 0]; + scope 10 { + } + scope 11 (inlined NonZero::::get) { + } + scope 12 (inlined without_provenance::<[bool; 0]>) { + scope 13 (inlined without_provenance_mut::<[bool; 0]>) { } } } } - scope 7 (inlined dangling_mut::<[bool; 0]>) { - let mut _7: usize; - scope 8 (inlined align_of::<[bool; 0]>) { - } - scope 9 (inlined without_provenance_mut::<[bool; 0]>) { - } + scope 7 (inlined std::ptr::Alignment::of::<[bool; 0]>) { } } } @@ -44,44 +42,13 @@ StorageLive(_1); StorageLive(_2); StorageLive(_3); - StorageLive(_9); StorageLive(_4); StorageLive(_5); StorageLive(_6); + _6 = const NonZero::(core::num::niche_types::NonZeroUsizeInner(1_usize)); StorageLive(_7); - _7 = const 1_usize; - _6 = const {0x1 as *mut [bool; 0]}; - StorageLive(_11); - StorageLive(_8); - _8 = UbChecks(); - switchInt(move _8) -> [0: bb5, otherwise: bb3]; - } - - bb1: { - StorageDead(_1); - return; - } - - bb2 (cleanup): { - resume; - } - - bb3: { - StorageLive(_10); - _10 = const {0x1 as *mut ()}; - _9 = NonNull::::new_unchecked::precondition_check(const {0x1 as *mut ()}) -> [return: bb4, unwind unreachable]; - } - - bb4: { - StorageDead(_10); - goto -> bb5; - } - - bb5: { - StorageDead(_8); - _11 = const {0x1 as *const [bool; 0]}; + _7 = const {0x1 as *const [bool; 0]}; _5 = const NonNull::<[bool; 0]> {{ pointer: {0x1 as *const [bool; 0]} }}; - StorageDead(_11); StorageDead(_7); StorageDead(_6); _4 = const Unique::<[bool; 0]> {{ pointer: NonNull::<[bool; 0]> {{ pointer: {0x1 as *const [bool; 0]} }}, _marker: PhantomData::<[bool; 0]> }}; @@ -89,13 +56,21 @@ _3 = const Unique::<[bool]> {{ pointer: NonNull::<[bool]> {{ pointer: Indirect { alloc_id: ALLOC0, offset: Size(0 bytes) }: *const [bool] }}, _marker: PhantomData::<[bool]> }}; StorageDead(_4); _2 = const Box::<[bool]>(Unique::<[bool]> {{ pointer: NonNull::<[bool]> {{ pointer: Indirect { alloc_id: ALLOC1, offset: Size(0 bytes) }: *const [bool] }}, _marker: PhantomData::<[bool]> }}, std::alloc::Global); - StorageDead(_9); StorageDead(_3); _1 = const A {{ foo: Box::<[bool]>(Unique::<[bool]> {{ pointer: NonNull::<[bool]> {{ pointer: Indirect { alloc_id: ALLOC2, offset: Size(0 bytes) }: *const [bool] }}, _marker: PhantomData::<[bool]> }}, std::alloc::Global) }}; StorageDead(_2); _0 = const (); drop(_1) -> [return: bb1, unwind: bb2]; } + + bb1: { + StorageDead(_1); + return; + } + + bb2 (cleanup): { + resume; + } } ALLOC2 (size: 8, align: 4) { .. } diff --git a/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.DataflowConstProp.64bit.panic-abort.diff b/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.DataflowConstProp.64bit.panic-abort.diff index 3d398fbea7935..037ed02ce6556 100644 --- a/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.DataflowConstProp.64bit.panic-abort.diff +++ b/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.DataflowConstProp.64bit.panic-abort.diff @@ -16,25 +16,23 @@ scope 4 (inlined Unique::<[bool; 0]>::dangling) { let mut _5: std::ptr::NonNull<[bool; 0]>; scope 5 (inlined NonNull::<[bool; 0]>::dangling) { - let _6: *mut [bool; 0]; + let mut _6: std::num::NonZero; scope 6 { - scope 10 (inlined NonNull::<[bool; 0]>::new_unchecked) { - let mut _8: bool; - let _9: (); - let mut _10: *mut (); - let mut _11: *const [bool; 0]; - scope 11 (inlined core::ub_checks::check_language_ub) { - scope 12 (inlined core::ub_checks::check_language_ub::runtime) { + scope 8 (inlined std::ptr::Alignment::as_nonzero) { + } + scope 9 (inlined NonNull::<[bool; 0]>::without_provenance) { + let _7: *const [bool; 0]; + scope 10 { + } + scope 11 (inlined NonZero::::get) { + } + scope 12 (inlined without_provenance::<[bool; 0]>) { + scope 13 (inlined without_provenance_mut::<[bool; 0]>) { } } } } - scope 7 (inlined dangling_mut::<[bool; 0]>) { - let mut _7: usize; - scope 8 (inlined align_of::<[bool; 0]>) { - } - scope 9 (inlined without_provenance_mut::<[bool; 0]>) { - } + scope 7 (inlined std::ptr::Alignment::of::<[bool; 0]>) { } } } @@ -44,40 +42,13 @@ StorageLive(_1); StorageLive(_2); StorageLive(_3); - StorageLive(_9); StorageLive(_4); StorageLive(_5); StorageLive(_6); + _6 = const NonZero::(core::num::niche_types::NonZeroUsizeInner(1_usize)); StorageLive(_7); - _7 = const 1_usize; - _6 = const {0x1 as *mut [bool; 0]}; - StorageLive(_11); - StorageLive(_8); - _8 = UbChecks(); - switchInt(move _8) -> [0: bb4, otherwise: bb2]; - } - - bb1: { - StorageDead(_1); - return; - } - - bb2: { - StorageLive(_10); - _10 = const {0x1 as *mut ()}; - _9 = NonNull::::new_unchecked::precondition_check(const {0x1 as *mut ()}) -> [return: bb3, unwind unreachable]; - } - - bb3: { - StorageDead(_10); - goto -> bb4; - } - - bb4: { - StorageDead(_8); - _11 = const {0x1 as *const [bool; 0]}; + _7 = const {0x1 as *const [bool; 0]}; _5 = const NonNull::<[bool; 0]> {{ pointer: {0x1 as *const [bool; 0]} }}; - StorageDead(_11); StorageDead(_7); StorageDead(_6); _4 = const Unique::<[bool; 0]> {{ pointer: NonNull::<[bool; 0]> {{ pointer: {0x1 as *const [bool; 0]} }}, _marker: PhantomData::<[bool; 0]> }}; @@ -85,13 +56,17 @@ _3 = const Unique::<[bool]> {{ pointer: NonNull::<[bool]> {{ pointer: Indirect { alloc_id: ALLOC0, offset: Size(0 bytes) }: *const [bool] }}, _marker: PhantomData::<[bool]> }}; StorageDead(_4); _2 = const Box::<[bool]>(Unique::<[bool]> {{ pointer: NonNull::<[bool]> {{ pointer: Indirect { alloc_id: ALLOC1, offset: Size(0 bytes) }: *const [bool] }}, _marker: PhantomData::<[bool]> }}, std::alloc::Global); - StorageDead(_9); StorageDead(_3); _1 = const A {{ foo: Box::<[bool]>(Unique::<[bool]> {{ pointer: NonNull::<[bool]> {{ pointer: Indirect { alloc_id: ALLOC2, offset: Size(0 bytes) }: *const [bool] }}, _marker: PhantomData::<[bool]> }}, std::alloc::Global) }}; StorageDead(_2); _0 = const (); drop(_1) -> [return: bb1, unwind unreachable]; } + + bb1: { + StorageDead(_1); + return; + } } ALLOC2 (size: 16, align: 8) { .. } diff --git a/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.DataflowConstProp.64bit.panic-unwind.diff b/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.DataflowConstProp.64bit.panic-unwind.diff index dc99c3f7a8c9b..86351c7875933 100644 --- a/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.DataflowConstProp.64bit.panic-unwind.diff +++ b/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.DataflowConstProp.64bit.panic-unwind.diff @@ -16,25 +16,23 @@ scope 4 (inlined Unique::<[bool; 0]>::dangling) { let mut _5: std::ptr::NonNull<[bool; 0]>; scope 5 (inlined NonNull::<[bool; 0]>::dangling) { - let _6: *mut [bool; 0]; + let mut _6: std::num::NonZero; scope 6 { - scope 10 (inlined NonNull::<[bool; 0]>::new_unchecked) { - let mut _8: bool; - let _9: (); - let mut _10: *mut (); - let mut _11: *const [bool; 0]; - scope 11 (inlined core::ub_checks::check_language_ub) { - scope 12 (inlined core::ub_checks::check_language_ub::runtime) { + scope 8 (inlined std::ptr::Alignment::as_nonzero) { + } + scope 9 (inlined NonNull::<[bool; 0]>::without_provenance) { + let _7: *const [bool; 0]; + scope 10 { + } + scope 11 (inlined NonZero::::get) { + } + scope 12 (inlined without_provenance::<[bool; 0]>) { + scope 13 (inlined without_provenance_mut::<[bool; 0]>) { } } } } - scope 7 (inlined dangling_mut::<[bool; 0]>) { - let mut _7: usize; - scope 8 (inlined align_of::<[bool; 0]>) { - } - scope 9 (inlined without_provenance_mut::<[bool; 0]>) { - } + scope 7 (inlined std::ptr::Alignment::of::<[bool; 0]>) { } } } @@ -44,44 +42,13 @@ StorageLive(_1); StorageLive(_2); StorageLive(_3); - StorageLive(_9); StorageLive(_4); StorageLive(_5); StorageLive(_6); + _6 = const NonZero::(core::num::niche_types::NonZeroUsizeInner(1_usize)); StorageLive(_7); - _7 = const 1_usize; - _6 = const {0x1 as *mut [bool; 0]}; - StorageLive(_11); - StorageLive(_8); - _8 = UbChecks(); - switchInt(move _8) -> [0: bb5, otherwise: bb3]; - } - - bb1: { - StorageDead(_1); - return; - } - - bb2 (cleanup): { - resume; - } - - bb3: { - StorageLive(_10); - _10 = const {0x1 as *mut ()}; - _9 = NonNull::::new_unchecked::precondition_check(const {0x1 as *mut ()}) -> [return: bb4, unwind unreachable]; - } - - bb4: { - StorageDead(_10); - goto -> bb5; - } - - bb5: { - StorageDead(_8); - _11 = const {0x1 as *const [bool; 0]}; + _7 = const {0x1 as *const [bool; 0]}; _5 = const NonNull::<[bool; 0]> {{ pointer: {0x1 as *const [bool; 0]} }}; - StorageDead(_11); StorageDead(_7); StorageDead(_6); _4 = const Unique::<[bool; 0]> {{ pointer: NonNull::<[bool; 0]> {{ pointer: {0x1 as *const [bool; 0]} }}, _marker: PhantomData::<[bool; 0]> }}; @@ -89,13 +56,21 @@ _3 = const Unique::<[bool]> {{ pointer: NonNull::<[bool]> {{ pointer: Indirect { alloc_id: ALLOC0, offset: Size(0 bytes) }: *const [bool] }}, _marker: PhantomData::<[bool]> }}; StorageDead(_4); _2 = const Box::<[bool]>(Unique::<[bool]> {{ pointer: NonNull::<[bool]> {{ pointer: Indirect { alloc_id: ALLOC1, offset: Size(0 bytes) }: *const [bool] }}, _marker: PhantomData::<[bool]> }}, std::alloc::Global); - StorageDead(_9); StorageDead(_3); _1 = const A {{ foo: Box::<[bool]>(Unique::<[bool]> {{ pointer: NonNull::<[bool]> {{ pointer: Indirect { alloc_id: ALLOC2, offset: Size(0 bytes) }: *const [bool] }}, _marker: PhantomData::<[bool]> }}, std::alloc::Global) }}; StorageDead(_2); _0 = const (); drop(_1) -> [return: bb1, unwind: bb2]; } + + bb1: { + StorageDead(_1); + return; + } + + bb2 (cleanup): { + resume; + } } ALLOC2 (size: 16, align: 8) { .. } diff --git a/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.GVN.32bit.panic-abort.diff b/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.GVN.32bit.panic-abort.diff index 6a3ec54306994..20a3897a934f0 100644 --- a/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.GVN.32bit.panic-abort.diff +++ b/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.GVN.32bit.panic-abort.diff @@ -16,25 +16,23 @@ scope 4 (inlined Unique::<[bool; 0]>::dangling) { let mut _5: std::ptr::NonNull<[bool; 0]>; scope 5 (inlined NonNull::<[bool; 0]>::dangling) { - let _6: *mut [bool; 0]; + let mut _6: std::num::NonZero; scope 6 { - scope 10 (inlined NonNull::<[bool; 0]>::new_unchecked) { - let mut _8: bool; - let _9: (); - let mut _10: *mut (); - let mut _11: *const [bool; 0]; - scope 11 (inlined core::ub_checks::check_language_ub) { - scope 12 (inlined core::ub_checks::check_language_ub::runtime) { + scope 8 (inlined std::ptr::Alignment::as_nonzero) { + } + scope 9 (inlined NonNull::<[bool; 0]>::without_provenance) { + let _7: *const [bool; 0]; + scope 10 { + } + scope 11 (inlined NonZero::::get) { + } + scope 12 (inlined without_provenance::<[bool; 0]>) { + scope 13 (inlined without_provenance_mut::<[bool; 0]>) { } } } } - scope 7 (inlined dangling_mut::<[bool; 0]>) { - let mut _7: usize; - scope 8 (inlined align_of::<[bool; 0]>) { - } - scope 9 (inlined without_provenance_mut::<[bool; 0]>) { - } + scope 7 (inlined std::ptr::Alignment::of::<[bool; 0]>) { } } } @@ -44,46 +42,16 @@ StorageLive(_1); StorageLive(_2); StorageLive(_3); - StorageLive(_9); StorageLive(_4); StorageLive(_5); StorageLive(_6); +- _6 = const std::ptr::Alignment::of::<[bool; 0]>::{constant#0} as std::num::NonZero (Transmute); ++ _6 = const NonZero::(core::num::niche_types::NonZeroUsizeInner(1_usize)); StorageLive(_7); -- _7 = AlignOf([bool; 0]); -- _6 = copy _7 as *mut [bool; 0] (Transmute); -+ _7 = const 1_usize; -+ _6 = const {0x1 as *mut [bool; 0]}; - StorageLive(_11); - StorageLive(_8); - _8 = UbChecks(); - switchInt(move _8) -> [0: bb4, otherwise: bb2]; - } - - bb1: { - StorageDead(_1); - return; - } - - bb2: { - StorageLive(_10); -- _10 = copy _7 as *mut () (Transmute); -- _9 = NonNull::::new_unchecked::precondition_check(move _10) -> [return: bb3, unwind unreachable]; -+ _10 = const {0x1 as *mut ()}; -+ _9 = NonNull::::new_unchecked::precondition_check(const {0x1 as *mut ()}) -> [return: bb3, unwind unreachable]; - } - - bb3: { - StorageDead(_10); - goto -> bb4; - } - - bb4: { - StorageDead(_8); -- _11 = copy _7 as *const [bool; 0] (Transmute); -- _5 = NonNull::<[bool; 0]> { pointer: copy _11 }; -+ _11 = const {0x1 as *const [bool; 0]}; +- _7 = copy _6 as *const [bool; 0] (Transmute); +- _5 = NonNull::<[bool; 0]> { pointer: copy _7 }; ++ _7 = const {0x1 as *const [bool; 0]}; + _5 = const NonNull::<[bool; 0]> {{ pointer: {0x1 as *const [bool; 0]} }}; - StorageDead(_11); StorageDead(_7); StorageDead(_6); - _4 = Unique::<[bool; 0]> { pointer: move _5, _marker: const PhantomData::<[bool; 0]> }; @@ -94,7 +62,6 @@ StorageDead(_4); - _2 = Box::<[bool]>(copy _3, const std::alloc::Global); + _2 = const Box::<[bool]>(Unique::<[bool]> {{ pointer: NonNull::<[bool]> {{ pointer: Indirect { alloc_id: ALLOC1, offset: Size(0 bytes) }: *const [bool] }}, _marker: PhantomData::<[bool]> }}, std::alloc::Global); - StorageDead(_9); StorageDead(_3); - _1 = A { foo: move _2 }; + _1 = const A {{ foo: Box::<[bool]>(Unique::<[bool]> {{ pointer: NonNull::<[bool]> {{ pointer: Indirect { alloc_id: ALLOC2, offset: Size(0 bytes) }: *const [bool] }}, _marker: PhantomData::<[bool]> }}, std::alloc::Global) }}; @@ -102,6 +69,11 @@ _0 = const (); drop(_1) -> [return: bb1, unwind unreachable]; } + + bb1: { + StorageDead(_1); + return; + } } + + ALLOC2 (size: 8, align: 4) { .. } diff --git a/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.GVN.32bit.panic-unwind.diff b/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.GVN.32bit.panic-unwind.diff index 9471ad47cd9df..2e396301fd0ec 100644 --- a/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.GVN.32bit.panic-unwind.diff +++ b/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.GVN.32bit.panic-unwind.diff @@ -16,25 +16,23 @@ scope 4 (inlined Unique::<[bool; 0]>::dangling) { let mut _5: std::ptr::NonNull<[bool; 0]>; scope 5 (inlined NonNull::<[bool; 0]>::dangling) { - let _6: *mut [bool; 0]; + let mut _6: std::num::NonZero; scope 6 { - scope 10 (inlined NonNull::<[bool; 0]>::new_unchecked) { - let mut _8: bool; - let _9: (); - let mut _10: *mut (); - let mut _11: *const [bool; 0]; - scope 11 (inlined core::ub_checks::check_language_ub) { - scope 12 (inlined core::ub_checks::check_language_ub::runtime) { + scope 8 (inlined std::ptr::Alignment::as_nonzero) { + } + scope 9 (inlined NonNull::<[bool; 0]>::without_provenance) { + let _7: *const [bool; 0]; + scope 10 { + } + scope 11 (inlined NonZero::::get) { + } + scope 12 (inlined without_provenance::<[bool; 0]>) { + scope 13 (inlined without_provenance_mut::<[bool; 0]>) { } } } } - scope 7 (inlined dangling_mut::<[bool; 0]>) { - let mut _7: usize; - scope 8 (inlined align_of::<[bool; 0]>) { - } - scope 9 (inlined without_provenance_mut::<[bool; 0]>) { - } + scope 7 (inlined std::ptr::Alignment::of::<[bool; 0]>) { } } } @@ -44,50 +42,16 @@ StorageLive(_1); StorageLive(_2); StorageLive(_3); - StorageLive(_9); StorageLive(_4); StorageLive(_5); StorageLive(_6); +- _6 = const std::ptr::Alignment::of::<[bool; 0]>::{constant#0} as std::num::NonZero (Transmute); ++ _6 = const NonZero::(core::num::niche_types::NonZeroUsizeInner(1_usize)); StorageLive(_7); -- _7 = AlignOf([bool; 0]); -- _6 = copy _7 as *mut [bool; 0] (Transmute); -+ _7 = const 1_usize; -+ _6 = const {0x1 as *mut [bool; 0]}; - StorageLive(_11); - StorageLive(_8); - _8 = UbChecks(); - switchInt(move _8) -> [0: bb5, otherwise: bb3]; - } - - bb1: { - StorageDead(_1); - return; - } - - bb2 (cleanup): { - resume; - } - - bb3: { - StorageLive(_10); -- _10 = copy _7 as *mut () (Transmute); -- _9 = NonNull::::new_unchecked::precondition_check(move _10) -> [return: bb4, unwind unreachable]; -+ _10 = const {0x1 as *mut ()}; -+ _9 = NonNull::::new_unchecked::precondition_check(const {0x1 as *mut ()}) -> [return: bb4, unwind unreachable]; - } - - bb4: { - StorageDead(_10); - goto -> bb5; - } - - bb5: { - StorageDead(_8); -- _11 = copy _7 as *const [bool; 0] (Transmute); -- _5 = NonNull::<[bool; 0]> { pointer: copy _11 }; -+ _11 = const {0x1 as *const [bool; 0]}; +- _7 = copy _6 as *const [bool; 0] (Transmute); +- _5 = NonNull::<[bool; 0]> { pointer: copy _7 }; ++ _7 = const {0x1 as *const [bool; 0]}; + _5 = const NonNull::<[bool; 0]> {{ pointer: {0x1 as *const [bool; 0]} }}; - StorageDead(_11); StorageDead(_7); StorageDead(_6); - _4 = Unique::<[bool; 0]> { pointer: move _5, _marker: const PhantomData::<[bool; 0]> }; @@ -98,7 +62,6 @@ StorageDead(_4); - _2 = Box::<[bool]>(copy _3, const std::alloc::Global); + _2 = const Box::<[bool]>(Unique::<[bool]> {{ pointer: NonNull::<[bool]> {{ pointer: Indirect { alloc_id: ALLOC1, offset: Size(0 bytes) }: *const [bool] }}, _marker: PhantomData::<[bool]> }}, std::alloc::Global); - StorageDead(_9); StorageDead(_3); - _1 = A { foo: move _2 }; + _1 = const A {{ foo: Box::<[bool]>(Unique::<[bool]> {{ pointer: NonNull::<[bool]> {{ pointer: Indirect { alloc_id: ALLOC2, offset: Size(0 bytes) }: *const [bool] }}, _marker: PhantomData::<[bool]> }}, std::alloc::Global) }}; @@ -106,6 +69,15 @@ _0 = const (); drop(_1) -> [return: bb1, unwind: bb2]; } + + bb1: { + StorageDead(_1); + return; + } + + bb2 (cleanup): { + resume; + } } + + ALLOC2 (size: 8, align: 4) { .. } diff --git a/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.GVN.64bit.panic-abort.diff b/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.GVN.64bit.panic-abort.diff index 187927b8ecab7..319691174cf66 100644 --- a/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.GVN.64bit.panic-abort.diff +++ b/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.GVN.64bit.panic-abort.diff @@ -16,25 +16,23 @@ scope 4 (inlined Unique::<[bool; 0]>::dangling) { let mut _5: std::ptr::NonNull<[bool; 0]>; scope 5 (inlined NonNull::<[bool; 0]>::dangling) { - let _6: *mut [bool; 0]; + let mut _6: std::num::NonZero; scope 6 { - scope 10 (inlined NonNull::<[bool; 0]>::new_unchecked) { - let mut _8: bool; - let _9: (); - let mut _10: *mut (); - let mut _11: *const [bool; 0]; - scope 11 (inlined core::ub_checks::check_language_ub) { - scope 12 (inlined core::ub_checks::check_language_ub::runtime) { + scope 8 (inlined std::ptr::Alignment::as_nonzero) { + } + scope 9 (inlined NonNull::<[bool; 0]>::without_provenance) { + let _7: *const [bool; 0]; + scope 10 { + } + scope 11 (inlined NonZero::::get) { + } + scope 12 (inlined without_provenance::<[bool; 0]>) { + scope 13 (inlined without_provenance_mut::<[bool; 0]>) { } } } } - scope 7 (inlined dangling_mut::<[bool; 0]>) { - let mut _7: usize; - scope 8 (inlined align_of::<[bool; 0]>) { - } - scope 9 (inlined without_provenance_mut::<[bool; 0]>) { - } + scope 7 (inlined std::ptr::Alignment::of::<[bool; 0]>) { } } } @@ -44,46 +42,16 @@ StorageLive(_1); StorageLive(_2); StorageLive(_3); - StorageLive(_9); StorageLive(_4); StorageLive(_5); StorageLive(_6); +- _6 = const std::ptr::Alignment::of::<[bool; 0]>::{constant#0} as std::num::NonZero (Transmute); ++ _6 = const NonZero::(core::num::niche_types::NonZeroUsizeInner(1_usize)); StorageLive(_7); -- _7 = AlignOf([bool; 0]); -- _6 = copy _7 as *mut [bool; 0] (Transmute); -+ _7 = const 1_usize; -+ _6 = const {0x1 as *mut [bool; 0]}; - StorageLive(_11); - StorageLive(_8); - _8 = UbChecks(); - switchInt(move _8) -> [0: bb4, otherwise: bb2]; - } - - bb1: { - StorageDead(_1); - return; - } - - bb2: { - StorageLive(_10); -- _10 = copy _7 as *mut () (Transmute); -- _9 = NonNull::::new_unchecked::precondition_check(move _10) -> [return: bb3, unwind unreachable]; -+ _10 = const {0x1 as *mut ()}; -+ _9 = NonNull::::new_unchecked::precondition_check(const {0x1 as *mut ()}) -> [return: bb3, unwind unreachable]; - } - - bb3: { - StorageDead(_10); - goto -> bb4; - } - - bb4: { - StorageDead(_8); -- _11 = copy _7 as *const [bool; 0] (Transmute); -- _5 = NonNull::<[bool; 0]> { pointer: copy _11 }; -+ _11 = const {0x1 as *const [bool; 0]}; +- _7 = copy _6 as *const [bool; 0] (Transmute); +- _5 = NonNull::<[bool; 0]> { pointer: copy _7 }; ++ _7 = const {0x1 as *const [bool; 0]}; + _5 = const NonNull::<[bool; 0]> {{ pointer: {0x1 as *const [bool; 0]} }}; - StorageDead(_11); StorageDead(_7); StorageDead(_6); - _4 = Unique::<[bool; 0]> { pointer: move _5, _marker: const PhantomData::<[bool; 0]> }; @@ -94,7 +62,6 @@ StorageDead(_4); - _2 = Box::<[bool]>(copy _3, const std::alloc::Global); + _2 = const Box::<[bool]>(Unique::<[bool]> {{ pointer: NonNull::<[bool]> {{ pointer: Indirect { alloc_id: ALLOC1, offset: Size(0 bytes) }: *const [bool] }}, _marker: PhantomData::<[bool]> }}, std::alloc::Global); - StorageDead(_9); StorageDead(_3); - _1 = A { foo: move _2 }; + _1 = const A {{ foo: Box::<[bool]>(Unique::<[bool]> {{ pointer: NonNull::<[bool]> {{ pointer: Indirect { alloc_id: ALLOC2, offset: Size(0 bytes) }: *const [bool] }}, _marker: PhantomData::<[bool]> }}, std::alloc::Global) }}; @@ -102,6 +69,11 @@ _0 = const (); drop(_1) -> [return: bb1, unwind unreachable]; } + + bb1: { + StorageDead(_1); + return; + } } + + ALLOC2 (size: 16, align: 8) { .. } diff --git a/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.GVN.64bit.panic-unwind.diff b/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.GVN.64bit.panic-unwind.diff index 031c021ba5abf..5dafc89d53f29 100644 --- a/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.GVN.64bit.panic-unwind.diff +++ b/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.GVN.64bit.panic-unwind.diff @@ -16,25 +16,23 @@ scope 4 (inlined Unique::<[bool; 0]>::dangling) { let mut _5: std::ptr::NonNull<[bool; 0]>; scope 5 (inlined NonNull::<[bool; 0]>::dangling) { - let _6: *mut [bool; 0]; + let mut _6: std::num::NonZero; scope 6 { - scope 10 (inlined NonNull::<[bool; 0]>::new_unchecked) { - let mut _8: bool; - let _9: (); - let mut _10: *mut (); - let mut _11: *const [bool; 0]; - scope 11 (inlined core::ub_checks::check_language_ub) { - scope 12 (inlined core::ub_checks::check_language_ub::runtime) { + scope 8 (inlined std::ptr::Alignment::as_nonzero) { + } + scope 9 (inlined NonNull::<[bool; 0]>::without_provenance) { + let _7: *const [bool; 0]; + scope 10 { + } + scope 11 (inlined NonZero::::get) { + } + scope 12 (inlined without_provenance::<[bool; 0]>) { + scope 13 (inlined without_provenance_mut::<[bool; 0]>) { } } } } - scope 7 (inlined dangling_mut::<[bool; 0]>) { - let mut _7: usize; - scope 8 (inlined align_of::<[bool; 0]>) { - } - scope 9 (inlined without_provenance_mut::<[bool; 0]>) { - } + scope 7 (inlined std::ptr::Alignment::of::<[bool; 0]>) { } } } @@ -44,50 +42,16 @@ StorageLive(_1); StorageLive(_2); StorageLive(_3); - StorageLive(_9); StorageLive(_4); StorageLive(_5); StorageLive(_6); +- _6 = const std::ptr::Alignment::of::<[bool; 0]>::{constant#0} as std::num::NonZero (Transmute); ++ _6 = const NonZero::(core::num::niche_types::NonZeroUsizeInner(1_usize)); StorageLive(_7); -- _7 = AlignOf([bool; 0]); -- _6 = copy _7 as *mut [bool; 0] (Transmute); -+ _7 = const 1_usize; -+ _6 = const {0x1 as *mut [bool; 0]}; - StorageLive(_11); - StorageLive(_8); - _8 = UbChecks(); - switchInt(move _8) -> [0: bb5, otherwise: bb3]; - } - - bb1: { - StorageDead(_1); - return; - } - - bb2 (cleanup): { - resume; - } - - bb3: { - StorageLive(_10); -- _10 = copy _7 as *mut () (Transmute); -- _9 = NonNull::::new_unchecked::precondition_check(move _10) -> [return: bb4, unwind unreachable]; -+ _10 = const {0x1 as *mut ()}; -+ _9 = NonNull::::new_unchecked::precondition_check(const {0x1 as *mut ()}) -> [return: bb4, unwind unreachable]; - } - - bb4: { - StorageDead(_10); - goto -> bb5; - } - - bb5: { - StorageDead(_8); -- _11 = copy _7 as *const [bool; 0] (Transmute); -- _5 = NonNull::<[bool; 0]> { pointer: copy _11 }; -+ _11 = const {0x1 as *const [bool; 0]}; +- _7 = copy _6 as *const [bool; 0] (Transmute); +- _5 = NonNull::<[bool; 0]> { pointer: copy _7 }; ++ _7 = const {0x1 as *const [bool; 0]}; + _5 = const NonNull::<[bool; 0]> {{ pointer: {0x1 as *const [bool; 0]} }}; - StorageDead(_11); StorageDead(_7); StorageDead(_6); - _4 = Unique::<[bool; 0]> { pointer: move _5, _marker: const PhantomData::<[bool; 0]> }; @@ -98,7 +62,6 @@ StorageDead(_4); - _2 = Box::<[bool]>(copy _3, const std::alloc::Global); + _2 = const Box::<[bool]>(Unique::<[bool]> {{ pointer: NonNull::<[bool]> {{ pointer: Indirect { alloc_id: ALLOC1, offset: Size(0 bytes) }: *const [bool] }}, _marker: PhantomData::<[bool]> }}, std::alloc::Global); - StorageDead(_9); StorageDead(_3); - _1 = A { foo: move _2 }; + _1 = const A {{ foo: Box::<[bool]>(Unique::<[bool]> {{ pointer: NonNull::<[bool]> {{ pointer: Indirect { alloc_id: ALLOC2, offset: Size(0 bytes) }: *const [bool] }}, _marker: PhantomData::<[bool]> }}, std::alloc::Global) }}; @@ -106,6 +69,15 @@ _0 = const (); drop(_1) -> [return: bb1, unwind: bb2]; } + + bb1: { + StorageDead(_1); + return; + } + + bb2 (cleanup): { + resume; + } } + + ALLOC2 (size: 16, align: 8) { .. } diff --git a/tests/mir-opt/gvn_ptr_eq_with_constant.main.GVN.diff b/tests/mir-opt/gvn_ptr_eq_with_constant.main.GVN.diff index 1e378d30a3e9d..8e7964297d060 100644 --- a/tests/mir-opt/gvn_ptr_eq_with_constant.main.GVN.diff +++ b/tests/mir-opt/gvn_ptr_eq_with_constant.main.GVN.diff @@ -6,17 +6,33 @@ let _1: bool; let mut _2: *mut u8; scope 1 (inlined dangling_mut::) { - let mut _3: usize; - scope 2 (inlined align_of::) { + scope 2 (inlined NonNull::::dangling) { + let mut _3: std::num::NonZero; + scope 3 { + scope 5 (inlined std::ptr::Alignment::as_nonzero) { + } + scope 6 (inlined NonNull::::without_provenance) { + scope 7 { + } + scope 8 (inlined NonZero::::get) { + } + scope 9 (inlined without_provenance::) { + scope 10 (inlined without_provenance_mut::) { + } + } + } + } + scope 4 (inlined std::ptr::Alignment::of::) { + } } - scope 3 (inlined without_provenance_mut::) { + scope 11 (inlined NonNull::::as_ptr) { } } - scope 4 (inlined Foo::::cmp_ptr) { + scope 12 (inlined Foo::::cmp_ptr) { let mut _4: *const u8; let mut _5: *mut u8; let mut _6: *const u8; - scope 5 (inlined std::ptr::eq::) { + scope 13 (inlined std::ptr::eq::) { } } @@ -24,9 +40,9 @@ StorageLive(_1); StorageLive(_2); StorageLive(_3); -- _3 = AlignOf(u8); +- _3 = const std::ptr::Alignment::of::::{constant#0} as std::num::NonZero (Transmute); - _2 = copy _3 as *mut u8 (Transmute); -+ _3 = const 1_usize; ++ _3 = const NonZero::(core::num::niche_types::NonZeroUsizeInner(1_usize)); + _2 = const {0x1 as *mut u8}; StorageDead(_3); StorageLive(_4); 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 a2ef53e0e1308..496ec78fd8d3e 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 @@ -19,30 +19,30 @@ fn enumerated_loop(_1: &[T], _2: impl Fn(usize, &T)) -> () { debug i => _22; debug x => _23; } - scope 18 (inlined > as Iterator>::next) { + scope 19 (inlined > as Iterator>::next) { let mut _14: &mut std::slice::Iter<'_, T>; let mut _15: std::option::Option<&T>; let mut _19: (usize, bool); let mut _20: (usize, &T); - scope 19 { + scope 20 { let _18: usize; - scope 24 { + scope 25 { } } - scope 20 { - scope 21 { - scope 27 (inlined as FromResidual>>::from_residual) { + scope 21 { + scope 22 { + scope 28 (inlined as FromResidual>>::from_residual) { } } } - scope 22 { - scope 23 { + scope 23 { + scope 24 { } } - scope 25 (inlined as Try>::branch) { + scope 26 (inlined as Try>::branch) { let mut _16: isize; let _17: &T; - scope 26 { + scope 27 { } } } @@ -60,10 +60,12 @@ fn enumerated_loop(_1: &[T], _2: impl Fn(usize, &T)) -> () { scope 7 { } scope 12 (inlined without_provenance::) { + scope 13 (inlined without_provenance_mut::) { + } } - scope 13 (inlined NonNull::::as_ptr) { + scope 14 (inlined NonNull::::as_ptr) { } - scope 14 (inlined std::ptr::mut_ptr::::add) { + scope 15 (inlined std::ptr::mut_ptr::::add) { } } scope 8 (inlined as From<&[T]>>::from) { @@ -79,11 +81,11 @@ fn enumerated_loop(_1: &[T], _2: impl Fn(usize, &T)) -> () { } } } - scope 15 (inlined as Iterator>::enumerate) { - scope 16 (inlined Enumerate::>::new) { + scope 16 (inlined as Iterator>::enumerate) { + scope 17 (inlined Enumerate::>::new) { } } - scope 17 (inlined > as IntoIterator>::into_iter) { + scope 18 (inlined > as IntoIterator>::into_iter) { } bb0: { diff --git a/tests/mir-opt/pre-codegen/slice_iter.enumerated_loop.PreCodegen.after.panic-unwind.mir b/tests/mir-opt/pre-codegen/slice_iter.enumerated_loop.PreCodegen.after.panic-unwind.mir index c1b846e662bc2..c4547cb888fab 100644 --- a/tests/mir-opt/pre-codegen/slice_iter.enumerated_loop.PreCodegen.after.panic-unwind.mir +++ b/tests/mir-opt/pre-codegen/slice_iter.enumerated_loop.PreCodegen.after.panic-unwind.mir @@ -35,10 +35,12 @@ fn enumerated_loop(_1: &[T], _2: impl Fn(usize, &T)) -> () { scope 7 { } scope 12 (inlined without_provenance::) { + scope 13 (inlined without_provenance_mut::) { + } } - scope 13 (inlined NonNull::::as_ptr) { + scope 14 (inlined NonNull::::as_ptr) { } - scope 14 (inlined std::ptr::mut_ptr::::add) { + scope 15 (inlined std::ptr::mut_ptr::::add) { } } scope 8 (inlined as From<&[T]>>::from) { @@ -54,11 +56,11 @@ fn enumerated_loop(_1: &[T], _2: impl Fn(usize, &T)) -> () { } } } - scope 15 (inlined as Iterator>::enumerate) { - scope 16 (inlined Enumerate::>::new) { + scope 16 (inlined as Iterator>::enumerate) { + scope 17 (inlined Enumerate::>::new) { } } - scope 17 (inlined > as IntoIterator>::into_iter) { + scope 18 (inlined > as IntoIterator>::into_iter) { } bb0: { 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 8cebf2c6bace6..7d011ea3347f3 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 @@ -32,10 +32,12 @@ fn forward_loop(_1: &[T], _2: impl Fn(&T)) -> () { scope 7 { } scope 12 (inlined without_provenance::) { + scope 13 (inlined without_provenance_mut::) { + } } - scope 13 (inlined NonNull::::as_ptr) { + scope 14 (inlined NonNull::::as_ptr) { } - scope 14 (inlined std::ptr::mut_ptr::::add) { + scope 15 (inlined std::ptr::mut_ptr::::add) { } } scope 8 (inlined as From<&[T]>>::from) { @@ -51,7 +53,7 @@ fn forward_loop(_1: &[T], _2: impl Fn(&T)) -> () { } } } - scope 15 (inlined as IntoIterator>::into_iter) { + scope 16 (inlined as IntoIterator>::into_iter) { } bb0: { 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 e7e39240fed58..75e6542a3a4b0 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 @@ -32,10 +32,12 @@ fn forward_loop(_1: &[T], _2: impl Fn(&T)) -> () { scope 7 { } scope 12 (inlined without_provenance::) { + scope 13 (inlined without_provenance_mut::) { + } } - scope 13 (inlined NonNull::::as_ptr) { + scope 14 (inlined NonNull::::as_ptr) { } - scope 14 (inlined std::ptr::mut_ptr::::add) { + scope 15 (inlined std::ptr::mut_ptr::::add) { } } scope 8 (inlined as From<&[T]>>::from) { @@ -51,7 +53,7 @@ fn forward_loop(_1: &[T], _2: impl Fn(&T)) -> () { } } } - scope 15 (inlined as IntoIterator>::into_iter) { + scope 16 (inlined as IntoIterator>::into_iter) { } bb0: { 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 58f95d0a43231..41bc91ab028dc 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 @@ -18,7 +18,7 @@ fn reverse_loop(_1: &[T], _2: impl Fn(&T)) -> () { scope 2 { debug x => _17; } - scope 18 (inlined > as Iterator>::next) { + scope 19 (inlined > as Iterator>::next) { let mut _14: &mut std::slice::Iter<'_, T>; } } @@ -35,10 +35,12 @@ fn reverse_loop(_1: &[T], _2: impl Fn(&T)) -> () { scope 7 { } scope 12 (inlined without_provenance::) { + scope 13 (inlined without_provenance_mut::) { + } } - scope 13 (inlined NonNull::::as_ptr) { + scope 14 (inlined NonNull::::as_ptr) { } - scope 14 (inlined std::ptr::mut_ptr::::add) { + scope 15 (inlined std::ptr::mut_ptr::::add) { } } scope 8 (inlined as From<&[T]>>::from) { @@ -54,11 +56,11 @@ fn reverse_loop(_1: &[T], _2: impl Fn(&T)) -> () { } } } - scope 15 (inlined as Iterator>::rev) { - scope 16 (inlined Rev::>::new) { + scope 16 (inlined as Iterator>::rev) { + scope 17 (inlined Rev::>::new) { } } - scope 17 (inlined > as IntoIterator>::into_iter) { + scope 18 (inlined > as IntoIterator>::into_iter) { } bb0: { 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 e7ddacf314457..6ed8ef9715bb5 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 @@ -18,7 +18,7 @@ fn reverse_loop(_1: &[T], _2: impl Fn(&T)) -> () { scope 2 { debug x => _17; } - scope 18 (inlined > as Iterator>::next) { + scope 19 (inlined > as Iterator>::next) { let mut _14: &mut std::slice::Iter<'_, T>; } } @@ -35,10 +35,12 @@ fn reverse_loop(_1: &[T], _2: impl Fn(&T)) -> () { scope 7 { } scope 12 (inlined without_provenance::) { + scope 13 (inlined without_provenance_mut::) { + } } - scope 13 (inlined NonNull::::as_ptr) { + scope 14 (inlined NonNull::::as_ptr) { } - scope 14 (inlined std::ptr::mut_ptr::::add) { + scope 15 (inlined std::ptr::mut_ptr::::add) { } } scope 8 (inlined as From<&[T]>>::from) { @@ -54,11 +56,11 @@ fn reverse_loop(_1: &[T], _2: impl Fn(&T)) -> () { } } } - scope 15 (inlined as Iterator>::rev) { - scope 16 (inlined Rev::>::new) { + scope 16 (inlined as Iterator>::rev) { + scope 17 (inlined Rev::>::new) { } } - scope 17 (inlined > as IntoIterator>::into_iter) { + scope 18 (inlined > as IntoIterator>::into_iter) { } bb0: {