diff --git a/library/core/src/intrinsics/mod.rs b/library/core/src/intrinsics/mod.rs index 904aa52c7845b..6e14c797a9a1c 100644 --- a/library/core/src/intrinsics/mod.rs +++ b/library/core/src/intrinsics/mod.rs @@ -2605,6 +2605,7 @@ pub const fn contract_checks() -> bool { // doesn't honor `#[allow_internal_unstable]`, so for the const feature gate we use the user-facing // `contracts` feature rather than the perma-unstable `contracts_internals` #[rustc_const_unstable(feature = "contracts", issue = "128044")] +#[miri::intrinsic_fallback_is_spec] #[lang = "contract_check_requires"] #[rustc_intrinsic] pub const fn contract_check_requires bool + Copy>(cond: C) { @@ -2632,6 +2633,7 @@ pub const fn contract_check_requires bool + Copy>(cond: C) { // `contracts` feature rather than the perma-unstable `contracts_internals`. // Const-checking doesn't honor allow_internal_unstable logic used by contract expansion. #[rustc_const_unstable(feature = "contracts", issue = "128044")] +#[miri::intrinsic_fallback_is_spec] #[lang = "contract_check_ensures"] #[rustc_intrinsic] pub const fn contract_check_ensures bool + Copy, Ret>(cond: C, ret: Ret) -> Ret { diff --git a/library/core/src/lib.rs b/library/core/src/lib.rs index 71abd707374cf..9d1d27a23ec98 100644 --- a/library/core/src/lib.rs +++ b/library/core/src/lib.rs @@ -106,6 +106,7 @@ #![feature(const_cmp)] #![feature(const_destruct)] #![feature(const_eval_select)] +#![feature(contracts)] #![feature(core_intrinsics)] #![feature(coverage_attribute)] #![feature(disjoint_bitor)] diff --git a/library/core/src/mem/mod.rs b/library/core/src/mem/mod.rs index db4c8e9e55150..3eed3da91091a 100644 --- a/library/core/src/mem/mod.rs +++ b/library/core/src/mem/mod.rs @@ -506,6 +506,8 @@ pub const fn align_of() -> usize { #[must_use] #[stable(feature = "rust1", since = "1.0.0")] #[rustc_const_stable(feature = "const_align_of_val", since = "1.85.0")] +#[rustc_allow_const_fn_unstable(contracts)] +#[core::contracts::ensures(|result: &usize| result.is_power_of_two())] pub const fn align_of_val(val: &T) -> usize { // SAFETY: val is a reference, so it's a valid raw pointer unsafe { intrinsics::align_of_val(val) } diff --git a/library/core/src/ptr/alignment.rs b/library/core/src/ptr/alignment.rs index 402634e49b37e..38409116b30d7 100644 --- a/library/core/src/ptr/alignment.rs +++ b/library/core/src/ptr/alignment.rs @@ -45,6 +45,8 @@ impl Alignment { #[unstable(feature = "ptr_alignment_type", issue = "102070")] #[inline] #[must_use] + #[rustc_allow_const_fn_unstable(contracts)] + #[core::contracts::ensures(|result: &Alignment| result.as_usize().is_power_of_two())] pub const fn of() -> Self { // This can't actually panic since type alignment is always a power of two. const { Alignment::new(align_of::()).unwrap() } @@ -56,6 +58,11 @@ impl Alignment { /// Note that `0` is not a power of two, nor a valid alignment. #[unstable(feature = "ptr_alignment_type", issue = "102070")] #[inline] + #[rustc_allow_const_fn_unstable(contracts)] + #[core::contracts::ensures( + move |result: &Option| + align.is_power_of_two() == result.is_some() && + (result.is_none() || result.unwrap().as_usize() == align))] pub const fn new(align: usize) -> Option { if align.is_power_of_two() { // SAFETY: Just checked it only has one bit set @@ -76,6 +83,12 @@ impl Alignment { #[unstable(feature = "ptr_alignment_type", issue = "102070")] #[inline] #[track_caller] + #[rustc_allow_const_fn_unstable(contracts)] + #[allow(unused_parens)] + #[core::contracts::requires(align.is_power_of_two())] + #[core::contracts::ensures( + move |result: &Alignment| + result.as_usize() == align && result.as_usize().is_power_of_two())] pub const unsafe fn new_unchecked(align: usize) -> Self { assert_unsafe_precondition!( check_language_ub, @@ -91,6 +104,8 @@ impl Alignment { /// Returns the alignment as a [`usize`]. #[unstable(feature = "ptr_alignment_type", issue = "102070")] #[inline] + #[rustc_allow_const_fn_unstable(contracts)] + #[core::contracts::ensures(|result: &usize| result.is_power_of_two())] pub const fn as_usize(self) -> usize { self.0 as usize } @@ -98,6 +113,10 @@ impl Alignment { /// Returns the alignment as a [NonZero]<[usize]>. #[unstable(feature = "ptr_alignment_type", issue = "102070")] #[inline] + #[rustc_allow_const_fn_unstable(contracts)] + #[core::contracts::ensures( + move |result: &NonZero| + result.get().is_power_of_two() && result.get() == self.as_usize())] 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 @@ -123,6 +142,12 @@ impl Alignment { /// ``` #[unstable(feature = "ptr_alignment_type", issue = "102070")] #[inline] + #[rustc_const_unstable(feature = "contracts", issue = "128044")] + #[allow(unused_parens)] + #[core::contracts::requires(self.as_usize().is_power_of_two())] + #[core::contracts::ensures( + move |result: &u32| + *result < usize::BITS && (1usize << *result) == self.as_usize())] pub const fn log2(self) -> u32 { self.as_nonzero().trailing_zeros() } @@ -152,6 +177,11 @@ impl Alignment { /// ``` #[unstable(feature = "ptr_alignment_type", issue = "102070")] #[inline] + #[rustc_const_unstable(feature = "contracts", issue = "128044")] + #[core::contracts::ensures( + move |result: &usize| + *result > 0 && *result == !(self.as_usize() -1) && + self.as_usize() & *result == self.as_usize())] pub const fn mask(self) -> usize { // SAFETY: The alignment is always nonzero, and therefore decrementing won't overflow. !(unsafe { self.as_usize().unchecked_sub(1) }) diff --git a/src/tools/miri/tests/pass/shims/time-with-isolation.rs b/src/tools/miri/tests/pass/shims/time-with-isolation.rs index e7b1624412358..dd4d96e490c89 100644 --- a/src/tools/miri/tests/pass/shims/time-with-isolation.rs +++ b/src/tools/miri/tests/pass/shims/time-with-isolation.rs @@ -27,7 +27,7 @@ fn test_time_passes() { // if `NANOSECONDS_PER_BASIC_BLOCK` changes. It may also need updating if the standard library // code that runs in the loop above changes. assert!(diff.as_millis() > 5); - assert!(diff.as_millis() < 20); + assert!(diff.as_millis() < 25); } fn test_block_for_one_second() { diff --git a/tests/codegen-llvm/cross-crate-inlining/auxiliary/leaf.rs b/tests/codegen-llvm/cross-crate-inlining/auxiliary/leaf.rs index d059a3d0a73b8..fab2762347775 100644 --- a/tests/codegen-llvm/cross-crate-inlining/auxiliary/leaf.rs +++ b/tests/codegen-llvm/cross-crate-inlining/auxiliary/leaf.rs @@ -4,8 +4,8 @@ // This function *looks* like it contains a call, but that call will be optimized out by MIR // optimizations. -pub fn leaf_fn() -> String { - String::new() +pub fn leaf_fn() -> bool { + Some(0).is_some() } // This function contains a call, even after MIR optimizations. It is only eligible for diff --git a/tests/codegen-llvm/cross-crate-inlining/leaf-inlining.rs b/tests/codegen-llvm/cross-crate-inlining/leaf-inlining.rs index 37132312ca94c..a80200fb3cadc 100644 --- a/tests/codegen-llvm/cross-crate-inlining/leaf-inlining.rs +++ b/tests/codegen-llvm/cross-crate-inlining/leaf-inlining.rs @@ -7,7 +7,7 @@ extern crate leaf; // Check that we inline a leaf cross-crate call #[no_mangle] -pub fn leaf_outer() -> String { +pub fn leaf_outer() -> bool { // CHECK-NOT: call {{.*}}leaf_fn leaf::leaf_fn() } 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 2c89670dcf7d7..e22e91ce09cf4 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,23 +16,34 @@ scope 4 (inlined Unique::<[bool; 0]>::dangling) { let mut _5: std::ptr::NonNull<[bool; 0]>; scope 5 (inlined NonNull::<[bool; 0]>::dangling) { - let mut _6: std::num::NonZero; + let _6: std::ptr::Alignment; + let mut _7: std::num::NonZero; scope 6 { - scope 8 (inlined std::ptr::Alignment::as_nonzero) { + scope 10 (inlined std::ptr::Alignment::as_nonzero) { + let mut _8: {closure@std::ptr::Alignment::as_nonzero::{closure#0}}; + let mut _9: std::num::NonZero; + scope 11 { + } + scope 12 (inlined core::contracts::build_check_ensures::, {closure@std::ptr::Alignment::as_nonzero::{closure#0}}>) { + } } - scope 9 (inlined NonNull::<[bool; 0]>::without_provenance) { - let _7: *const [bool; 0]; - scope 10 { + scope 13 (inlined NonNull::<[bool; 0]>::without_provenance) { + let _10: *const [bool; 0]; + scope 14 { } - scope 11 (inlined NonZero::::get) { + scope 15 (inlined NonZero::::get) { } - scope 12 (inlined std::ptr::without_provenance::<[bool; 0]>) { - scope 13 (inlined without_provenance_mut::<[bool; 0]>) { + scope 16 (inlined std::ptr::without_provenance::<[bool; 0]>) { + scope 17 (inlined without_provenance_mut::<[bool; 0]>) { } } } } scope 7 (inlined std::ptr::Alignment::of::<[bool; 0]>) { + scope 8 { + } + scope 9 (inlined core::contracts::build_check_ensures::::{closure#0}}>) { + } } } } @@ -45,33 +56,42 @@ StorageLive(_4); StorageLive(_5); StorageLive(_6); - _6 = const NonZero::(core::num::niche_types::NonZeroUsizeInner(1_usize)); + _6 = contract_check_ensures::<{closure@std::ptr::Alignment::of<[bool; 0]>::{closure#0}}, std::ptr::Alignment>(const ZeroSized: {closure@std::ptr::Alignment::of<[bool; 0]>::{closure#0}}, const std::ptr::Alignment::of::<[bool; 0]>::{constant#0}) -> [return: bb2, unwind unreachable]; + } + + bb1: { + StorageDead(_1); + return; + } + + bb2: { StorageLive(_7); - _7 = const {0x1 as *const [bool; 0]}; - _5 = const NonNull::<[bool; 0]> {{ pointer: {0x1 as *const [bool; 0]} }}; + StorageLive(_8); + _8 = {closure@$SRC_DIR/core/src/ptr/alignment.rs:LL:COL} { 0: copy _6 }; + StorageLive(_9); + _9 = copy _6 as std::num::NonZero (Transmute); + _7 = contract_check_ensures::<{closure@std::ptr::Alignment::as_nonzero::{closure#0}}, NonZero>(move _8, move _9) -> [return: bb3, unwind unreachable]; + } + + bb3: { + StorageDead(_9); + StorageDead(_8); + StorageLive(_10); + _10 = copy _7 as *const [bool; 0] (Transmute); + _5 = NonNull::<[bool; 0]> { pointer: copy _10 }; + StorageDead(_10); StorageDead(_7); StorageDead(_6); - _4 = const Unique::<[bool; 0]> {{ pointer: NonNull::<[bool; 0]> {{ pointer: {0x1 as *const [bool; 0]} }}, _marker: PhantomData::<[bool; 0]> }}; + _4 = Unique::<[bool; 0]> { pointer: move _5, _marker: const PhantomData::<[bool; 0]> }; StorageDead(_5); - _3 = const Unique::<[bool]> {{ pointer: NonNull::<[bool]> {{ pointer: Indirect { alloc_id: ALLOC0, offset: Size(0 bytes) }: *const [bool] }}, _marker: PhantomData::<[bool]> }}; + _3 = move _4 as std::ptr::Unique<[bool]> (PointerCoercion(Unsize, Implicit)); 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); + _2 = Box::<[bool]>(copy _3, const std::alloc::Global); 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) }}; + _1 = A { foo: move _2 }; StorageDead(_2); _0 = const (); drop(_1) -> [return: bb1, unwind unreachable]; } - - bb1: { - StorageDead(_1); - return; - } } - ALLOC2 (size: 8, align: 4) { .. } - - ALLOC1 (size: 8, align: 4) { .. } - - ALLOC0 (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 8fecfe224cc69..d98a016c85f41 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,23 +16,34 @@ scope 4 (inlined Unique::<[bool; 0]>::dangling) { let mut _5: std::ptr::NonNull<[bool; 0]>; scope 5 (inlined NonNull::<[bool; 0]>::dangling) { - let mut _6: std::num::NonZero; + let _6: std::ptr::Alignment; + let mut _7: std::num::NonZero; scope 6 { - scope 8 (inlined std::ptr::Alignment::as_nonzero) { + scope 10 (inlined std::ptr::Alignment::as_nonzero) { + let mut _8: {closure@std::ptr::Alignment::as_nonzero::{closure#0}}; + let mut _9: std::num::NonZero; + scope 11 { + } + scope 12 (inlined core::contracts::build_check_ensures::, {closure@std::ptr::Alignment::as_nonzero::{closure#0}}>) { + } } - scope 9 (inlined NonNull::<[bool; 0]>::without_provenance) { - let _7: *const [bool; 0]; - scope 10 { + scope 13 (inlined NonNull::<[bool; 0]>::without_provenance) { + let _10: *const [bool; 0]; + scope 14 { } - scope 11 (inlined NonZero::::get) { + scope 15 (inlined NonZero::::get) { } - scope 12 (inlined std::ptr::without_provenance::<[bool; 0]>) { - scope 13 (inlined without_provenance_mut::<[bool; 0]>) { + scope 16 (inlined std::ptr::without_provenance::<[bool; 0]>) { + scope 17 (inlined without_provenance_mut::<[bool; 0]>) { } } } } scope 7 (inlined std::ptr::Alignment::of::<[bool; 0]>) { + scope 8 { + } + scope 9 (inlined core::contracts::build_check_ensures::::{closure#0}}>) { + } } } } @@ -45,22 +56,7 @@ StorageLive(_4); StorageLive(_5); StorageLive(_6); - _6 = const NonZero::(core::num::niche_types::NonZeroUsizeInner(1_usize)); - StorageLive(_7); - _7 = const {0x1 as *const [bool; 0]}; - _5 = const NonNull::<[bool; 0]> {{ pointer: {0x1 as *const [bool; 0]} }}; - StorageDead(_7); - StorageDead(_6); - _4 = const Unique::<[bool; 0]> {{ pointer: NonNull::<[bool; 0]> {{ pointer: {0x1 as *const [bool; 0]} }}, _marker: PhantomData::<[bool; 0]> }}; - StorageDead(_5); - _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(_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]; + _6 = contract_check_ensures::<{closure@std::ptr::Alignment::of<[bool; 0]>::{closure#0}}, std::ptr::Alignment>(const ZeroSized: {closure@std::ptr::Alignment::of<[bool; 0]>::{closure#0}}, const std::ptr::Alignment::of::<[bool; 0]>::{constant#0}) -> [return: bb3, unwind continue]; } bb1: { @@ -71,11 +67,35 @@ bb2 (cleanup): { resume; } - } - ALLOC2 (size: 8, align: 4) { .. } - - ALLOC1 (size: 8, align: 4) { .. } + bb3: { + StorageLive(_7); + StorageLive(_8); + _8 = {closure@$SRC_DIR/core/src/ptr/alignment.rs:LL:COL} { 0: copy _6 }; + StorageLive(_9); + _9 = copy _6 as std::num::NonZero (Transmute); + _7 = contract_check_ensures::<{closure@std::ptr::Alignment::as_nonzero::{closure#0}}, NonZero>(move _8, move _9) -> [return: bb4, unwind continue]; + } - ALLOC0 (size: 8, align: 4) { .. } + bb4: { + StorageDead(_9); + StorageDead(_8); + StorageLive(_10); + _10 = copy _7 as *const [bool; 0] (Transmute); + _5 = NonNull::<[bool; 0]> { pointer: copy _10 }; + StorageDead(_10); + StorageDead(_7); + StorageDead(_6); + _4 = Unique::<[bool; 0]> { pointer: move _5, _marker: const PhantomData::<[bool; 0]> }; + StorageDead(_5); + _3 = move _4 as std::ptr::Unique<[bool]> (PointerCoercion(Unsize, Implicit)); + StorageDead(_4); + _2 = Box::<[bool]>(copy _3, const std::alloc::Global); + StorageDead(_3); + _1 = A { foo: move _2 }; + StorageDead(_2); + _0 = const (); + drop(_1) -> [return: bb1, unwind: bb2]; + } + } 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 976ea252c2f89..e22e91ce09cf4 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,23 +16,34 @@ scope 4 (inlined Unique::<[bool; 0]>::dangling) { let mut _5: std::ptr::NonNull<[bool; 0]>; scope 5 (inlined NonNull::<[bool; 0]>::dangling) { - let mut _6: std::num::NonZero; + let _6: std::ptr::Alignment; + let mut _7: std::num::NonZero; scope 6 { - scope 8 (inlined std::ptr::Alignment::as_nonzero) { + scope 10 (inlined std::ptr::Alignment::as_nonzero) { + let mut _8: {closure@std::ptr::Alignment::as_nonzero::{closure#0}}; + let mut _9: std::num::NonZero; + scope 11 { + } + scope 12 (inlined core::contracts::build_check_ensures::, {closure@std::ptr::Alignment::as_nonzero::{closure#0}}>) { + } } - scope 9 (inlined NonNull::<[bool; 0]>::without_provenance) { - let _7: *const [bool; 0]; - scope 10 { + scope 13 (inlined NonNull::<[bool; 0]>::without_provenance) { + let _10: *const [bool; 0]; + scope 14 { } - scope 11 (inlined NonZero::::get) { + scope 15 (inlined NonZero::::get) { } - scope 12 (inlined std::ptr::without_provenance::<[bool; 0]>) { - scope 13 (inlined without_provenance_mut::<[bool; 0]>) { + scope 16 (inlined std::ptr::without_provenance::<[bool; 0]>) { + scope 17 (inlined without_provenance_mut::<[bool; 0]>) { } } } } scope 7 (inlined std::ptr::Alignment::of::<[bool; 0]>) { + scope 8 { + } + scope 9 (inlined core::contracts::build_check_ensures::::{closure#0}}>) { + } } } } @@ -45,33 +56,42 @@ StorageLive(_4); StorageLive(_5); StorageLive(_6); - _6 = const NonZero::(core::num::niche_types::NonZeroUsizeInner(1_usize)); + _6 = contract_check_ensures::<{closure@std::ptr::Alignment::of<[bool; 0]>::{closure#0}}, std::ptr::Alignment>(const ZeroSized: {closure@std::ptr::Alignment::of<[bool; 0]>::{closure#0}}, const std::ptr::Alignment::of::<[bool; 0]>::{constant#0}) -> [return: bb2, unwind unreachable]; + } + + bb1: { + StorageDead(_1); + return; + } + + bb2: { StorageLive(_7); - _7 = const {0x1 as *const [bool; 0]}; - _5 = const NonNull::<[bool; 0]> {{ pointer: {0x1 as *const [bool; 0]} }}; + StorageLive(_8); + _8 = {closure@$SRC_DIR/core/src/ptr/alignment.rs:LL:COL} { 0: copy _6 }; + StorageLive(_9); + _9 = copy _6 as std::num::NonZero (Transmute); + _7 = contract_check_ensures::<{closure@std::ptr::Alignment::as_nonzero::{closure#0}}, NonZero>(move _8, move _9) -> [return: bb3, unwind unreachable]; + } + + bb3: { + StorageDead(_9); + StorageDead(_8); + StorageLive(_10); + _10 = copy _7 as *const [bool; 0] (Transmute); + _5 = NonNull::<[bool; 0]> { pointer: copy _10 }; + StorageDead(_10); StorageDead(_7); StorageDead(_6); - _4 = const Unique::<[bool; 0]> {{ pointer: NonNull::<[bool; 0]> {{ pointer: {0x1 as *const [bool; 0]} }}, _marker: PhantomData::<[bool; 0]> }}; + _4 = Unique::<[bool; 0]> { pointer: move _5, _marker: const PhantomData::<[bool; 0]> }; StorageDead(_5); - _3 = const Unique::<[bool]> {{ pointer: NonNull::<[bool]> {{ pointer: Indirect { alloc_id: ALLOC0, offset: Size(0 bytes) }: *const [bool] }}, _marker: PhantomData::<[bool]> }}; + _3 = move _4 as std::ptr::Unique<[bool]> (PointerCoercion(Unsize, Implicit)); 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); + _2 = Box::<[bool]>(copy _3, const std::alloc::Global); 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) }}; + _1 = A { foo: move _2 }; StorageDead(_2); _0 = const (); drop(_1) -> [return: bb1, unwind unreachable]; } - - bb1: { - StorageDead(_1); - return; - } } - ALLOC2 (size: 16, align: 8) { .. } - - ALLOC1 (size: 16, align: 8) { .. } - - ALLOC0 (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 6c59f5e3e2e86..d98a016c85f41 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,23 +16,34 @@ scope 4 (inlined Unique::<[bool; 0]>::dangling) { let mut _5: std::ptr::NonNull<[bool; 0]>; scope 5 (inlined NonNull::<[bool; 0]>::dangling) { - let mut _6: std::num::NonZero; + let _6: std::ptr::Alignment; + let mut _7: std::num::NonZero; scope 6 { - scope 8 (inlined std::ptr::Alignment::as_nonzero) { + scope 10 (inlined std::ptr::Alignment::as_nonzero) { + let mut _8: {closure@std::ptr::Alignment::as_nonzero::{closure#0}}; + let mut _9: std::num::NonZero; + scope 11 { + } + scope 12 (inlined core::contracts::build_check_ensures::, {closure@std::ptr::Alignment::as_nonzero::{closure#0}}>) { + } } - scope 9 (inlined NonNull::<[bool; 0]>::without_provenance) { - let _7: *const [bool; 0]; - scope 10 { + scope 13 (inlined NonNull::<[bool; 0]>::without_provenance) { + let _10: *const [bool; 0]; + scope 14 { } - scope 11 (inlined NonZero::::get) { + scope 15 (inlined NonZero::::get) { } - scope 12 (inlined std::ptr::without_provenance::<[bool; 0]>) { - scope 13 (inlined without_provenance_mut::<[bool; 0]>) { + scope 16 (inlined std::ptr::without_provenance::<[bool; 0]>) { + scope 17 (inlined without_provenance_mut::<[bool; 0]>) { } } } } scope 7 (inlined std::ptr::Alignment::of::<[bool; 0]>) { + scope 8 { + } + scope 9 (inlined core::contracts::build_check_ensures::::{closure#0}}>) { + } } } } @@ -45,22 +56,7 @@ StorageLive(_4); StorageLive(_5); StorageLive(_6); - _6 = const NonZero::(core::num::niche_types::NonZeroUsizeInner(1_usize)); - StorageLive(_7); - _7 = const {0x1 as *const [bool; 0]}; - _5 = const NonNull::<[bool; 0]> {{ pointer: {0x1 as *const [bool; 0]} }}; - StorageDead(_7); - StorageDead(_6); - _4 = const Unique::<[bool; 0]> {{ pointer: NonNull::<[bool; 0]> {{ pointer: {0x1 as *const [bool; 0]} }}, _marker: PhantomData::<[bool; 0]> }}; - StorageDead(_5); - _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(_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]; + _6 = contract_check_ensures::<{closure@std::ptr::Alignment::of<[bool; 0]>::{closure#0}}, std::ptr::Alignment>(const ZeroSized: {closure@std::ptr::Alignment::of<[bool; 0]>::{closure#0}}, const std::ptr::Alignment::of::<[bool; 0]>::{constant#0}) -> [return: bb3, unwind continue]; } bb1: { @@ -71,11 +67,35 @@ bb2 (cleanup): { resume; } - } - ALLOC2 (size: 16, align: 8) { .. } - - ALLOC1 (size: 16, align: 8) { .. } + bb3: { + StorageLive(_7); + StorageLive(_8); + _8 = {closure@$SRC_DIR/core/src/ptr/alignment.rs:LL:COL} { 0: copy _6 }; + StorageLive(_9); + _9 = copy _6 as std::num::NonZero (Transmute); + _7 = contract_check_ensures::<{closure@std::ptr::Alignment::as_nonzero::{closure#0}}, NonZero>(move _8, move _9) -> [return: bb4, unwind continue]; + } - ALLOC0 (size: 16, align: 8) { .. } + bb4: { + StorageDead(_9); + StorageDead(_8); + StorageLive(_10); + _10 = copy _7 as *const [bool; 0] (Transmute); + _5 = NonNull::<[bool; 0]> { pointer: copy _10 }; + StorageDead(_10); + StorageDead(_7); + StorageDead(_6); + _4 = Unique::<[bool; 0]> { pointer: move _5, _marker: const PhantomData::<[bool; 0]> }; + StorageDead(_5); + _3 = move _4 as std::ptr::Unique<[bool]> (PointerCoercion(Unsize, Implicit)); + StorageDead(_4); + _2 = Box::<[bool]>(copy _3, const std::alloc::Global); + StorageDead(_3); + _1 = A { foo: move _2 }; + StorageDead(_2); + _0 = const (); + drop(_1) -> [return: bb1, unwind: bb2]; + } + } 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 1f9cf6d6aca83..df8d93565d5a6 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,23 +16,34 @@ scope 4 (inlined Unique::<[bool; 0]>::dangling) { let mut _5: std::ptr::NonNull<[bool; 0]>; scope 5 (inlined NonNull::<[bool; 0]>::dangling) { - let mut _6: std::num::NonZero; + let _6: std::ptr::Alignment; + let mut _7: std::num::NonZero; scope 6 { - scope 8 (inlined std::ptr::Alignment::as_nonzero) { + scope 10 (inlined std::ptr::Alignment::as_nonzero) { + let mut _8: {closure@std::ptr::Alignment::as_nonzero::{closure#0}}; + let mut _9: std::num::NonZero; + scope 11 { + } + scope 12 (inlined core::contracts::build_check_ensures::, {closure@std::ptr::Alignment::as_nonzero::{closure#0}}>) { + } } - scope 9 (inlined NonNull::<[bool; 0]>::without_provenance) { - let _7: *const [bool; 0]; - scope 10 { + scope 13 (inlined NonNull::<[bool; 0]>::without_provenance) { + let _10: *const [bool; 0]; + scope 14 { } - scope 11 (inlined NonZero::::get) { + scope 15 (inlined NonZero::::get) { } - scope 12 (inlined std::ptr::without_provenance::<[bool; 0]>) { - scope 13 (inlined without_provenance_mut::<[bool; 0]>) { + scope 16 (inlined std::ptr::without_provenance::<[bool; 0]>) { + scope 17 (inlined without_provenance_mut::<[bool; 0]>) { } } } } scope 7 (inlined std::ptr::Alignment::of::<[bool; 0]>) { + scope 8 { + } + scope 9 (inlined core::contracts::build_check_ensures::::{closure#0}}>) { + } } } } @@ -45,40 +56,42 @@ 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)); + _6 = contract_check_ensures::<{closure@std::ptr::Alignment::of<[bool; 0]>::{closure#0}}, std::ptr::Alignment>(const ZeroSized: {closure@std::ptr::Alignment::of<[bool; 0]>::{closure#0}}, const std::ptr::Alignment::of::<[bool; 0]>::{constant#0}) -> [return: bb2, unwind unreachable]; + } + + bb1: { + StorageDead(_1); + return; + } + + bb2: { StorageLive(_7); -- _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]} }}; + StorageLive(_8); + _8 = {closure@$SRC_DIR/core/src/ptr/alignment.rs:LL:COL} { 0: copy _6 }; + StorageLive(_9); + _9 = copy _6 as std::num::NonZero (Transmute); + _7 = contract_check_ensures::<{closure@std::ptr::Alignment::as_nonzero::{closure#0}}, NonZero>(move _8, move _9) -> [return: bb3, unwind unreachable]; + } + + bb3: { + StorageDead(_9); + StorageDead(_8); + StorageLive(_10); + _10 = copy _7 as *const [bool; 0] (Transmute); + _5 = NonNull::<[bool; 0]> { pointer: copy _10 }; + StorageDead(_10); StorageDead(_7); StorageDead(_6); -- _4 = Unique::<[bool; 0]> { pointer: move _5, _marker: const PhantomData::<[bool; 0]> }; -+ _4 = const Unique::<[bool; 0]> {{ pointer: NonNull::<[bool; 0]> {{ pointer: {0x1 as *const [bool; 0]} }}, _marker: PhantomData::<[bool; 0]> }}; + _4 = Unique::<[bool; 0]> { pointer: move _5, _marker: const PhantomData::<[bool; 0]> }; StorageDead(_5); -- _3 = move _4 as std::ptr::Unique<[bool]> (PointerCoercion(Unsize, Implicit)); -+ _3 = const Unique::<[bool]> {{ pointer: NonNull::<[bool]> {{ pointer: Indirect { alloc_id: ALLOC0, offset: Size(0 bytes) }: *const [bool] }}, _marker: PhantomData::<[bool]> }}; + _3 = move _4 as std::ptr::Unique<[bool]> (PointerCoercion(Unsize, Implicit)); 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); + _2 = Box::<[bool]>(copy _3, const std::alloc::Global); 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) }}; + _1 = A { foo: move _2 }; StorageDead(_2); _0 = const (); drop(_1) -> [return: bb1, unwind unreachable]; } - - bb1: { - StorageDead(_1); - return; - } } -+ -+ ALLOC2 (size: 8, align: 4) { .. } -+ -+ ALLOC1 (size: 8, align: 4) { .. } -+ -+ ALLOC0 (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 a8760285fac11..0abce626aeb75 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,23 +16,34 @@ scope 4 (inlined Unique::<[bool; 0]>::dangling) { let mut _5: std::ptr::NonNull<[bool; 0]>; scope 5 (inlined NonNull::<[bool; 0]>::dangling) { - let mut _6: std::num::NonZero; + let _6: std::ptr::Alignment; + let mut _7: std::num::NonZero; scope 6 { - scope 8 (inlined std::ptr::Alignment::as_nonzero) { + scope 10 (inlined std::ptr::Alignment::as_nonzero) { + let mut _8: {closure@std::ptr::Alignment::as_nonzero::{closure#0}}; + let mut _9: std::num::NonZero; + scope 11 { + } + scope 12 (inlined core::contracts::build_check_ensures::, {closure@std::ptr::Alignment::as_nonzero::{closure#0}}>) { + } } - scope 9 (inlined NonNull::<[bool; 0]>::without_provenance) { - let _7: *const [bool; 0]; - scope 10 { + scope 13 (inlined NonNull::<[bool; 0]>::without_provenance) { + let _10: *const [bool; 0]; + scope 14 { } - scope 11 (inlined NonZero::::get) { + scope 15 (inlined NonZero::::get) { } - scope 12 (inlined std::ptr::without_provenance::<[bool; 0]>) { - scope 13 (inlined without_provenance_mut::<[bool; 0]>) { + scope 16 (inlined std::ptr::without_provenance::<[bool; 0]>) { + scope 17 (inlined without_provenance_mut::<[bool; 0]>) { } } } } scope 7 (inlined std::ptr::Alignment::of::<[bool; 0]>) { + scope 8 { + } + scope 9 (inlined core::contracts::build_check_ensures::::{closure#0}}>) { + } } } } @@ -45,29 +56,7 @@ 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 = 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(_7); - StorageDead(_6); -- _4 = Unique::<[bool; 0]> { pointer: move _5, _marker: const PhantomData::<[bool; 0]> }; -+ _4 = const Unique::<[bool; 0]> {{ pointer: NonNull::<[bool; 0]> {{ pointer: {0x1 as *const [bool; 0]} }}, _marker: PhantomData::<[bool; 0]> }}; - StorageDead(_5); -- _3 = move _4 as std::ptr::Unique<[bool]> (PointerCoercion(Unsize, Implicit)); -+ _3 = const Unique::<[bool]> {{ pointer: NonNull::<[bool]> {{ pointer: Indirect { alloc_id: ALLOC0, offset: Size(0 bytes) }: *const [bool] }}, _marker: PhantomData::<[bool]> }}; - 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(_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) }}; - StorageDead(_2); - _0 = const (); - drop(_1) -> [return: bb1, unwind: bb2]; + _6 = contract_check_ensures::<{closure@std::ptr::Alignment::of<[bool; 0]>::{closure#0}}, std::ptr::Alignment>(const ZeroSized: {closure@std::ptr::Alignment::of<[bool; 0]>::{closure#0}}, const std::ptr::Alignment::of::<[bool; 0]>::{constant#0}) -> [return: bb3, unwind continue]; } bb1: { @@ -78,11 +67,35 @@ bb2 (cleanup): { resume; } + + bb3: { + StorageLive(_7); + StorageLive(_8); + _8 = {closure@$SRC_DIR/core/src/ptr/alignment.rs:LL:COL} { 0: copy _6 }; + StorageLive(_9); + _9 = copy _6 as std::num::NonZero (Transmute); + _7 = contract_check_ensures::<{closure@std::ptr::Alignment::as_nonzero::{closure#0}}, NonZero>(move _8, move _9) -> [return: bb4, unwind continue]; + } + + bb4: { + StorageDead(_9); + StorageDead(_8); + StorageLive(_10); + _10 = copy _7 as *const [bool; 0] (Transmute); + _5 = NonNull::<[bool; 0]> { pointer: copy _10 }; + StorageDead(_10); + StorageDead(_7); + StorageDead(_6); + _4 = Unique::<[bool; 0]> { pointer: move _5, _marker: const PhantomData::<[bool; 0]> }; + StorageDead(_5); + _3 = move _4 as std::ptr::Unique<[bool]> (PointerCoercion(Unsize, Implicit)); + StorageDead(_4); + _2 = Box::<[bool]>(copy _3, const std::alloc::Global); + StorageDead(_3); + _1 = A { foo: move _2 }; + StorageDead(_2); + _0 = const (); + drop(_1) -> [return: bb1, unwind: bb2]; + } } -+ -+ ALLOC2 (size: 8, align: 4) { .. } -+ -+ ALLOC1 (size: 8, align: 4) { .. } -+ -+ ALLOC0 (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 c398ae70a1a3e..df8d93565d5a6 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,23 +16,34 @@ scope 4 (inlined Unique::<[bool; 0]>::dangling) { let mut _5: std::ptr::NonNull<[bool; 0]>; scope 5 (inlined NonNull::<[bool; 0]>::dangling) { - let mut _6: std::num::NonZero; + let _6: std::ptr::Alignment; + let mut _7: std::num::NonZero; scope 6 { - scope 8 (inlined std::ptr::Alignment::as_nonzero) { + scope 10 (inlined std::ptr::Alignment::as_nonzero) { + let mut _8: {closure@std::ptr::Alignment::as_nonzero::{closure#0}}; + let mut _9: std::num::NonZero; + scope 11 { + } + scope 12 (inlined core::contracts::build_check_ensures::, {closure@std::ptr::Alignment::as_nonzero::{closure#0}}>) { + } } - scope 9 (inlined NonNull::<[bool; 0]>::without_provenance) { - let _7: *const [bool; 0]; - scope 10 { + scope 13 (inlined NonNull::<[bool; 0]>::without_provenance) { + let _10: *const [bool; 0]; + scope 14 { } - scope 11 (inlined NonZero::::get) { + scope 15 (inlined NonZero::::get) { } - scope 12 (inlined std::ptr::without_provenance::<[bool; 0]>) { - scope 13 (inlined without_provenance_mut::<[bool; 0]>) { + scope 16 (inlined std::ptr::without_provenance::<[bool; 0]>) { + scope 17 (inlined without_provenance_mut::<[bool; 0]>) { } } } } scope 7 (inlined std::ptr::Alignment::of::<[bool; 0]>) { + scope 8 { + } + scope 9 (inlined core::contracts::build_check_ensures::::{closure#0}}>) { + } } } } @@ -45,40 +56,42 @@ 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)); + _6 = contract_check_ensures::<{closure@std::ptr::Alignment::of<[bool; 0]>::{closure#0}}, std::ptr::Alignment>(const ZeroSized: {closure@std::ptr::Alignment::of<[bool; 0]>::{closure#0}}, const std::ptr::Alignment::of::<[bool; 0]>::{constant#0}) -> [return: bb2, unwind unreachable]; + } + + bb1: { + StorageDead(_1); + return; + } + + bb2: { StorageLive(_7); -- _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]} }}; + StorageLive(_8); + _8 = {closure@$SRC_DIR/core/src/ptr/alignment.rs:LL:COL} { 0: copy _6 }; + StorageLive(_9); + _9 = copy _6 as std::num::NonZero (Transmute); + _7 = contract_check_ensures::<{closure@std::ptr::Alignment::as_nonzero::{closure#0}}, NonZero>(move _8, move _9) -> [return: bb3, unwind unreachable]; + } + + bb3: { + StorageDead(_9); + StorageDead(_8); + StorageLive(_10); + _10 = copy _7 as *const [bool; 0] (Transmute); + _5 = NonNull::<[bool; 0]> { pointer: copy _10 }; + StorageDead(_10); StorageDead(_7); StorageDead(_6); -- _4 = Unique::<[bool; 0]> { pointer: move _5, _marker: const PhantomData::<[bool; 0]> }; -+ _4 = const Unique::<[bool; 0]> {{ pointer: NonNull::<[bool; 0]> {{ pointer: {0x1 as *const [bool; 0]} }}, _marker: PhantomData::<[bool; 0]> }}; + _4 = Unique::<[bool; 0]> { pointer: move _5, _marker: const PhantomData::<[bool; 0]> }; StorageDead(_5); -- _3 = move _4 as std::ptr::Unique<[bool]> (PointerCoercion(Unsize, Implicit)); -+ _3 = const Unique::<[bool]> {{ pointer: NonNull::<[bool]> {{ pointer: Indirect { alloc_id: ALLOC0, offset: Size(0 bytes) }: *const [bool] }}, _marker: PhantomData::<[bool]> }}; + _3 = move _4 as std::ptr::Unique<[bool]> (PointerCoercion(Unsize, Implicit)); 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); + _2 = Box::<[bool]>(copy _3, const std::alloc::Global); 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) }}; + _1 = A { foo: move _2 }; StorageDead(_2); _0 = const (); drop(_1) -> [return: bb1, unwind unreachable]; } - - bb1: { - StorageDead(_1); - return; - } } -+ -+ ALLOC2 (size: 16, align: 8) { .. } -+ -+ ALLOC1 (size: 16, align: 8) { .. } -+ -+ ALLOC0 (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 02934c02587d2..0abce626aeb75 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,23 +16,34 @@ scope 4 (inlined Unique::<[bool; 0]>::dangling) { let mut _5: std::ptr::NonNull<[bool; 0]>; scope 5 (inlined NonNull::<[bool; 0]>::dangling) { - let mut _6: std::num::NonZero; + let _6: std::ptr::Alignment; + let mut _7: std::num::NonZero; scope 6 { - scope 8 (inlined std::ptr::Alignment::as_nonzero) { + scope 10 (inlined std::ptr::Alignment::as_nonzero) { + let mut _8: {closure@std::ptr::Alignment::as_nonzero::{closure#0}}; + let mut _9: std::num::NonZero; + scope 11 { + } + scope 12 (inlined core::contracts::build_check_ensures::, {closure@std::ptr::Alignment::as_nonzero::{closure#0}}>) { + } } - scope 9 (inlined NonNull::<[bool; 0]>::without_provenance) { - let _7: *const [bool; 0]; - scope 10 { + scope 13 (inlined NonNull::<[bool; 0]>::without_provenance) { + let _10: *const [bool; 0]; + scope 14 { } - scope 11 (inlined NonZero::::get) { + scope 15 (inlined NonZero::::get) { } - scope 12 (inlined std::ptr::without_provenance::<[bool; 0]>) { - scope 13 (inlined without_provenance_mut::<[bool; 0]>) { + scope 16 (inlined std::ptr::without_provenance::<[bool; 0]>) { + scope 17 (inlined without_provenance_mut::<[bool; 0]>) { } } } } scope 7 (inlined std::ptr::Alignment::of::<[bool; 0]>) { + scope 8 { + } + scope 9 (inlined core::contracts::build_check_ensures::::{closure#0}}>) { + } } } } @@ -45,29 +56,7 @@ 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 = 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(_7); - StorageDead(_6); -- _4 = Unique::<[bool; 0]> { pointer: move _5, _marker: const PhantomData::<[bool; 0]> }; -+ _4 = const Unique::<[bool; 0]> {{ pointer: NonNull::<[bool; 0]> {{ pointer: {0x1 as *const [bool; 0]} }}, _marker: PhantomData::<[bool; 0]> }}; - StorageDead(_5); -- _3 = move _4 as std::ptr::Unique<[bool]> (PointerCoercion(Unsize, Implicit)); -+ _3 = const Unique::<[bool]> {{ pointer: NonNull::<[bool]> {{ pointer: Indirect { alloc_id: ALLOC0, offset: Size(0 bytes) }: *const [bool] }}, _marker: PhantomData::<[bool]> }}; - 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(_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) }}; - StorageDead(_2); - _0 = const (); - drop(_1) -> [return: bb1, unwind: bb2]; + _6 = contract_check_ensures::<{closure@std::ptr::Alignment::of<[bool; 0]>::{closure#0}}, std::ptr::Alignment>(const ZeroSized: {closure@std::ptr::Alignment::of<[bool; 0]>::{closure#0}}, const std::ptr::Alignment::of::<[bool; 0]>::{constant#0}) -> [return: bb3, unwind continue]; } bb1: { @@ -78,11 +67,35 @@ bb2 (cleanup): { resume; } + + bb3: { + StorageLive(_7); + StorageLive(_8); + _8 = {closure@$SRC_DIR/core/src/ptr/alignment.rs:LL:COL} { 0: copy _6 }; + StorageLive(_9); + _9 = copy _6 as std::num::NonZero (Transmute); + _7 = contract_check_ensures::<{closure@std::ptr::Alignment::as_nonzero::{closure#0}}, NonZero>(move _8, move _9) -> [return: bb4, unwind continue]; + } + + bb4: { + StorageDead(_9); + StorageDead(_8); + StorageLive(_10); + _10 = copy _7 as *const [bool; 0] (Transmute); + _5 = NonNull::<[bool; 0]> { pointer: copy _10 }; + StorageDead(_10); + StorageDead(_7); + StorageDead(_6); + _4 = Unique::<[bool; 0]> { pointer: move _5, _marker: const PhantomData::<[bool; 0]> }; + StorageDead(_5); + _3 = move _4 as std::ptr::Unique<[bool]> (PointerCoercion(Unsize, Implicit)); + StorageDead(_4); + _2 = Box::<[bool]>(copy _3, const std::alloc::Global); + StorageDead(_3); + _1 = A { foo: move _2 }; + StorageDead(_2); + _0 = const (); + drop(_1) -> [return: bb1, unwind: bb2]; + } } -+ -+ ALLOC2 (size: 16, align: 8) { .. } -+ -+ ALLOC1 (size: 16, align: 8) { .. } -+ -+ ALLOC0 (size: 16, align: 8) { .. } diff --git a/tests/mir-opt/dataflow-const-prop/default_boxed_slice.rs b/tests/mir-opt/dataflow-const-prop/default_boxed_slice.rs index 087bd7a18572c..ca9f38453b5b1 100644 --- a/tests/mir-opt/dataflow-const-prop/default_boxed_slice.rs +++ b/tests/mir-opt/dataflow-const-prop/default_boxed_slice.rs @@ -20,6 +20,6 @@ fn main() { // CHECK: debug a => [[a:_.*]]; // We may check other inlined functions as well... - // CHECK: {{_.*}} = const Box::<[bool]>( + // CHECK: {{_.*}} = {{(const )?}}Box::<[bool]>( let a: A = A { foo: Box::default() }; } 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 f56af33ea603f..989d33bff3183 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,59 +6,94 @@ let _1: bool; let mut _2: *mut u8; scope 1 (inlined dangling_mut::) { + let mut _3: std::ptr::NonNull; scope 2 (inlined NonNull::::dangling) { - let mut _3: std::num::NonZero; + let _4: std::ptr::Alignment; + let mut _5: std::num::NonZero; scope 3 { - scope 5 (inlined std::ptr::Alignment::as_nonzero) { + scope 7 (inlined std::ptr::Alignment::as_nonzero) { + let mut _6: {closure@std::ptr::Alignment::as_nonzero::{closure#0}}; + let mut _7: std::num::NonZero; + scope 8 { + } + scope 9 (inlined core::contracts::build_check_ensures::, {closure@std::ptr::Alignment::as_nonzero::{closure#0}}>) { + } } - scope 6 (inlined NonNull::::without_provenance) { - scope 7 { + scope 10 (inlined NonNull::::without_provenance) { + let _8: *const u8; + scope 11 { } - scope 8 (inlined NonZero::::get) { + scope 12 (inlined NonZero::::get) { } - scope 9 (inlined std::ptr::without_provenance::) { - scope 10 (inlined without_provenance_mut::) { + scope 13 (inlined std::ptr::without_provenance::) { + scope 14 (inlined without_provenance_mut::) { } } } } scope 4 (inlined std::ptr::Alignment::of::) { + scope 5 { + } + scope 6 (inlined core::contracts::build_check_ensures::::{closure#0}}>) { + } } } - scope 11 (inlined NonNull::::as_ptr) { + scope 15 (inlined NonNull::::as_ptr) { } } - scope 12 (inlined Foo::::cmp_ptr) { - let mut _4: *const u8; - let mut _5: *mut u8; - let mut _6: *const u8; - scope 13 (inlined std::ptr::eq::) { + scope 16 (inlined Foo::::cmp_ptr) { + let mut _9: *const u8; + let mut _10: *mut u8; + let mut _11: *const u8; + scope 17 (inlined std::ptr::eq::) { } } bb0: { StorageLive(_1); StorageLive(_2); +- StorageLive(_5); ++ nop; StorageLive(_3); -- _3 = const std::ptr::Alignment::of::::{constant#0} as std::num::NonZero (Transmute); -- _2 = copy _3 as *mut u8 (Transmute); -+ _3 = const NonZero::(core::num::niche_types::NonZeroUsizeInner(1_usize)); -+ _2 = const {0x1 as *mut u8}; - StorageDead(_3); StorageLive(_4); - StorageLive(_5); -- _5 = copy _2; -- _4 = copy _2 as *const u8 (PtrToPtr); -+ _5 = const {0x1 as *mut u8}; -+ _4 = const {0x1 as *const u8}; - StorageDead(_5); + _4 = contract_check_ensures::<{closure@std::ptr::Alignment::of::{closure#0}}, std::ptr::Alignment>(const ZeroSized: {closure@std::ptr::Alignment::of::{closure#0}}, const std::ptr::Alignment::of::::{constant#0}) -> [return: bb1, unwind continue]; + } + + bb1: { StorageLive(_6); -- _6 = const Foo::::SENTINEL as *const u8 (PtrToPtr); -- _1 = Eq(copy _4, copy _6); -+ _6 = const {0x1 as *const u8}; -+ _1 = const true; + _6 = {closure@$SRC_DIR/core/src/ptr/alignment.rs:LL:COL} { 0: copy _4 }; + StorageLive(_7); + _7 = copy _4 as std::num::NonZero (Transmute); + _5 = contract_check_ensures::<{closure@std::ptr::Alignment::as_nonzero::{closure#0}}, NonZero>(move _6, move _7) -> [return: bb2, unwind continue]; + } + + bb2: { + StorageDead(_7); StorageDead(_6); +- StorageLive(_8); ++ nop; + _8 = copy _5 as *const u8 (Transmute); + _3 = NonNull:: { pointer: copy _8 }; +- StorageDead(_8); ++ nop; StorageDead(_4); + _2 = copy _5 as *mut u8 (Transmute); + StorageDead(_3); +- StorageDead(_5); ++ nop; + StorageLive(_9); + StorageLive(_10); + _10 = copy _2; +- _9 = copy _2 as *const u8 (PtrToPtr); ++ _9 = copy _8; + StorageDead(_10); + StorageLive(_11); +- _11 = const Foo::::SENTINEL as *const u8 (PtrToPtr); +- _1 = Eq(copy _9, copy _11); ++ _11 = const {0x1 as *const u8}; ++ _1 = Eq(copy _8, const {0x1 as *const u8}); + StorageDead(_11); + StorageDead(_9); StorageDead(_2); StorageDead(_1); _0 = const (); diff --git a/tests/mir-opt/pre-codegen/drop_boxed_slice.generic_in_place.PreCodegen.after.32bit.panic-abort.mir b/tests/mir-opt/pre-codegen/drop_boxed_slice.generic_in_place.PreCodegen.after.32bit.panic-abort.mir index ba6ce0ee5286f..5d1696241e1e9 100644 --- a/tests/mir-opt/pre-codegen/drop_boxed_slice.generic_in_place.PreCodegen.after.32bit.panic-abort.mir +++ b/tests/mir-opt/pre-codegen/drop_boxed_slice.generic_in_place.PreCodegen.after.32bit.panic-abort.mir @@ -8,7 +8,7 @@ fn generic_in_place(_1: *mut Box<[T]>) -> () { let _2: std::ptr::NonNull<[T]>; let mut _3: *mut [T]; let mut _4: *const [T]; - let _11: (); + let _12: (); scope 3 { let _8: std::ptr::alignment::AlignmentEnum; scope 4 { @@ -31,11 +31,16 @@ fn generic_in_place(_1: *mut Box<[T]>) -> () { scope 20 (inlined NonNull::::as_ptr) { } scope 21 (inlined std::alloc::dealloc) { - let mut _10: usize; + let mut _11: usize; scope 22 (inlined Layout::size) { } scope 23 (inlined Layout::align) { scope 24 (inlined std::ptr::Alignment::as_usize) { + let mut _10: usize; + scope 25 { + } + scope 26 (inlined core::contracts::build_check_ensures::) { + } } } } @@ -80,24 +85,30 @@ fn generic_in_place(_1: *mut Box<[T]>) -> () { StorageDead(_7); StorageDead(_6); StorageDead(_4); - switchInt(copy _5) -> [0: bb4, otherwise: bb2]; + switchInt(copy _5) -> [0: bb5, otherwise: bb2]; } bb2: { StorageLive(_9); _9 = copy _3 as *mut u8 (PtrToPtr); + StorageLive(_11); StorageLive(_10); _10 = discriminant(_8); - _11 = alloc::alloc::__rust_dealloc(move _9, move _5, move _10) -> [return: bb3, unwind unreachable]; + _11 = contract_check_ensures::<{closure@std::ptr::Alignment::as_usize::{closure#0}}, usize>(const ZeroSized: {closure@std::ptr::Alignment::as_usize::{closure#0}}, move _10) -> [return: bb3, unwind unreachable]; } bb3: { StorageDead(_10); - StorageDead(_9); - goto -> bb4; + _12 = alloc::alloc::__rust_dealloc(move _9, move _5, move _11) -> [return: bb4, unwind unreachable]; } bb4: { + StorageDead(_11); + StorageDead(_9); + goto -> bb5; + } + + bb5: { StorageDead(_2); return; } diff --git a/tests/mir-opt/pre-codegen/drop_boxed_slice.generic_in_place.PreCodegen.after.32bit.panic-unwind.mir b/tests/mir-opt/pre-codegen/drop_boxed_slice.generic_in_place.PreCodegen.after.32bit.panic-unwind.mir index ba6ce0ee5286f..9506b9950855e 100644 --- a/tests/mir-opt/pre-codegen/drop_boxed_slice.generic_in_place.PreCodegen.after.32bit.panic-unwind.mir +++ b/tests/mir-opt/pre-codegen/drop_boxed_slice.generic_in_place.PreCodegen.after.32bit.panic-unwind.mir @@ -8,7 +8,7 @@ fn generic_in_place(_1: *mut Box<[T]>) -> () { let _2: std::ptr::NonNull<[T]>; let mut _3: *mut [T]; let mut _4: *const [T]; - let _11: (); + let _12: (); scope 3 { let _8: std::ptr::alignment::AlignmentEnum; scope 4 { @@ -31,11 +31,16 @@ fn generic_in_place(_1: *mut Box<[T]>) -> () { scope 20 (inlined NonNull::::as_ptr) { } scope 21 (inlined std::alloc::dealloc) { - let mut _10: usize; + let mut _11: usize; scope 22 (inlined Layout::size) { } scope 23 (inlined Layout::align) { scope 24 (inlined std::ptr::Alignment::as_usize) { + let mut _10: usize; + scope 25 { + } + scope 26 (inlined core::contracts::build_check_ensures::) { + } } } } @@ -80,24 +85,30 @@ fn generic_in_place(_1: *mut Box<[T]>) -> () { StorageDead(_7); StorageDead(_6); StorageDead(_4); - switchInt(copy _5) -> [0: bb4, otherwise: bb2]; + switchInt(copy _5) -> [0: bb5, otherwise: bb2]; } bb2: { StorageLive(_9); _9 = copy _3 as *mut u8 (PtrToPtr); + StorageLive(_11); StorageLive(_10); _10 = discriminant(_8); - _11 = alloc::alloc::__rust_dealloc(move _9, move _5, move _10) -> [return: bb3, unwind unreachable]; + _11 = contract_check_ensures::<{closure@std::ptr::Alignment::as_usize::{closure#0}}, usize>(const ZeroSized: {closure@std::ptr::Alignment::as_usize::{closure#0}}, move _10) -> [return: bb3, unwind continue]; } bb3: { StorageDead(_10); - StorageDead(_9); - goto -> bb4; + _12 = alloc::alloc::__rust_dealloc(move _9, move _5, move _11) -> [return: bb4, unwind unreachable]; } bb4: { + StorageDead(_11); + StorageDead(_9); + goto -> bb5; + } + + bb5: { StorageDead(_2); return; } diff --git a/tests/mir-opt/pre-codegen/drop_boxed_slice.generic_in_place.PreCodegen.after.64bit.panic-abort.mir b/tests/mir-opt/pre-codegen/drop_boxed_slice.generic_in_place.PreCodegen.after.64bit.panic-abort.mir index ba6ce0ee5286f..5d1696241e1e9 100644 --- a/tests/mir-opt/pre-codegen/drop_boxed_slice.generic_in_place.PreCodegen.after.64bit.panic-abort.mir +++ b/tests/mir-opt/pre-codegen/drop_boxed_slice.generic_in_place.PreCodegen.after.64bit.panic-abort.mir @@ -8,7 +8,7 @@ fn generic_in_place(_1: *mut Box<[T]>) -> () { let _2: std::ptr::NonNull<[T]>; let mut _3: *mut [T]; let mut _4: *const [T]; - let _11: (); + let _12: (); scope 3 { let _8: std::ptr::alignment::AlignmentEnum; scope 4 { @@ -31,11 +31,16 @@ fn generic_in_place(_1: *mut Box<[T]>) -> () { scope 20 (inlined NonNull::::as_ptr) { } scope 21 (inlined std::alloc::dealloc) { - let mut _10: usize; + let mut _11: usize; scope 22 (inlined Layout::size) { } scope 23 (inlined Layout::align) { scope 24 (inlined std::ptr::Alignment::as_usize) { + let mut _10: usize; + scope 25 { + } + scope 26 (inlined core::contracts::build_check_ensures::) { + } } } } @@ -80,24 +85,30 @@ fn generic_in_place(_1: *mut Box<[T]>) -> () { StorageDead(_7); StorageDead(_6); StorageDead(_4); - switchInt(copy _5) -> [0: bb4, otherwise: bb2]; + switchInt(copy _5) -> [0: bb5, otherwise: bb2]; } bb2: { StorageLive(_9); _9 = copy _3 as *mut u8 (PtrToPtr); + StorageLive(_11); StorageLive(_10); _10 = discriminant(_8); - _11 = alloc::alloc::__rust_dealloc(move _9, move _5, move _10) -> [return: bb3, unwind unreachable]; + _11 = contract_check_ensures::<{closure@std::ptr::Alignment::as_usize::{closure#0}}, usize>(const ZeroSized: {closure@std::ptr::Alignment::as_usize::{closure#0}}, move _10) -> [return: bb3, unwind unreachable]; } bb3: { StorageDead(_10); - StorageDead(_9); - goto -> bb4; + _12 = alloc::alloc::__rust_dealloc(move _9, move _5, move _11) -> [return: bb4, unwind unreachable]; } bb4: { + StorageDead(_11); + StorageDead(_9); + goto -> bb5; + } + + bb5: { StorageDead(_2); return; } diff --git a/tests/mir-opt/pre-codegen/drop_boxed_slice.generic_in_place.PreCodegen.after.64bit.panic-unwind.mir b/tests/mir-opt/pre-codegen/drop_boxed_slice.generic_in_place.PreCodegen.after.64bit.panic-unwind.mir index ba6ce0ee5286f..9506b9950855e 100644 --- a/tests/mir-opt/pre-codegen/drop_boxed_slice.generic_in_place.PreCodegen.after.64bit.panic-unwind.mir +++ b/tests/mir-opt/pre-codegen/drop_boxed_slice.generic_in_place.PreCodegen.after.64bit.panic-unwind.mir @@ -8,7 +8,7 @@ fn generic_in_place(_1: *mut Box<[T]>) -> () { let _2: std::ptr::NonNull<[T]>; let mut _3: *mut [T]; let mut _4: *const [T]; - let _11: (); + let _12: (); scope 3 { let _8: std::ptr::alignment::AlignmentEnum; scope 4 { @@ -31,11 +31,16 @@ fn generic_in_place(_1: *mut Box<[T]>) -> () { scope 20 (inlined NonNull::::as_ptr) { } scope 21 (inlined std::alloc::dealloc) { - let mut _10: usize; + let mut _11: usize; scope 22 (inlined Layout::size) { } scope 23 (inlined Layout::align) { scope 24 (inlined std::ptr::Alignment::as_usize) { + let mut _10: usize; + scope 25 { + } + scope 26 (inlined core::contracts::build_check_ensures::) { + } } } } @@ -80,24 +85,30 @@ fn generic_in_place(_1: *mut Box<[T]>) -> () { StorageDead(_7); StorageDead(_6); StorageDead(_4); - switchInt(copy _5) -> [0: bb4, otherwise: bb2]; + switchInt(copy _5) -> [0: bb5, otherwise: bb2]; } bb2: { StorageLive(_9); _9 = copy _3 as *mut u8 (PtrToPtr); + StorageLive(_11); StorageLive(_10); _10 = discriminant(_8); - _11 = alloc::alloc::__rust_dealloc(move _9, move _5, move _10) -> [return: bb3, unwind unreachable]; + _11 = contract_check_ensures::<{closure@std::ptr::Alignment::as_usize::{closure#0}}, usize>(const ZeroSized: {closure@std::ptr::Alignment::as_usize::{closure#0}}, move _10) -> [return: bb3, unwind continue]; } bb3: { StorageDead(_10); - StorageDead(_9); - goto -> bb4; + _12 = alloc::alloc::__rust_dealloc(move _9, move _5, move _11) -> [return: bb4, unwind unreachable]; } bb4: { + StorageDead(_11); + StorageDead(_9); + goto -> bb5; + } + + bb5: { StorageDead(_2); return; } diff --git a/tests/mir-opt/pre-codegen/drop_boxed_slice.rs b/tests/mir-opt/pre-codegen/drop_boxed_slice.rs index 9ceba9444b8da..33bfe88184eed 100644 --- a/tests/mir-opt/pre-codegen/drop_boxed_slice.rs +++ b/tests/mir-opt/pre-codegen/drop_boxed_slice.rs @@ -13,6 +13,6 @@ pub unsafe fn generic_in_place(ptr: *mut Box<[T]>) { // CHECK: [[B:_.+]] = copy [[ALIGN]] as std::ptr::Alignment (Transmute); // CHECK: [[C:_.+]] = move ([[B]].0: std::ptr::alignment::AlignmentEnum); // CHECK: [[D:_.+]] = discriminant([[C]]); - // CHECK: = alloc::alloc::__rust_dealloc({{.+}}, move [[SIZE]], move [[D]]) -> + // CHECK: = alloc::alloc::__rust_dealloc({{.+}}, move [[SIZE]], move {{.+}}) -> std::ptr::drop_in_place(ptr) }