Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 4ec6b4e

Browse files
committedFeb 3, 2024
Auto merge of rust-lang#120594 - saethlin:delayed-debug-asserts, r=<try>
Toggle assert_unsafe_precondition in codegen instead of expansion r? `@ghost` rust-lang#120539 (comment)
2 parents bf3c6c5 + 6dd581b commit 4ec6b4e

File tree

31 files changed

+1008
-1205
lines changed

31 files changed

+1008
-1205
lines changed
 

‎compiler/rustc_codegen_cranelift/src/intrinsics/mod.rs‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,14 @@ fn codegen_regular_intrinsic_call<'tcx>(
438438
fx.bcx.ins().trap(TrapCode::User(0));
439439
return;
440440
}
441+
sym::debug_assertions => {
442+
let bool_layout = fx.layout_of(fx.tcx.types.bool);
443+
let val = CValue::by_val(
444+
fx.bcx.ins().iconst(types::I8, fx.tcx.sess.opts.debug_assertions as i64),
445+
bool_layout,
446+
);
447+
ret.write_cvalue(fx, val);
448+
}
441449
sym::likely | sym::unlikely => {
442450
intrinsic_args!(fx, args => (a); intrinsic);
443451

‎compiler/rustc_codegen_ssa/src/mir/intrinsic.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
8484
return;
8585
}
8686

87+
sym::debug_assertions => bx.const_bool(bx.tcx().sess.opts.debug_assertions),
8788
sym::va_start => bx.va_start(args[0].immediate()),
8889
sym::va_end => bx.va_end(args[0].immediate()),
8990
sym::size_of_val => {

‎compiler/rustc_const_eval/src/const_eval/machine.rs‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,11 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir,
536536
// (We know the value here in the machine of course, but this is the runtime of that code,
537537
// not the optimization stage.)
538538
sym::is_val_statically_known => ecx.write_scalar(Scalar::from_bool(false), dest)?,
539+
540+
sym::debug_assertions => {
541+
ecx.write_scalar(Scalar::from_bool(ecx.tcx.sess.opts.debug_assertions), dest)?
542+
}
543+
539544
_ => {
540545
throw_unsup_format!(
541546
"intrinsic `{intrinsic_name}` is not supported at compile-time"

‎compiler/rustc_hir_analysis/src/check/intrinsic.rs‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,8 @@ pub fn intrinsic_operation_unsafety(tcx: TyCtxt<'_>, intrinsic_id: DefId) -> hir
112112
| sym::forget
113113
| sym::black_box
114114
| sym::variant_count
115-
| sym::ptr_mask => hir::Unsafety::Normal,
115+
| sym::ptr_mask
116+
| sym::debug_assertions => hir::Unsafety::Normal,
116117
_ => hir::Unsafety::Unsafe,
117118
};
118119

@@ -461,6 +462,8 @@ pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>) {
461462
(0, vec![Ty::new_imm_ptr(tcx, Ty::new_unit(tcx))], tcx.types.usize)
462463
}
463464

465+
sym::debug_assertions => (0, Vec::new(), tcx.types.bool),
466+
464467
other => {
465468
tcx.dcx().emit_err(UnrecognizedIntrinsicFunction { span: it.span, name: other });
466469
return;

‎library/core/src/intrinsics.rs‎

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2569,6 +2569,12 @@ extern "rust-intrinsic" {
25692569
#[rustc_nounwind]
25702570
#[cfg(not(bootstrap))]
25712571
pub fn is_val_statically_known<T: Copy>(arg: T) -> bool;
2572+
2573+
#[rustc_const_unstable(feature = "delayed_debug_assertions", issue = "none")]
2574+
#[rustc_safe_intrinsic]
2575+
#[rustc_nounwind]
2576+
#[cfg(not(bootstrap))]
2577+
pub(crate) fn debug_assertions() -> bool;
25722578
}
25732579

25742580
// FIXME: Seems using `unstable` here completely ignores `rustc_allow_const_fn_unstable`
@@ -2604,10 +2610,18 @@ pub const unsafe fn is_val_statically_known<T: Copy>(_arg: T) -> bool {
26042610
///
26052611
/// So in a sense it is UB if this macro is useful, but we expect callers of `unsafe fn` to make
26062612
/// the occasional mistake, and this check should help them figure things out.
2607-
#[allow_internal_unstable(const_eval_select)] // permit this to be called in stably-const fn
2613+
#[allow_internal_unstable(const_eval_select, delayed_debug_assertions)] // permit this to be called in stably-const fn
26082614
macro_rules! assert_unsafe_precondition {
26092615
($name:expr, $([$($tt:tt)*])?($($i:ident:$ty:ty),*$(,)?) => $e:expr $(,)?) => {
2610-
if cfg!(debug_assertions) {
2616+
{
2617+
#[cfg(bootstrap)]
2618+
let should_check = cfg!(debug_assertions);
2619+
2620+
// Turn assertions off in Miri, but otherwise check in codegen
2621+
#[cfg(not(bootstrap))]
2622+
let should_check = !cfg!(miri) && ::core::intrinsics::debug_assertions();
2623+
2624+
if should_check {
26112625
// allow non_snake_case to allow capturing const generics
26122626
#[allow(non_snake_case)]
26132627
#[inline(always)]
@@ -2625,6 +2639,7 @@ macro_rules! assert_unsafe_precondition {
26252639

26262640
::core::intrinsics::const_eval_select(($($i,)*), comptime, runtime);
26272641
}
2642+
}
26282643
};
26292644
}
26302645
pub(crate) use assert_unsafe_precondition;

‎library/core/src/ptr/mod.rs‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1208,10 +1208,12 @@ pub const unsafe fn read<T>(src: *const T) -> T {
12081208

12091209
// SAFETY: the caller must guarantee that `src` is valid for reads.
12101210
unsafe {
1211+
/*
12111212
assert_unsafe_precondition!(
12121213
"ptr::read requires that the pointer argument is aligned and non-null",
12131214
[T](src: *const T) => is_aligned_and_not_null(src)
12141215
);
1216+
*/
12151217
crate::intrinsics::read_via_copy(src)
12161218
}
12171219
}
@@ -1408,10 +1410,12 @@ pub const unsafe fn write<T>(dst: *mut T, src: T) {
14081410
// `dst` cannot overlap `src` because the caller has mutable access
14091411
// to `dst` while `src` is owned by this function.
14101412
unsafe {
1413+
/*
14111414
assert_unsafe_precondition!(
14121415
"ptr::write requires that the pointer argument is aligned and non-null",
14131416
[T](dst: *mut T) => is_aligned_and_not_null(dst)
14141417
);
1418+
*/
14151419
intrinsics::write_via_move(dst, src)
14161420
}
14171421
}

‎tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.DataflowConstProp.32bit.panic-abort.diff‎

Lines changed: 58 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,28 @@
2424
debug ptr => _6;
2525
scope 11 (inlined NonNull::<[bool; 0]>::new_unchecked) {
2626
debug ptr => _6;
27-
let mut _8: *const [bool; 0];
28-
let mut _9: *mut [bool; 0];
27+
let mut _9: *const [bool; 0];
2928
scope 12 {
30-
scope 13 (inlined NonNull::<T>::new_unchecked::runtime::<[bool; 0]>) {
31-
debug ptr => _9;
32-
scope 14 (inlined std::ptr::mut_ptr::<impl *mut [bool; 0]>::is_null) {
33-
debug self => _9;
34-
let mut _10: *mut u8;
35-
scope 15 {
36-
scope 16 (inlined std::ptr::mut_ptr::<impl *mut T>::is_null::runtime_impl) {
37-
debug ptr => _10;
38-
scope 17 (inlined std::ptr::mut_ptr::<impl *mut u8>::addr) {
39-
debug self => _10;
40-
scope 18 {
41-
scope 19 (inlined std::ptr::mut_ptr::<impl *mut u8>::cast::<()>) {
42-
debug self => _10;
29+
let _8: bool;
30+
scope 13 {
31+
debug should_check => _8;
32+
scope 14 (inlined NonNull::<T>::new_unchecked::runtime::<[bool; 0]>) {
33+
debug ptr => _6;
34+
let _10: !;
35+
scope 15 (inlined std::ptr::mut_ptr::<impl *mut [bool; 0]>::is_null) {
36+
debug self => _6;
37+
let mut _11: *mut u8;
38+
scope 16 {
39+
scope 17 (inlined std::ptr::mut_ptr::<impl *mut T>::is_null::runtime_impl) {
40+
debug ptr => _11;
41+
let mut _12: usize;
42+
scope 18 (inlined std::ptr::mut_ptr::<impl *mut u8>::addr) {
43+
debug self => _11;
44+
let mut _13: *mut ();
45+
scope 19 {
46+
scope 20 (inlined std::ptr::mut_ptr::<impl *mut u8>::cast::<()>) {
47+
debug self => _11;
48+
}
4349
}
4450
}
4551
}
@@ -66,6 +72,7 @@
6672
StorageLive(_1);
6773
StorageLive(_2);
6874
StorageLive(_3);
75+
StorageLive(_10);
6976
StorageLive(_4);
7077
StorageLive(_5);
7178
StorageLive(_6);
@@ -75,10 +82,33 @@
7582
StorageDead(_7);
7683
StorageLive(_8);
7784
StorageLive(_9);
78-
StorageLive(_10);
79-
_8 = const {0x1 as *mut [bool; 0]} as *const [bool; 0] (PointerCoercion(MutToConstPointer));
80-
_5 = NonNull::<[bool; 0]> { pointer: _8 };
81-
StorageDead(_10);
85+
_8 = intrinsics::debug_assertions() -> [return: bb2, unwind unreachable];
86+
}
87+
88+
bb1: {
89+
StorageDead(_1);
90+
return;
91+
}
92+
93+
bb2: {
94+
switchInt(_8) -> [0: bb4, otherwise: bb3];
95+
}
96+
97+
bb3: {
98+
StorageLive(_11);
99+
_11 = const {0x1 as *mut [bool; 0]} as *mut u8 (PtrToPtr);
100+
StorageLive(_12);
101+
StorageLive(_13);
102+
_13 = _11 as *mut () (PtrToPtr);
103+
_12 = move _13 as usize (Transmute);
104+
StorageDead(_13);
105+
StorageDead(_11);
106+
switchInt(move _12) -> [0: bb5, otherwise: bb6];
107+
}
108+
109+
bb4: {
110+
_9 = const {0x1 as *mut [bool; 0]} as *const [bool; 0] (PointerCoercion(MutToConstPointer));
111+
_5 = NonNull::<[bool; 0]> { pointer: _9 };
82112
StorageDead(_9);
83113
StorageDead(_8);
84114
StorageDead(_6);
@@ -87,16 +117,22 @@
87117
_3 = move _4 as std::ptr::Unique<[bool]> (PointerCoercion(Unsize));
88118
StorageDead(_4);
89119
_2 = Box::<[bool]>(_3, const std::alloc::Global);
120+
StorageDead(_10);
90121
StorageDead(_3);
91122
_1 = A { foo: move _2 };
92123
StorageDead(_2);
93124
_0 = const ();
94125
drop(_1) -> [return: bb1, unwind unreachable];
95126
}
96127

97-
bb1: {
98-
StorageDead(_1);
99-
return;
128+
bb5: {
129+
StorageDead(_12);
130+
_10 = core::panicking::panic_nounwind(const "unsafe precondition(s) violated: NonNull::new_unchecked requires that the pointer is non-null") -> unwind unreachable;
131+
}
132+
133+
bb6: {
134+
StorageDead(_12);
135+
goto -> bb4;
100136
}
101137
}
102138

‎tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.DataflowConstProp.32bit.panic-unwind.diff‎

Lines changed: 60 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,28 @@
2424
debug ptr => _6;
2525
scope 11 (inlined NonNull::<[bool; 0]>::new_unchecked) {
2626
debug ptr => _6;
27-
let mut _8: *const [bool; 0];
28-
let mut _9: *mut [bool; 0];
27+
let mut _9: *const [bool; 0];
2928
scope 12 {
30-
scope 13 (inlined NonNull::<T>::new_unchecked::runtime::<[bool; 0]>) {
31-
debug ptr => _9;
32-
scope 14 (inlined std::ptr::mut_ptr::<impl *mut [bool; 0]>::is_null) {
33-
debug self => _9;
34-
let mut _10: *mut u8;
35-
scope 15 {
36-
scope 16 (inlined std::ptr::mut_ptr::<impl *mut T>::is_null::runtime_impl) {
37-
debug ptr => _10;
38-
scope 17 (inlined std::ptr::mut_ptr::<impl *mut u8>::addr) {
39-
debug self => _10;
40-
scope 18 {
41-
scope 19 (inlined std::ptr::mut_ptr::<impl *mut u8>::cast::<()>) {
42-
debug self => _10;
29+
let _8: bool;
30+
scope 13 {
31+
debug should_check => _8;
32+
scope 14 (inlined NonNull::<T>::new_unchecked::runtime::<[bool; 0]>) {
33+
debug ptr => _6;
34+
let _10: !;
35+
scope 15 (inlined std::ptr::mut_ptr::<impl *mut [bool; 0]>::is_null) {
36+
debug self => _6;
37+
let mut _11: *mut u8;
38+
scope 16 {
39+
scope 17 (inlined std::ptr::mut_ptr::<impl *mut T>::is_null::runtime_impl) {
40+
debug ptr => _11;
41+
let mut _12: usize;
42+
scope 18 (inlined std::ptr::mut_ptr::<impl *mut u8>::addr) {
43+
debug self => _11;
44+
let mut _13: *mut ();
45+
scope 19 {
46+
scope 20 (inlined std::ptr::mut_ptr::<impl *mut u8>::cast::<()>) {
47+
debug self => _11;
48+
}
4349
}
4450
}
4551
}
@@ -66,6 +72,7 @@
6672
StorageLive(_1);
6773
StorageLive(_2);
6874
StorageLive(_3);
75+
StorageLive(_10);
6976
StorageLive(_4);
7077
StorageLive(_5);
7178
StorageLive(_6);
@@ -75,10 +82,37 @@
7582
StorageDead(_7);
7683
StorageLive(_8);
7784
StorageLive(_9);
78-
StorageLive(_10);
79-
_8 = const {0x1 as *mut [bool; 0]} as *const [bool; 0] (PointerCoercion(MutToConstPointer));
80-
_5 = NonNull::<[bool; 0]> { pointer: _8 };
81-
StorageDead(_10);
85+
_8 = intrinsics::debug_assertions() -> [return: bb3, unwind unreachable];
86+
}
87+
88+
bb1: {
89+
StorageDead(_1);
90+
return;
91+
}
92+
93+
bb2 (cleanup): {
94+
resume;
95+
}
96+
97+
bb3: {
98+
switchInt(_8) -> [0: bb5, otherwise: bb4];
99+
}
100+
101+
bb4: {
102+
StorageLive(_11);
103+
_11 = const {0x1 as *mut [bool; 0]} as *mut u8 (PtrToPtr);
104+
StorageLive(_12);
105+
StorageLive(_13);
106+
_13 = _11 as *mut () (PtrToPtr);
107+
_12 = move _13 as usize (Transmute);
108+
StorageDead(_13);
109+
StorageDead(_11);
110+
switchInt(move _12) -> [0: bb6, otherwise: bb7];
111+
}
112+
113+
bb5: {
114+
_9 = const {0x1 as *mut [bool; 0]} as *const [bool; 0] (PointerCoercion(MutToConstPointer));
115+
_5 = NonNull::<[bool; 0]> { pointer: _9 };
82116
StorageDead(_9);
83117
StorageDead(_8);
84118
StorageDead(_6);
@@ -87,20 +121,22 @@
87121
_3 = move _4 as std::ptr::Unique<[bool]> (PointerCoercion(Unsize));
88122
StorageDead(_4);
89123
_2 = Box::<[bool]>(_3, const std::alloc::Global);
124+
StorageDead(_10);
90125
StorageDead(_3);
91126
_1 = A { foo: move _2 };
92127
StorageDead(_2);
93128
_0 = const ();
94129
drop(_1) -> [return: bb1, unwind: bb2];
95130
}
96131

97-
bb1: {
98-
StorageDead(_1);
99-
return;
132+
bb6: {
133+
StorageDead(_12);
134+
_10 = core::panicking::panic_nounwind(const "unsafe precondition(s) violated: NonNull::new_unchecked requires that the pointer is non-null") -> unwind unreachable;
100135
}
101136

102-
bb2 (cleanup): {
103-
resume;
137+
bb7: {
138+
StorageDead(_12);
139+
goto -> bb5;
104140
}
105141
}
106142

‎tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.DataflowConstProp.64bit.panic-abort.diff‎

Lines changed: 58 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,28 @@
2424
debug ptr => _6;
2525
scope 11 (inlined NonNull::<[bool; 0]>::new_unchecked) {
2626
debug ptr => _6;
27-
let mut _8: *const [bool; 0];
28-
let mut _9: *mut [bool; 0];
27+
let mut _9: *const [bool; 0];
2928
scope 12 {
30-
scope 13 (inlined NonNull::<T>::new_unchecked::runtime::<[bool; 0]>) {
31-
debug ptr => _9;
32-
scope 14 (inlined std::ptr::mut_ptr::<impl *mut [bool; 0]>::is_null) {
33-
debug self => _9;
34-
let mut _10: *mut u8;
35-
scope 15 {
36-
scope 16 (inlined std::ptr::mut_ptr::<impl *mut T>::is_null::runtime_impl) {
37-
debug ptr => _10;
38-
scope 17 (inlined std::ptr::mut_ptr::<impl *mut u8>::addr) {
39-
debug self => _10;
40-
scope 18 {
41-
scope 19 (inlined std::ptr::mut_ptr::<impl *mut u8>::cast::<()>) {
42-
debug self => _10;
29+
let _8: bool;
30+
scope 13 {
31+
debug should_check => _8;
32+
scope 14 (inlined NonNull::<T>::new_unchecked::runtime::<[bool; 0]>) {
33+
debug ptr => _6;
34+
let _10: !;
35+
scope 15 (inlined std::ptr::mut_ptr::<impl *mut [bool; 0]>::is_null) {
36+
debug self => _6;
37+
let mut _11: *mut u8;
38+
scope 16 {
39+
scope 17 (inlined std::ptr::mut_ptr::<impl *mut T>::is_null::runtime_impl) {
40+
debug ptr => _11;
41+
let mut _12: usize;
42+
scope 18 (inlined std::ptr::mut_ptr::<impl *mut u8>::addr) {
43+
debug self => _11;
44+
let mut _13: *mut ();
45+
scope 19 {
46+
scope 20 (inlined std::ptr::mut_ptr::<impl *mut u8>::cast::<()>) {
47+
debug self => _11;
48+
}
4349
}
4450
}
4551
}
@@ -66,6 +72,7 @@
6672
StorageLive(_1);
6773
StorageLive(_2);
6874
StorageLive(_3);
75+
StorageLive(_10);
6976
StorageLive(_4);
7077
StorageLive(_5);
7178
StorageLive(_6);
@@ -75,10 +82,33 @@
7582
StorageDead(_7);
7683
StorageLive(_8);
7784
StorageLive(_9);
78-
StorageLive(_10);
79-
_8 = const {0x1 as *mut [bool; 0]} as *const [bool; 0] (PointerCoercion(MutToConstPointer));
80-
_5 = NonNull::<[bool; 0]> { pointer: _8 };
81-
StorageDead(_10);
85+
_8 = intrinsics::debug_assertions() -> [return: bb2, unwind unreachable];
86+
}
87+
88+
bb1: {
89+
StorageDead(_1);
90+
return;
91+
}
92+
93+
bb2: {
94+
switchInt(_8) -> [0: bb4, otherwise: bb3];
95+
}
96+
97+
bb3: {
98+
StorageLive(_11);
99+
_11 = const {0x1 as *mut [bool; 0]} as *mut u8 (PtrToPtr);
100+
StorageLive(_12);
101+
StorageLive(_13);
102+
_13 = _11 as *mut () (PtrToPtr);
103+
_12 = move _13 as usize (Transmute);
104+
StorageDead(_13);
105+
StorageDead(_11);
106+
switchInt(move _12) -> [0: bb5, otherwise: bb6];
107+
}
108+
109+
bb4: {
110+
_9 = const {0x1 as *mut [bool; 0]} as *const [bool; 0] (PointerCoercion(MutToConstPointer));
111+
_5 = NonNull::<[bool; 0]> { pointer: _9 };
82112
StorageDead(_9);
83113
StorageDead(_8);
84114
StorageDead(_6);
@@ -87,16 +117,22 @@
87117
_3 = move _4 as std::ptr::Unique<[bool]> (PointerCoercion(Unsize));
88118
StorageDead(_4);
89119
_2 = Box::<[bool]>(_3, const std::alloc::Global);
120+
StorageDead(_10);
90121
StorageDead(_3);
91122
_1 = A { foo: move _2 };
92123
StorageDead(_2);
93124
_0 = const ();
94125
drop(_1) -> [return: bb1, unwind unreachable];
95126
}
96127

97-
bb1: {
98-
StorageDead(_1);
99-
return;
128+
bb5: {
129+
StorageDead(_12);
130+
_10 = core::panicking::panic_nounwind(const "unsafe precondition(s) violated: NonNull::new_unchecked requires that the pointer is non-null") -> unwind unreachable;
131+
}
132+
133+
bb6: {
134+
StorageDead(_12);
135+
goto -> bb4;
100136
}
101137
}
102138

‎tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.DataflowConstProp.64bit.panic-unwind.diff‎

Lines changed: 60 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,28 @@
2424
debug ptr => _6;
2525
scope 11 (inlined NonNull::<[bool; 0]>::new_unchecked) {
2626
debug ptr => _6;
27-
let mut _8: *const [bool; 0];
28-
let mut _9: *mut [bool; 0];
27+
let mut _9: *const [bool; 0];
2928
scope 12 {
30-
scope 13 (inlined NonNull::<T>::new_unchecked::runtime::<[bool; 0]>) {
31-
debug ptr => _9;
32-
scope 14 (inlined std::ptr::mut_ptr::<impl *mut [bool; 0]>::is_null) {
33-
debug self => _9;
34-
let mut _10: *mut u8;
35-
scope 15 {
36-
scope 16 (inlined std::ptr::mut_ptr::<impl *mut T>::is_null::runtime_impl) {
37-
debug ptr => _10;
38-
scope 17 (inlined std::ptr::mut_ptr::<impl *mut u8>::addr) {
39-
debug self => _10;
40-
scope 18 {
41-
scope 19 (inlined std::ptr::mut_ptr::<impl *mut u8>::cast::<()>) {
42-
debug self => _10;
29+
let _8: bool;
30+
scope 13 {
31+
debug should_check => _8;
32+
scope 14 (inlined NonNull::<T>::new_unchecked::runtime::<[bool; 0]>) {
33+
debug ptr => _6;
34+
let _10: !;
35+
scope 15 (inlined std::ptr::mut_ptr::<impl *mut [bool; 0]>::is_null) {
36+
debug self => _6;
37+
let mut _11: *mut u8;
38+
scope 16 {
39+
scope 17 (inlined std::ptr::mut_ptr::<impl *mut T>::is_null::runtime_impl) {
40+
debug ptr => _11;
41+
let mut _12: usize;
42+
scope 18 (inlined std::ptr::mut_ptr::<impl *mut u8>::addr) {
43+
debug self => _11;
44+
let mut _13: *mut ();
45+
scope 19 {
46+
scope 20 (inlined std::ptr::mut_ptr::<impl *mut u8>::cast::<()>) {
47+
debug self => _11;
48+
}
4349
}
4450
}
4551
}
@@ -66,6 +72,7 @@
6672
StorageLive(_1);
6773
StorageLive(_2);
6874
StorageLive(_3);
75+
StorageLive(_10);
6976
StorageLive(_4);
7077
StorageLive(_5);
7178
StorageLive(_6);
@@ -75,10 +82,37 @@
7582
StorageDead(_7);
7683
StorageLive(_8);
7784
StorageLive(_9);
78-
StorageLive(_10);
79-
_8 = const {0x1 as *mut [bool; 0]} as *const [bool; 0] (PointerCoercion(MutToConstPointer));
80-
_5 = NonNull::<[bool; 0]> { pointer: _8 };
81-
StorageDead(_10);
85+
_8 = intrinsics::debug_assertions() -> [return: bb3, unwind unreachable];
86+
}
87+
88+
bb1: {
89+
StorageDead(_1);
90+
return;
91+
}
92+
93+
bb2 (cleanup): {
94+
resume;
95+
}
96+
97+
bb3: {
98+
switchInt(_8) -> [0: bb5, otherwise: bb4];
99+
}
100+
101+
bb4: {
102+
StorageLive(_11);
103+
_11 = const {0x1 as *mut [bool; 0]} as *mut u8 (PtrToPtr);
104+
StorageLive(_12);
105+
StorageLive(_13);
106+
_13 = _11 as *mut () (PtrToPtr);
107+
_12 = move _13 as usize (Transmute);
108+
StorageDead(_13);
109+
StorageDead(_11);
110+
switchInt(move _12) -> [0: bb6, otherwise: bb7];
111+
}
112+
113+
bb5: {
114+
_9 = const {0x1 as *mut [bool; 0]} as *const [bool; 0] (PointerCoercion(MutToConstPointer));
115+
_5 = NonNull::<[bool; 0]> { pointer: _9 };
82116
StorageDead(_9);
83117
StorageDead(_8);
84118
StorageDead(_6);
@@ -87,20 +121,22 @@
87121
_3 = move _4 as std::ptr::Unique<[bool]> (PointerCoercion(Unsize));
88122
StorageDead(_4);
89123
_2 = Box::<[bool]>(_3, const std::alloc::Global);
124+
StorageDead(_10);
90125
StorageDead(_3);
91126
_1 = A { foo: move _2 };
92127
StorageDead(_2);
93128
_0 = const ();
94129
drop(_1) -> [return: bb1, unwind: bb2];
95130
}
96131

97-
bb1: {
98-
StorageDead(_1);
99-
return;
132+
bb6: {
133+
StorageDead(_12);
134+
_10 = core::panicking::panic_nounwind(const "unsafe precondition(s) violated: NonNull::new_unchecked requires that the pointer is non-null") -> unwind unreachable;
100135
}
101136

102-
bb2 (cleanup): {
103-
resume;
137+
bb7: {
138+
StorageDead(_12);
139+
goto -> bb5;
104140
}
105141
}
106142

‎tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.GVN.32bit.panic-abort.diff‎

Lines changed: 60 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,28 @@
2424
debug ptr => _6;
2525
scope 11 (inlined NonNull::<[bool; 0]>::new_unchecked) {
2626
debug ptr => _6;
27-
let mut _8: *const [bool; 0];
28-
let mut _9: *mut [bool; 0];
27+
let mut _9: *const [bool; 0];
2928
scope 12 {
30-
scope 13 (inlined NonNull::<T>::new_unchecked::runtime::<[bool; 0]>) {
31-
debug ptr => _9;
32-
scope 14 (inlined std::ptr::mut_ptr::<impl *mut [bool; 0]>::is_null) {
33-
debug self => _9;
34-
let mut _10: *mut u8;
35-
scope 15 {
36-
scope 16 (inlined std::ptr::mut_ptr::<impl *mut T>::is_null::runtime_impl) {
37-
debug ptr => _10;
38-
scope 17 (inlined std::ptr::mut_ptr::<impl *mut u8>::addr) {
39-
debug self => _10;
40-
scope 18 {
41-
scope 19 (inlined std::ptr::mut_ptr::<impl *mut u8>::cast::<()>) {
42-
debug self => _10;
29+
let _8: bool;
30+
scope 13 {
31+
debug should_check => _8;
32+
scope 14 (inlined NonNull::<T>::new_unchecked::runtime::<[bool; 0]>) {
33+
debug ptr => _6;
34+
let _10: !;
35+
scope 15 (inlined std::ptr::mut_ptr::<impl *mut [bool; 0]>::is_null) {
36+
debug self => _6;
37+
let mut _11: *mut u8;
38+
scope 16 {
39+
scope 17 (inlined std::ptr::mut_ptr::<impl *mut T>::is_null::runtime_impl) {
40+
debug ptr => _11;
41+
let mut _12: usize;
42+
scope 18 (inlined std::ptr::mut_ptr::<impl *mut u8>::addr) {
43+
debug self => _11;
44+
let mut _13: *mut ();
45+
scope 19 {
46+
scope 20 (inlined std::ptr::mut_ptr::<impl *mut u8>::cast::<()>) {
47+
debug self => _11;
48+
}
4349
}
4450
}
4551
}
@@ -66,6 +72,7 @@
6672
StorageLive(_1);
6773
StorageLive(_2);
6874
StorageLive(_3);
75+
StorageLive(_10);
6976
StorageLive(_4);
7077
StorageLive(_5);
7178
StorageLive(_6);
@@ -77,11 +84,35 @@
7784
StorageDead(_7);
7885
StorageLive(_8);
7986
StorageLive(_9);
80-
StorageLive(_10);
81-
- _8 = _6 as *const [bool; 0] (PointerCoercion(MutToConstPointer));
82-
+ _8 = const {0x1 as *mut [bool; 0]} as *const [bool; 0] (PointerCoercion(MutToConstPointer));
83-
_5 = NonNull::<[bool; 0]> { pointer: _8 };
84-
StorageDead(_10);
87+
_8 = intrinsics::debug_assertions() -> [return: bb2, unwind unreachable];
88+
}
89+
90+
bb1: {
91+
StorageDead(_1);
92+
return;
93+
}
94+
95+
bb2: {
96+
switchInt(_8) -> [0: bb4, otherwise: bb3];
97+
}
98+
99+
bb3: {
100+
StorageLive(_11);
101+
- _11 = _6 as *mut u8 (PtrToPtr);
102+
+ _11 = const {0x1 as *mut [bool; 0]} as *mut u8 (PtrToPtr);
103+
StorageLive(_12);
104+
StorageLive(_13);
105+
_13 = _11 as *mut () (PtrToPtr);
106+
_12 = move _13 as usize (Transmute);
107+
StorageDead(_13);
108+
StorageDead(_11);
109+
switchInt(move _12) -> [0: bb5, otherwise: bb6];
110+
}
111+
112+
bb4: {
113+
- _9 = _6 as *const [bool; 0] (PointerCoercion(MutToConstPointer));
114+
+ _9 = const {0x1 as *mut [bool; 0]} as *const [bool; 0] (PointerCoercion(MutToConstPointer));
115+
_5 = NonNull::<[bool; 0]> { pointer: _9 };
85116
StorageDead(_9);
86117
StorageDead(_8);
87118
StorageDead(_6);
@@ -90,16 +121,22 @@
90121
_3 = move _4 as std::ptr::Unique<[bool]> (PointerCoercion(Unsize));
91122
StorageDead(_4);
92123
_2 = Box::<[bool]>(_3, const std::alloc::Global);
124+
StorageDead(_10);
93125
StorageDead(_3);
94126
_1 = A { foo: move _2 };
95127
StorageDead(_2);
96128
_0 = const ();
97129
drop(_1) -> [return: bb1, unwind unreachable];
98130
}
99131

100-
bb1: {
101-
StorageDead(_1);
102-
return;
132+
bb5: {
133+
StorageDead(_12);
134+
_10 = core::panicking::panic_nounwind(const "unsafe precondition(s) violated: NonNull::new_unchecked requires that the pointer is non-null") -> unwind unreachable;
135+
}
136+
137+
bb6: {
138+
StorageDead(_12);
139+
goto -> bb4;
103140
}
104141
}
105142

‎tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.GVN.32bit.panic-unwind.diff‎

Lines changed: 62 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,28 @@
2424
debug ptr => _6;
2525
scope 11 (inlined NonNull::<[bool; 0]>::new_unchecked) {
2626
debug ptr => _6;
27-
let mut _8: *const [bool; 0];
28-
let mut _9: *mut [bool; 0];
27+
let mut _9: *const [bool; 0];
2928
scope 12 {
30-
scope 13 (inlined NonNull::<T>::new_unchecked::runtime::<[bool; 0]>) {
31-
debug ptr => _9;
32-
scope 14 (inlined std::ptr::mut_ptr::<impl *mut [bool; 0]>::is_null) {
33-
debug self => _9;
34-
let mut _10: *mut u8;
35-
scope 15 {
36-
scope 16 (inlined std::ptr::mut_ptr::<impl *mut T>::is_null::runtime_impl) {
37-
debug ptr => _10;
38-
scope 17 (inlined std::ptr::mut_ptr::<impl *mut u8>::addr) {
39-
debug self => _10;
40-
scope 18 {
41-
scope 19 (inlined std::ptr::mut_ptr::<impl *mut u8>::cast::<()>) {
42-
debug self => _10;
29+
let _8: bool;
30+
scope 13 {
31+
debug should_check => _8;
32+
scope 14 (inlined NonNull::<T>::new_unchecked::runtime::<[bool; 0]>) {
33+
debug ptr => _6;
34+
let _10: !;
35+
scope 15 (inlined std::ptr::mut_ptr::<impl *mut [bool; 0]>::is_null) {
36+
debug self => _6;
37+
let mut _11: *mut u8;
38+
scope 16 {
39+
scope 17 (inlined std::ptr::mut_ptr::<impl *mut T>::is_null::runtime_impl) {
40+
debug ptr => _11;
41+
let mut _12: usize;
42+
scope 18 (inlined std::ptr::mut_ptr::<impl *mut u8>::addr) {
43+
debug self => _11;
44+
let mut _13: *mut ();
45+
scope 19 {
46+
scope 20 (inlined std::ptr::mut_ptr::<impl *mut u8>::cast::<()>) {
47+
debug self => _11;
48+
}
4349
}
4450
}
4551
}
@@ -66,6 +72,7 @@
6672
StorageLive(_1);
6773
StorageLive(_2);
6874
StorageLive(_3);
75+
StorageLive(_10);
6976
StorageLive(_4);
7077
StorageLive(_5);
7178
StorageLive(_6);
@@ -77,11 +84,39 @@
7784
StorageDead(_7);
7885
StorageLive(_8);
7986
StorageLive(_9);
80-
StorageLive(_10);
81-
- _8 = _6 as *const [bool; 0] (PointerCoercion(MutToConstPointer));
82-
+ _8 = const {0x1 as *mut [bool; 0]} as *const [bool; 0] (PointerCoercion(MutToConstPointer));
83-
_5 = NonNull::<[bool; 0]> { pointer: _8 };
84-
StorageDead(_10);
87+
_8 = intrinsics::debug_assertions() -> [return: bb3, unwind unreachable];
88+
}
89+
90+
bb1: {
91+
StorageDead(_1);
92+
return;
93+
}
94+
95+
bb2 (cleanup): {
96+
resume;
97+
}
98+
99+
bb3: {
100+
switchInt(_8) -> [0: bb5, otherwise: bb4];
101+
}
102+
103+
bb4: {
104+
StorageLive(_11);
105+
- _11 = _6 as *mut u8 (PtrToPtr);
106+
+ _11 = const {0x1 as *mut [bool; 0]} as *mut u8 (PtrToPtr);
107+
StorageLive(_12);
108+
StorageLive(_13);
109+
_13 = _11 as *mut () (PtrToPtr);
110+
_12 = move _13 as usize (Transmute);
111+
StorageDead(_13);
112+
StorageDead(_11);
113+
switchInt(move _12) -> [0: bb6, otherwise: bb7];
114+
}
115+
116+
bb5: {
117+
- _9 = _6 as *const [bool; 0] (PointerCoercion(MutToConstPointer));
118+
+ _9 = const {0x1 as *mut [bool; 0]} as *const [bool; 0] (PointerCoercion(MutToConstPointer));
119+
_5 = NonNull::<[bool; 0]> { pointer: _9 };
85120
StorageDead(_9);
86121
StorageDead(_8);
87122
StorageDead(_6);
@@ -90,20 +125,22 @@
90125
_3 = move _4 as std::ptr::Unique<[bool]> (PointerCoercion(Unsize));
91126
StorageDead(_4);
92127
_2 = Box::<[bool]>(_3, const std::alloc::Global);
128+
StorageDead(_10);
93129
StorageDead(_3);
94130
_1 = A { foo: move _2 };
95131
StorageDead(_2);
96132
_0 = const ();
97133
drop(_1) -> [return: bb1, unwind: bb2];
98134
}
99135

100-
bb1: {
101-
StorageDead(_1);
102-
return;
136+
bb6: {
137+
StorageDead(_12);
138+
_10 = core::panicking::panic_nounwind(const "unsafe precondition(s) violated: NonNull::new_unchecked requires that the pointer is non-null") -> unwind unreachable;
103139
}
104140

105-
bb2 (cleanup): {
106-
resume;
141+
bb7: {
142+
StorageDead(_12);
143+
goto -> bb5;
107144
}
108145
}
109146

‎tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.GVN.64bit.panic-abort.diff‎

Lines changed: 60 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,28 @@
2424
debug ptr => _6;
2525
scope 11 (inlined NonNull::<[bool; 0]>::new_unchecked) {
2626
debug ptr => _6;
27-
let mut _8: *const [bool; 0];
28-
let mut _9: *mut [bool; 0];
27+
let mut _9: *const [bool; 0];
2928
scope 12 {
30-
scope 13 (inlined NonNull::<T>::new_unchecked::runtime::<[bool; 0]>) {
31-
debug ptr => _9;
32-
scope 14 (inlined std::ptr::mut_ptr::<impl *mut [bool; 0]>::is_null) {
33-
debug self => _9;
34-
let mut _10: *mut u8;
35-
scope 15 {
36-
scope 16 (inlined std::ptr::mut_ptr::<impl *mut T>::is_null::runtime_impl) {
37-
debug ptr => _10;
38-
scope 17 (inlined std::ptr::mut_ptr::<impl *mut u8>::addr) {
39-
debug self => _10;
40-
scope 18 {
41-
scope 19 (inlined std::ptr::mut_ptr::<impl *mut u8>::cast::<()>) {
42-
debug self => _10;
29+
let _8: bool;
30+
scope 13 {
31+
debug should_check => _8;
32+
scope 14 (inlined NonNull::<T>::new_unchecked::runtime::<[bool; 0]>) {
33+
debug ptr => _6;
34+
let _10: !;
35+
scope 15 (inlined std::ptr::mut_ptr::<impl *mut [bool; 0]>::is_null) {
36+
debug self => _6;
37+
let mut _11: *mut u8;
38+
scope 16 {
39+
scope 17 (inlined std::ptr::mut_ptr::<impl *mut T>::is_null::runtime_impl) {
40+
debug ptr => _11;
41+
let mut _12: usize;
42+
scope 18 (inlined std::ptr::mut_ptr::<impl *mut u8>::addr) {
43+
debug self => _11;
44+
let mut _13: *mut ();
45+
scope 19 {
46+
scope 20 (inlined std::ptr::mut_ptr::<impl *mut u8>::cast::<()>) {
47+
debug self => _11;
48+
}
4349
}
4450
}
4551
}
@@ -66,6 +72,7 @@
6672
StorageLive(_1);
6773
StorageLive(_2);
6874
StorageLive(_3);
75+
StorageLive(_10);
6976
StorageLive(_4);
7077
StorageLive(_5);
7178
StorageLive(_6);
@@ -77,11 +84,35 @@
7784
StorageDead(_7);
7885
StorageLive(_8);
7986
StorageLive(_9);
80-
StorageLive(_10);
81-
- _8 = _6 as *const [bool; 0] (PointerCoercion(MutToConstPointer));
82-
+ _8 = const {0x1 as *mut [bool; 0]} as *const [bool; 0] (PointerCoercion(MutToConstPointer));
83-
_5 = NonNull::<[bool; 0]> { pointer: _8 };
84-
StorageDead(_10);
87+
_8 = intrinsics::debug_assertions() -> [return: bb2, unwind unreachable];
88+
}
89+
90+
bb1: {
91+
StorageDead(_1);
92+
return;
93+
}
94+
95+
bb2: {
96+
switchInt(_8) -> [0: bb4, otherwise: bb3];
97+
}
98+
99+
bb3: {
100+
StorageLive(_11);
101+
- _11 = _6 as *mut u8 (PtrToPtr);
102+
+ _11 = const {0x1 as *mut [bool; 0]} as *mut u8 (PtrToPtr);
103+
StorageLive(_12);
104+
StorageLive(_13);
105+
_13 = _11 as *mut () (PtrToPtr);
106+
_12 = move _13 as usize (Transmute);
107+
StorageDead(_13);
108+
StorageDead(_11);
109+
switchInt(move _12) -> [0: bb5, otherwise: bb6];
110+
}
111+
112+
bb4: {
113+
- _9 = _6 as *const [bool; 0] (PointerCoercion(MutToConstPointer));
114+
+ _9 = const {0x1 as *mut [bool; 0]} as *const [bool; 0] (PointerCoercion(MutToConstPointer));
115+
_5 = NonNull::<[bool; 0]> { pointer: _9 };
85116
StorageDead(_9);
86117
StorageDead(_8);
87118
StorageDead(_6);
@@ -90,16 +121,22 @@
90121
_3 = move _4 as std::ptr::Unique<[bool]> (PointerCoercion(Unsize));
91122
StorageDead(_4);
92123
_2 = Box::<[bool]>(_3, const std::alloc::Global);
124+
StorageDead(_10);
93125
StorageDead(_3);
94126
_1 = A { foo: move _2 };
95127
StorageDead(_2);
96128
_0 = const ();
97129
drop(_1) -> [return: bb1, unwind unreachable];
98130
}
99131

100-
bb1: {
101-
StorageDead(_1);
102-
return;
132+
bb5: {
133+
StorageDead(_12);
134+
_10 = core::panicking::panic_nounwind(const "unsafe precondition(s) violated: NonNull::new_unchecked requires that the pointer is non-null") -> unwind unreachable;
135+
}
136+
137+
bb6: {
138+
StorageDead(_12);
139+
goto -> bb4;
103140
}
104141
}
105142

‎tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.GVN.64bit.panic-unwind.diff‎

Lines changed: 62 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,28 @@
2424
debug ptr => _6;
2525
scope 11 (inlined NonNull::<[bool; 0]>::new_unchecked) {
2626
debug ptr => _6;
27-
let mut _8: *const [bool; 0];
28-
let mut _9: *mut [bool; 0];
27+
let mut _9: *const [bool; 0];
2928
scope 12 {
30-
scope 13 (inlined NonNull::<T>::new_unchecked::runtime::<[bool; 0]>) {
31-
debug ptr => _9;
32-
scope 14 (inlined std::ptr::mut_ptr::<impl *mut [bool; 0]>::is_null) {
33-
debug self => _9;
34-
let mut _10: *mut u8;
35-
scope 15 {
36-
scope 16 (inlined std::ptr::mut_ptr::<impl *mut T>::is_null::runtime_impl) {
37-
debug ptr => _10;
38-
scope 17 (inlined std::ptr::mut_ptr::<impl *mut u8>::addr) {
39-
debug self => _10;
40-
scope 18 {
41-
scope 19 (inlined std::ptr::mut_ptr::<impl *mut u8>::cast::<()>) {
42-
debug self => _10;
29+
let _8: bool;
30+
scope 13 {
31+
debug should_check => _8;
32+
scope 14 (inlined NonNull::<T>::new_unchecked::runtime::<[bool; 0]>) {
33+
debug ptr => _6;
34+
let _10: !;
35+
scope 15 (inlined std::ptr::mut_ptr::<impl *mut [bool; 0]>::is_null) {
36+
debug self => _6;
37+
let mut _11: *mut u8;
38+
scope 16 {
39+
scope 17 (inlined std::ptr::mut_ptr::<impl *mut T>::is_null::runtime_impl) {
40+
debug ptr => _11;
41+
let mut _12: usize;
42+
scope 18 (inlined std::ptr::mut_ptr::<impl *mut u8>::addr) {
43+
debug self => _11;
44+
let mut _13: *mut ();
45+
scope 19 {
46+
scope 20 (inlined std::ptr::mut_ptr::<impl *mut u8>::cast::<()>) {
47+
debug self => _11;
48+
}
4349
}
4450
}
4551
}
@@ -66,6 +72,7 @@
6672
StorageLive(_1);
6773
StorageLive(_2);
6874
StorageLive(_3);
75+
StorageLive(_10);
6976
StorageLive(_4);
7077
StorageLive(_5);
7178
StorageLive(_6);
@@ -77,11 +84,39 @@
7784
StorageDead(_7);
7885
StorageLive(_8);
7986
StorageLive(_9);
80-
StorageLive(_10);
81-
- _8 = _6 as *const [bool; 0] (PointerCoercion(MutToConstPointer));
82-
+ _8 = const {0x1 as *mut [bool; 0]} as *const [bool; 0] (PointerCoercion(MutToConstPointer));
83-
_5 = NonNull::<[bool; 0]> { pointer: _8 };
84-
StorageDead(_10);
87+
_8 = intrinsics::debug_assertions() -> [return: bb3, unwind unreachable];
88+
}
89+
90+
bb1: {
91+
StorageDead(_1);
92+
return;
93+
}
94+
95+
bb2 (cleanup): {
96+
resume;
97+
}
98+
99+
bb3: {
100+
switchInt(_8) -> [0: bb5, otherwise: bb4];
101+
}
102+
103+
bb4: {
104+
StorageLive(_11);
105+
- _11 = _6 as *mut u8 (PtrToPtr);
106+
+ _11 = const {0x1 as *mut [bool; 0]} as *mut u8 (PtrToPtr);
107+
StorageLive(_12);
108+
StorageLive(_13);
109+
_13 = _11 as *mut () (PtrToPtr);
110+
_12 = move _13 as usize (Transmute);
111+
StorageDead(_13);
112+
StorageDead(_11);
113+
switchInt(move _12) -> [0: bb6, otherwise: bb7];
114+
}
115+
116+
bb5: {
117+
- _9 = _6 as *const [bool; 0] (PointerCoercion(MutToConstPointer));
118+
+ _9 = const {0x1 as *mut [bool; 0]} as *const [bool; 0] (PointerCoercion(MutToConstPointer));
119+
_5 = NonNull::<[bool; 0]> { pointer: _9 };
85120
StorageDead(_9);
86121
StorageDead(_8);
87122
StorageDead(_6);
@@ -90,20 +125,22 @@
90125
_3 = move _4 as std::ptr::Unique<[bool]> (PointerCoercion(Unsize));
91126
StorageDead(_4);
92127
_2 = Box::<[bool]>(_3, const std::alloc::Global);
128+
StorageDead(_10);
93129
StorageDead(_3);
94130
_1 = A { foo: move _2 };
95131
StorageDead(_2);
96132
_0 = const ();
97133
drop(_1) -> [return: bb1, unwind: bb2];
98134
}
99135

100-
bb1: {
101-
StorageDead(_1);
102-
return;
136+
bb6: {
137+
StorageDead(_12);
138+
_10 = core::panicking::panic_nounwind(const "unsafe precondition(s) violated: NonNull::new_unchecked requires that the pointer is non-null") -> unwind unreachable;
103139
}
104140

105-
bb2 (cleanup): {
106-
resume;
141+
bb7: {
142+
StorageDead(_12);
143+
goto -> bb5;
107144
}
108145
}
109146

‎tests/mir-opt/inline/unwrap_unchecked.unwrap_unchecked.Inline.panic-abort.diff‎

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,18 @@
99
+ debug self => _2;
1010
+ let mut _3: &std::option::Option<T>;
1111
+ let mut _4: isize;
12-
+ let mut _5: bool;
1312
+ scope 2 {
1413
+ debug val => _0;
1514
+ }
1615
+ scope 3 {
1716
+ scope 5 (inlined unreachable_unchecked) {
1817
+ scope 6 {
19-
+ scope 7 (inlined unreachable_unchecked::runtime) {
18+
+ let _5: bool;
19+
+ scope 7 {
20+
+ debug should_check => _5;
21+
+ scope 8 (inlined unreachable_unchecked::runtime) {
22+
+ let _6: !;
23+
+ }
2024
+ }
2125
+ }
2226
+ }
@@ -30,21 +34,34 @@
3034
StorageLive(_2);
3135
_2 = move _1;
3236
- _0 = Option::<T>::unwrap_unchecked(move _2) -> [return: bb1, unwind unreachable];
33-
- }
34-
-
35-
- bb1: {
3637
+ StorageLive(_3);
3738
+ StorageLive(_4);
38-
+ StorageLive(_5);
39+
+ StorageLive(_6);
3940
+ _4 = discriminant(_2);
40-
+ _5 = Eq(_4, const 1_isize);
41-
+ assume(move _5);
41+
+ switchInt(move _4) -> [0: bb1, 1: bb3, otherwise: bb2];
42+
}
43+
44+
bb1: {
45+
+ StorageLive(_5);
46+
+ _5 = intrinsics::debug_assertions() -> [return: bb4, unwind unreachable];
47+
+ }
48+
+
49+
+ bb2: {
50+
+ unreachable;
51+
+ }
52+
+
53+
+ bb3: {
4254
+ _0 = move ((_2 as Some).0: T);
43-
+ StorageDead(_5);
55+
+ StorageDead(_6);
4456
+ StorageDead(_4);
4557
+ StorageDead(_3);
4658
StorageDead(_2);
4759
return;
60+
+ }
61+
+
62+
+ bb4: {
63+
+ assume(_5);
64+
+ _6 = core::panicking::panic_nounwind(const "unsafe precondition(s) violated: hint::unreachable_unchecked must never be reached") -> unwind unreachable;
4865
}
4966
}
5067

‎tests/mir-opt/inline/unwrap_unchecked.unwrap_unchecked.Inline.panic-unwind.diff‎

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,18 @@
99
+ debug self => _2;
1010
+ let mut _3: &std::option::Option<T>;
1111
+ let mut _4: isize;
12-
+ let mut _5: bool;
1312
+ scope 2 {
1413
+ debug val => _0;
1514
+ }
1615
+ scope 3 {
1716
+ scope 5 (inlined unreachable_unchecked) {
1817
+ scope 6 {
19-
+ scope 7 (inlined unreachable_unchecked::runtime) {
18+
+ let _5: bool;
19+
+ scope 7 {
20+
+ debug should_check => _5;
21+
+ scope 8 (inlined unreachable_unchecked::runtime) {
22+
+ let _6: !;
23+
+ }
2024
+ }
2125
+ }
2226
+ }
@@ -30,25 +34,36 @@
3034
StorageLive(_2);
3135
_2 = move _1;
3236
- _0 = Option::<T>::unwrap_unchecked(move _2) -> [return: bb1, unwind: bb2];
33-
- }
34-
-
35-
- bb1: {
3637
+ StorageLive(_3);
3738
+ StorageLive(_4);
38-
+ StorageLive(_5);
39+
+ StorageLive(_6);
3940
+ _4 = discriminant(_2);
40-
+ _5 = Eq(_4, const 1_isize);
41-
+ assume(move _5);
41+
+ switchInt(move _4) -> [0: bb1, 1: bb3, otherwise: bb2];
42+
}
43+
44+
bb1: {
45+
+ StorageLive(_5);
46+
+ _5 = intrinsics::debug_assertions() -> [return: bb4, unwind unreachable];
47+
+ }
48+
+
49+
+ bb2: {
50+
+ unreachable;
51+
+ }
52+
+
53+
+ bb3: {
4254
+ _0 = move ((_2 as Some).0: T);
43-
+ StorageDead(_5);
55+
+ StorageDead(_6);
4456
+ StorageDead(_4);
4557
+ StorageDead(_3);
4658
StorageDead(_2);
4759
return;
48-
- }
49-
-
60+
}
61+
5062
- bb2 (cleanup): {
5163
- resume;
64+
+ bb4: {
65+
+ assume(_5);
66+
+ _6 = core::panicking::panic_nounwind(const "unsafe precondition(s) violated: hint::unreachable_unchecked must never be reached") -> unwind unreachable;
5267
}
5368
}
5469

‎tests/mir-opt/inline/unwrap_unchecked.unwrap_unchecked.PreCodegen.after.panic-abort.mir‎

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,35 +6,53 @@ fn unwrap_unchecked(_1: Option<T>) -> T {
66
scope 1 (inlined #[track_caller] Option::<T>::unwrap_unchecked) {
77
debug self => _1;
88
let mut _2: isize;
9-
let mut _3: bool;
10-
let mut _4: &std::option::Option<T>;
9+
let mut _5: &std::option::Option<T>;
1110
scope 2 {
1211
debug val => _0;
1312
}
1413
scope 3 {
1514
scope 5 (inlined unreachable_unchecked) {
1615
scope 6 {
17-
scope 7 (inlined unreachable_unchecked::runtime) {
16+
let _3: bool;
17+
scope 7 {
18+
debug should_check => _3;
19+
scope 8 (inlined unreachable_unchecked::runtime) {
20+
let _4: !;
21+
}
1822
}
1923
}
2024
}
2125
}
2226
scope 4 (inlined Option::<T>::is_some) {
23-
debug self => _4;
27+
debug self => _5;
2428
}
2529
}
2630

2731
bb0: {
28-
StorageLive(_4);
32+
StorageLive(_5);
2933
StorageLive(_2);
30-
StorageLive(_3);
3134
_2 = discriminant(_1);
32-
_3 = Eq(_2, const 1_isize);
33-
assume(move _3);
35+
switchInt(move _2) -> [0: bb1, 1: bb3, otherwise: bb4];
36+
}
37+
38+
bb1: {
39+
StorageLive(_3);
40+
_3 = intrinsics::debug_assertions() -> [return: bb2, unwind unreachable];
41+
}
42+
43+
bb2: {
44+
assume(_3);
45+
_4 = core::panicking::panic_nounwind(const "unsafe precondition(s) violated: hint::unreachable_unchecked must never be reached") -> unwind unreachable;
46+
}
47+
48+
bb3: {
3449
_0 = ((_1 as Some).0: T);
35-
StorageDead(_3);
3650
StorageDead(_2);
37-
StorageDead(_4);
51+
StorageDead(_5);
3852
return;
3953
}
54+
55+
bb4: {
56+
unreachable;
57+
}
4058
}

‎tests/mir-opt/inline/unwrap_unchecked.unwrap_unchecked.PreCodegen.after.panic-unwind.mir‎

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,35 +6,53 @@ fn unwrap_unchecked(_1: Option<T>) -> T {
66
scope 1 (inlined #[track_caller] Option::<T>::unwrap_unchecked) {
77
debug self => _1;
88
let mut _2: isize;
9-
let mut _3: bool;
10-
let mut _4: &std::option::Option<T>;
9+
let mut _5: &std::option::Option<T>;
1110
scope 2 {
1211
debug val => _0;
1312
}
1413
scope 3 {
1514
scope 5 (inlined unreachable_unchecked) {
1615
scope 6 {
17-
scope 7 (inlined unreachable_unchecked::runtime) {
16+
let _3: bool;
17+
scope 7 {
18+
debug should_check => _3;
19+
scope 8 (inlined unreachable_unchecked::runtime) {
20+
let _4: !;
21+
}
1822
}
1923
}
2024
}
2125
}
2226
scope 4 (inlined Option::<T>::is_some) {
23-
debug self => _4;
27+
debug self => _5;
2428
}
2529
}
2630

2731
bb0: {
28-
StorageLive(_4);
32+
StorageLive(_5);
2933
StorageLive(_2);
30-
StorageLive(_3);
3134
_2 = discriminant(_1);
32-
_3 = Eq(_2, const 1_isize);
33-
assume(move _3);
35+
switchInt(move _2) -> [0: bb1, 1: bb3, otherwise: bb4];
36+
}
37+
38+
bb1: {
39+
StorageLive(_3);
40+
_3 = intrinsics::debug_assertions() -> [return: bb2, unwind unreachable];
41+
}
42+
43+
bb2: {
44+
assume(_3);
45+
_4 = core::panicking::panic_nounwind(const "unsafe precondition(s) violated: hint::unreachable_unchecked must never be reached") -> unwind unreachable;
46+
}
47+
48+
bb3: {
3449
_0 = ((_1 as Some).0: T);
35-
StorageDead(_3);
3650
StorageDead(_2);
37-
StorageDead(_4);
51+
StorageDead(_5);
3852
return;
3953
}
54+
55+
bb4: {
56+
unreachable;
57+
}
4058
}

‎tests/mir-opt/pre-codegen/duplicate_switch_targets.ub_if_b.PreCodegen.after.mir‎

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,39 @@ fn ub_if_b(_1: Thing) -> Thing {
44
debug t => _1;
55
let mut _0: Thing;
66
let mut _2: isize;
7-
let mut _3: bool;
87
scope 1 (inlined unreachable_unchecked) {
98
scope 2 {
10-
scope 3 (inlined unreachable_unchecked::runtime) {
9+
let _3: bool;
10+
scope 3 {
11+
debug should_check => _3;
12+
scope 4 (inlined unreachable_unchecked::runtime) {
13+
let _4: !;
14+
}
1115
}
1216
}
1317
}
1418

1519
bb0: {
1620
_2 = discriminant(_1);
17-
_3 = Eq(_2, const 0_isize);
18-
assume(move _3);
21+
switchInt(move _2) -> [0: bb1, 1: bb2, otherwise: bb4];
22+
}
23+
24+
bb1: {
1925
_0 = move _1;
2026
return;
2127
}
28+
29+
bb2: {
30+
StorageLive(_3);
31+
_3 = intrinsics::debug_assertions() -> [return: bb3, unwind unreachable];
32+
}
33+
34+
bb3: {
35+
assume(_3);
36+
_4 = core::panicking::panic_nounwind(const "unsafe precondition(s) violated: hint::unreachable_unchecked must never be reached") -> unwind unreachable;
37+
}
38+
39+
bb4: {
40+
unreachable;
41+
}
2242
}
File renamed without changes.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// MIR for `manual_replace` after PreCodegen
2+
3+
fn manual_replace(_1: &mut u32, _2: u32) -> u32 {
4+
debug r => _1;
5+
debug v => _2;
6+
let mut _0: u32;
7+
scope 1 {
8+
debug temp => _0;
9+
}
10+
11+
bb0: {
12+
_0 = (*_1);
13+
(*_1) = _2;
14+
return;
15+
}
16+
}

‎tests/mir-opt/pre-codegen/mem_replace.mem_replace.PreCodegen.after.mir‎

Lines changed: 0 additions & 66 deletions
This file was deleted.
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// MIR for `mem_replace` after PreCodegen
2+
3+
fn mem_replace(_1: &mut u32, _2: u32) -> u32 {
4+
debug r => _1;
5+
debug v => _2;
6+
let mut _0: u32;
7+
scope 1 (inlined std::mem::replace::<u32>) {
8+
debug dest => _1;
9+
debug src => _2;
10+
scope 2 {
11+
scope 3 {
12+
debug result => _0;
13+
scope 6 (inlined std::ptr::write::<u32>) {
14+
debug dst => _1;
15+
debug src => _2;
16+
scope 7 {
17+
}
18+
}
19+
}
20+
scope 4 (inlined std::ptr::read::<u32>) {
21+
debug src => _1;
22+
scope 5 {
23+
}
24+
}
25+
}
26+
}
27+
28+
bb0: {
29+
_0 = (*_1);
30+
(*_1) = _2;
31+
return;
32+
}
33+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// MIR for `mem_replace` after PreCodegen
2+
3+
fn mem_replace(_1: &mut u32, _2: u32) -> u32 {
4+
debug r => _1;
5+
debug v => _2;
6+
let mut _0: u32;
7+
scope 1 (inlined std::mem::replace::<u32>) {
8+
debug dest => _1;
9+
debug src => _2;
10+
scope 2 {
11+
scope 3 {
12+
debug result => _0;
13+
scope 6 (inlined std::ptr::write::<u32>) {
14+
debug dst => _1;
15+
debug src => _2;
16+
scope 7 {
17+
}
18+
}
19+
}
20+
scope 4 (inlined std::ptr::read::<u32>) {
21+
debug src => _1;
22+
scope 5 {
23+
}
24+
}
25+
}
26+
}
27+
28+
bb0: {
29+
_0 = (*_1);
30+
(*_1) = _2;
31+
return;
32+
}
33+
}

‎tests/mir-opt/pre-codegen/mem_replace.rs‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
// skip-filecheck
2-
// compile-flags: -O -C debuginfo=0 -Zmir-opt-level=2
2+
// compile-flags: -O -C debuginfo=0 -Zmir-opt-level=2 -Zinline-mir
33
// only-64bit
44
// ignore-debug the standard library debug assertions leak into this test
5+
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY
56

67
#![crate_type = "lib"]
78

‎tests/mir-opt/pre-codegen/slice_iter.enumerated_loop.PreCodegen.after.panic-abort.mir‎

Lines changed: 48 additions & 153 deletions
Original file line numberDiff line numberDiff line change
@@ -4,196 +4,91 @@ fn enumerated_loop(_1: &[T], _2: impl Fn(usize, &T)) -> () {
44
debug slice => _1;
55
debug f => _2;
66
let mut _0: ();
7-
let mut _13: std::slice::Iter<'_, T>;
8-
let mut _14: std::iter::Enumerate<std::slice::Iter<'_, T>>;
9-
let mut _15: std::iter::Enumerate<std::slice::Iter<'_, T>>;
10-
let mut _16: &mut std::iter::Enumerate<std::slice::Iter<'_, T>>;
11-
let mut _17: std::option::Option<(usize, &T)>;
12-
let mut _18: isize;
13-
let mut _21: &impl Fn(usize, &T);
14-
let mut _22: (usize, &T);
15-
let _23: ();
7+
let mut _3: std::slice::Iter<'_, T>;
8+
let mut _4: std::iter::Enumerate<std::slice::Iter<'_, T>>;
9+
let mut _5: std::iter::Enumerate<std::slice::Iter<'_, T>>;
10+
let mut _6: &mut std::iter::Enumerate<std::slice::Iter<'_, T>>;
11+
let mut _7: std::option::Option<(usize, &T)>;
12+
let mut _8: isize;
13+
let mut _11: &impl Fn(usize, &T);
14+
let mut _12: (usize, &T);
15+
let _13: ();
1616
scope 1 {
17-
debug iter => _15;
18-
let _19: usize;
19-
let _20: &T;
17+
debug iter => _5;
18+
let _9: usize;
19+
let _10: &T;
2020
scope 2 {
21-
debug i => _19;
22-
debug x => _20;
21+
debug i => _9;
22+
debug x => _10;
2323
}
2424
}
2525
scope 3 (inlined core::slice::<impl [T]>::iter) {
2626
debug self => _1;
27-
scope 4 (inlined std::slice::Iter::<'_, T>::new) {
28-
debug slice => _1;
29-
let _4: *const T;
30-
let mut _5: bool;
31-
let mut _6: usize;
32-
let mut _8: usize;
33-
let mut _9: *mut T;
34-
let mut _11: std::ptr::NonNull<T>;
35-
let mut _12: *const T;
36-
scope 5 {
37-
debug ptr => _4;
38-
scope 6 {
39-
let _7: *const T;
40-
scope 7 {
41-
debug end_or_len => _7;
42-
scope 13 (inlined NonNull::<T>::new_unchecked) {
43-
debug ptr => _9;
44-
let mut _10: *const T;
45-
let mut _24: *mut T;
46-
scope 14 {
47-
scope 15 (inlined NonNull::<T>::new_unchecked::runtime::<T>) {
48-
debug ptr => _24;
49-
scope 16 (inlined std::ptr::mut_ptr::<impl *mut T>::is_null) {
50-
debug self => _24;
51-
let mut _25: *mut u8;
52-
scope 17 {
53-
scope 18 (inlined std::ptr::mut_ptr::<impl *mut T>::is_null::runtime_impl) {
54-
debug ptr => _25;
55-
scope 19 (inlined std::ptr::mut_ptr::<impl *mut u8>::addr) {
56-
debug self => _25;
57-
scope 20 {
58-
scope 21 (inlined std::ptr::mut_ptr::<impl *mut u8>::cast::<()>) {
59-
debug self => _25;
60-
}
61-
}
62-
}
63-
}
64-
}
65-
}
66-
}
67-
}
68-
}
69-
}
70-
scope 9 (inlined invalid::<T>) {
71-
debug addr => _8;
72-
scope 10 {
73-
}
74-
}
75-
scope 11 (inlined std::ptr::const_ptr::<impl *const T>::add) {
76-
debug self => _4;
77-
debug count => _6;
78-
scope 12 {
79-
}
80-
}
81-
}
82-
}
83-
scope 8 (inlined core::slice::<impl [T]>::as_ptr) {
84-
debug self => _1;
85-
let mut _3: *const [T];
86-
}
87-
}
8827
}
89-
scope 22 (inlined <std::slice::Iter<'_, T> as Iterator>::enumerate) {
90-
debug self => _13;
91-
scope 23 (inlined Enumerate::<std::slice::Iter<'_, T>>::new) {
92-
debug iter => _13;
28+
scope 4 (inlined <std::slice::Iter<'_, T> as Iterator>::enumerate) {
29+
debug self => _3;
30+
scope 5 (inlined Enumerate::<std::slice::Iter<'_, T>>::new) {
31+
debug iter => _3;
9332
}
9433
}
95-
scope 24 (inlined <Enumerate<std::slice::Iter<'_, T>> as IntoIterator>::into_iter) {
96-
debug self => _14;
34+
scope 6 (inlined <Enumerate<std::slice::Iter<'_, T>> as IntoIterator>::into_iter) {
35+
debug self => _4;
9736
}
9837

9938
bb0: {
100-
StorageLive(_13);
101-
StorageLive(_4);
10239
StorageLive(_3);
103-
_3 = &raw const (*_1);
104-
_4 = move _3 as *const T (PtrToPtr);
105-
StorageDead(_3);
106-
StorageLive(_7);
107-
StorageLive(_5);
108-
_5 = const _;
109-
switchInt(move _5) -> [0: bb1, otherwise: bb2];
40+
_3 = std::slice::Iter::<'_, T>::new(move _1) -> [return: bb1, unwind unreachable];
11041
}
11142

11243
bb1: {
113-
StorageLive(_6);
114-
_6 = Len((*_1));
115-
_7 = Offset(_4, _6);
116-
StorageDead(_6);
117-
goto -> bb3;
44+
_4 = Enumerate::<std::slice::Iter<'_, T>> { iter: _3, count: const 0_usize };
45+
StorageDead(_3);
46+
StorageLive(_5);
47+
_5 = _4;
48+
goto -> bb2;
11849
}
11950

12051
bb2: {
121-
StorageLive(_8);
122-
_8 = Len((*_1));
123-
_7 = _8 as *const T (Transmute);
124-
StorageDead(_8);
125-
goto -> bb3;
52+
StorageLive(_7);
53+
StorageLive(_6);
54+
_6 = &mut _5;
55+
_7 = <Enumerate<std::slice::Iter<'_, T>> as Iterator>::next(move _6) -> [return: bb3, unwind unreachable];
12656
}
12757

12858
bb3: {
129-
StorageDead(_5);
130-
StorageLive(_11);
131-
StorageLive(_9);
132-
_9 = _4 as *mut T (PtrToPtr);
133-
StorageLive(_10);
134-
StorageLive(_24);
135-
StorageLive(_25);
136-
_10 = _9 as *const T (PointerCoercion(MutToConstPointer));
137-
_11 = NonNull::<T> { pointer: _10 };
138-
StorageDead(_25);
139-
StorageDead(_24);
140-
StorageDead(_10);
141-
StorageDead(_9);
142-
StorageLive(_12);
143-
_12 = _7;
144-
_13 = std::slice::Iter::<'_, T> { ptr: move _11, end_or_len: move _12, _marker: const ZeroSized: PhantomData<&T> };
145-
StorageDead(_12);
146-
StorageDead(_11);
147-
StorageDead(_7);
148-
StorageDead(_4);
149-
_14 = Enumerate::<std::slice::Iter<'_, T>> { iter: _13, count: const 0_usize };
150-
StorageDead(_13);
151-
StorageLive(_15);
152-
_15 = _14;
153-
goto -> bb4;
59+
StorageDead(_6);
60+
_8 = discriminant(_7);
61+
switchInt(move _8) -> [0: bb4, 1: bb6, otherwise: bb8];
15462
}
15563

15664
bb4: {
157-
StorageLive(_17);
158-
StorageLive(_16);
159-
_16 = &mut _15;
160-
_17 = <Enumerate<std::slice::Iter<'_, T>> as Iterator>::next(move _16) -> [return: bb5, unwind unreachable];
65+
StorageDead(_7);
66+
StorageDead(_5);
67+
drop(_2) -> [return: bb5, unwind unreachable];
16168
}
16269

16370
bb5: {
164-
StorageDead(_16);
165-
_18 = discriminant(_17);
166-
switchInt(move _18) -> [0: bb6, 1: bb8, otherwise: bb10];
71+
return;
16772
}
16873

16974
bb6: {
170-
StorageDead(_17);
171-
StorageDead(_15);
172-
drop(_2) -> [return: bb7, unwind unreachable];
75+
_9 = (((_7 as Some).0: (usize, &T)).0: usize);
76+
_10 = (((_7 as Some).0: (usize, &T)).1: &T);
77+
StorageLive(_11);
78+
_11 = &_2;
79+
StorageLive(_12);
80+
_12 = (_9, _10);
81+
_13 = <impl Fn(usize, &T) as Fn<(usize, &T)>>::call(move _11, move _12) -> [return: bb7, unwind unreachable];
17382
}
17483

17584
bb7: {
176-
return;
85+
StorageDead(_12);
86+
StorageDead(_11);
87+
StorageDead(_7);
88+
goto -> bb2;
17789
}
17890

17991
bb8: {
180-
_19 = (((_17 as Some).0: (usize, &T)).0: usize);
181-
_20 = (((_17 as Some).0: (usize, &T)).1: &T);
182-
StorageLive(_21);
183-
_21 = &_2;
184-
StorageLive(_22);
185-
_22 = (_19, _20);
186-
_23 = <impl Fn(usize, &T) as Fn<(usize, &T)>>::call(move _21, move _22) -> [return: bb9, unwind unreachable];
187-
}
188-
189-
bb9: {
190-
StorageDead(_22);
191-
StorageDead(_21);
192-
StorageDead(_17);
193-
goto -> bb4;
194-
}
195-
196-
bb10: {
19792
unreachable;
19893
}
19994
}

‎tests/mir-opt/pre-codegen/slice_iter.enumerated_loop.PreCodegen.after.panic-unwind.mir‎

Lines changed: 51 additions & 156 deletions
Original file line numberDiff line numberDiff line change
@@ -4,204 +4,99 @@ fn enumerated_loop(_1: &[T], _2: impl Fn(usize, &T)) -> () {
44
debug slice => _1;
55
debug f => _2;
66
let mut _0: ();
7-
let mut _13: std::slice::Iter<'_, T>;
8-
let mut _14: std::iter::Enumerate<std::slice::Iter<'_, T>>;
9-
let mut _15: std::iter::Enumerate<std::slice::Iter<'_, T>>;
10-
let mut _16: &mut std::iter::Enumerate<std::slice::Iter<'_, T>>;
11-
let mut _17: std::option::Option<(usize, &T)>;
12-
let mut _18: isize;
13-
let mut _21: &impl Fn(usize, &T);
14-
let mut _22: (usize, &T);
15-
let _23: ();
7+
let mut _3: std::slice::Iter<'_, T>;
8+
let mut _4: std::iter::Enumerate<std::slice::Iter<'_, T>>;
9+
let mut _5: std::iter::Enumerate<std::slice::Iter<'_, T>>;
10+
let mut _6: &mut std::iter::Enumerate<std::slice::Iter<'_, T>>;
11+
let mut _7: std::option::Option<(usize, &T)>;
12+
let mut _8: isize;
13+
let mut _11: &impl Fn(usize, &T);
14+
let mut _12: (usize, &T);
15+
let _13: ();
1616
scope 1 {
17-
debug iter => _15;
18-
let _19: usize;
19-
let _20: &T;
17+
debug iter => _5;
18+
let _9: usize;
19+
let _10: &T;
2020
scope 2 {
21-
debug i => _19;
22-
debug x => _20;
21+
debug i => _9;
22+
debug x => _10;
2323
}
2424
}
2525
scope 3 (inlined core::slice::<impl [T]>::iter) {
2626
debug self => _1;
27-
scope 4 (inlined std::slice::Iter::<'_, T>::new) {
28-
debug slice => _1;
29-
let _4: *const T;
30-
let mut _5: bool;
31-
let mut _6: usize;
32-
let mut _8: usize;
33-
let mut _9: *mut T;
34-
let mut _11: std::ptr::NonNull<T>;
35-
let mut _12: *const T;
36-
scope 5 {
37-
debug ptr => _4;
38-
scope 6 {
39-
let _7: *const T;
40-
scope 7 {
41-
debug end_or_len => _7;
42-
scope 13 (inlined NonNull::<T>::new_unchecked) {
43-
debug ptr => _9;
44-
let mut _10: *const T;
45-
let mut _24: *mut T;
46-
scope 14 {
47-
scope 15 (inlined NonNull::<T>::new_unchecked::runtime::<T>) {
48-
debug ptr => _24;
49-
scope 16 (inlined std::ptr::mut_ptr::<impl *mut T>::is_null) {
50-
debug self => _24;
51-
let mut _25: *mut u8;
52-
scope 17 {
53-
scope 18 (inlined std::ptr::mut_ptr::<impl *mut T>::is_null::runtime_impl) {
54-
debug ptr => _25;
55-
scope 19 (inlined std::ptr::mut_ptr::<impl *mut u8>::addr) {
56-
debug self => _25;
57-
scope 20 {
58-
scope 21 (inlined std::ptr::mut_ptr::<impl *mut u8>::cast::<()>) {
59-
debug self => _25;
60-
}
61-
}
62-
}
63-
}
64-
}
65-
}
66-
}
67-
}
68-
}
69-
}
70-
scope 9 (inlined invalid::<T>) {
71-
debug addr => _8;
72-
scope 10 {
73-
}
74-
}
75-
scope 11 (inlined std::ptr::const_ptr::<impl *const T>::add) {
76-
debug self => _4;
77-
debug count => _6;
78-
scope 12 {
79-
}
80-
}
81-
}
82-
}
83-
scope 8 (inlined core::slice::<impl [T]>::as_ptr) {
84-
debug self => _1;
85-
let mut _3: *const [T];
86-
}
87-
}
8827
}
89-
scope 22 (inlined <std::slice::Iter<'_, T> as Iterator>::enumerate) {
90-
debug self => _13;
91-
scope 23 (inlined Enumerate::<std::slice::Iter<'_, T>>::new) {
92-
debug iter => _13;
28+
scope 4 (inlined <std::slice::Iter<'_, T> as Iterator>::enumerate) {
29+
debug self => _3;
30+
scope 5 (inlined Enumerate::<std::slice::Iter<'_, T>>::new) {
31+
debug iter => _3;
9332
}
9433
}
95-
scope 24 (inlined <Enumerate<std::slice::Iter<'_, T>> as IntoIterator>::into_iter) {
96-
debug self => _14;
34+
scope 6 (inlined <Enumerate<std::slice::Iter<'_, T>> as IntoIterator>::into_iter) {
35+
debug self => _4;
9736
}
9837

9938
bb0: {
100-
StorageLive(_13);
101-
StorageLive(_4);
10239
StorageLive(_3);
103-
_3 = &raw const (*_1);
104-
_4 = move _3 as *const T (PtrToPtr);
105-
StorageDead(_3);
106-
StorageLive(_7);
107-
StorageLive(_5);
108-
_5 = const _;
109-
switchInt(move _5) -> [0: bb1, otherwise: bb2];
40+
_3 = std::slice::Iter::<'_, T>::new(move _1) -> [return: bb1, unwind: bb9];
11041
}
11142

11243
bb1: {
113-
StorageLive(_6);
114-
_6 = Len((*_1));
115-
_7 = Offset(_4, _6);
116-
StorageDead(_6);
117-
goto -> bb3;
44+
_4 = Enumerate::<std::slice::Iter<'_, T>> { iter: _3, count: const 0_usize };
45+
StorageDead(_3);
46+
StorageLive(_5);
47+
_5 = _4;
48+
goto -> bb2;
11849
}
11950

12051
bb2: {
121-
StorageLive(_8);
122-
_8 = Len((*_1));
123-
_7 = _8 as *const T (Transmute);
124-
StorageDead(_8);
125-
goto -> bb3;
52+
StorageLive(_7);
53+
StorageLive(_6);
54+
_6 = &mut _5;
55+
_7 = <Enumerate<std::slice::Iter<'_, T>> as Iterator>::next(move _6) -> [return: bb3, unwind: bb9];
12656
}
12757

12858
bb3: {
129-
StorageDead(_5);
130-
StorageLive(_11);
131-
StorageLive(_9);
132-
_9 = _4 as *mut T (PtrToPtr);
133-
StorageLive(_10);
134-
StorageLive(_24);
135-
StorageLive(_25);
136-
_10 = _9 as *const T (PointerCoercion(MutToConstPointer));
137-
_11 = NonNull::<T> { pointer: _10 };
138-
StorageDead(_25);
139-
StorageDead(_24);
140-
StorageDead(_10);
141-
StorageDead(_9);
142-
StorageLive(_12);
143-
_12 = _7;
144-
_13 = std::slice::Iter::<'_, T> { ptr: move _11, end_or_len: move _12, _marker: const ZeroSized: PhantomData<&T> };
145-
StorageDead(_12);
146-
StorageDead(_11);
147-
StorageDead(_7);
148-
StorageDead(_4);
149-
_14 = Enumerate::<std::slice::Iter<'_, T>> { iter: _13, count: const 0_usize };
150-
StorageDead(_13);
151-
StorageLive(_15);
152-
_15 = _14;
153-
goto -> bb4;
59+
StorageDead(_6);
60+
_8 = discriminant(_7);
61+
switchInt(move _8) -> [0: bb4, 1: bb6, otherwise: bb8];
15462
}
15563

15664
bb4: {
157-
StorageLive(_17);
158-
StorageLive(_16);
159-
_16 = &mut _15;
160-
_17 = <Enumerate<std::slice::Iter<'_, T>> as Iterator>::next(move _16) -> [return: bb5, unwind: bb11];
65+
StorageDead(_7);
66+
StorageDead(_5);
67+
drop(_2) -> [return: bb5, unwind continue];
16168
}
16269

16370
bb5: {
164-
StorageDead(_16);
165-
_18 = discriminant(_17);
166-
switchInt(move _18) -> [0: bb6, 1: bb8, otherwise: bb10];
71+
return;
16772
}
16873

16974
bb6: {
170-
StorageDead(_17);
171-
StorageDead(_15);
172-
drop(_2) -> [return: bb7, unwind continue];
75+
_9 = (((_7 as Some).0: (usize, &T)).0: usize);
76+
_10 = (((_7 as Some).0: (usize, &T)).1: &T);
77+
StorageLive(_11);
78+
_11 = &_2;
79+
StorageLive(_12);
80+
_12 = (_9, _10);
81+
_13 = <impl Fn(usize, &T) as Fn<(usize, &T)>>::call(move _11, move _12) -> [return: bb7, unwind: bb9];
17382
}
17483

17584
bb7: {
176-
return;
85+
StorageDead(_12);
86+
StorageDead(_11);
87+
StorageDead(_7);
88+
goto -> bb2;
17789
}
17890

17991
bb8: {
180-
_19 = (((_17 as Some).0: (usize, &T)).0: usize);
181-
_20 = (((_17 as Some).0: (usize, &T)).1: &T);
182-
StorageLive(_21);
183-
_21 = &_2;
184-
StorageLive(_22);
185-
_22 = (_19, _20);
186-
_23 = <impl Fn(usize, &T) as Fn<(usize, &T)>>::call(move _21, move _22) -> [return: bb9, unwind: bb11];
187-
}
188-
189-
bb9: {
190-
StorageDead(_22);
191-
StorageDead(_21);
192-
StorageDead(_17);
193-
goto -> bb4;
194-
}
195-
196-
bb10: {
19792
unreachable;
19893
}
19994

200-
bb11 (cleanup): {
201-
drop(_2) -> [return: bb12, unwind terminate(cleanup)];
95+
bb9 (cleanup): {
96+
drop(_2) -> [return: bb10, unwind terminate(cleanup)];
20297
}
20398

204-
bb12 (cleanup): {
99+
bb10 (cleanup): {
205100
resume;
206101
}
207102
}

‎tests/mir-opt/pre-codegen/slice_iter.forward_loop.PreCodegen.after.panic-abort.mir‎

Lines changed: 37 additions & 142 deletions
Original file line numberDiff line numberDiff line change
@@ -4,183 +4,78 @@ fn forward_loop(_1: &[T], _2: impl Fn(&T)) -> () {
44
debug slice => _1;
55
debug f => _2;
66
let mut _0: ();
7-
let mut _13: std::slice::Iter<'_, T>;
8-
let mut _14: std::slice::Iter<'_, T>;
9-
let mut _15: &mut std::slice::Iter<'_, T>;
10-
let mut _16: std::option::Option<&T>;
11-
let mut _17: isize;
12-
let mut _19: &impl Fn(&T);
13-
let mut _20: (&T,);
14-
let _21: ();
7+
let mut _3: std::slice::Iter<'_, T>;
8+
let mut _4: std::slice::Iter<'_, T>;
9+
let mut _5: &mut std::slice::Iter<'_, T>;
10+
let mut _6: std::option::Option<&T>;
11+
let mut _7: isize;
12+
let mut _9: &impl Fn(&T);
13+
let mut _10: (&T,);
14+
let _11: ();
1515
scope 1 {
16-
debug iter => _14;
17-
let _18: &T;
16+
debug iter => _4;
17+
let _8: &T;
1818
scope 2 {
19-
debug x => _18;
19+
debug x => _8;
2020
}
2121
}
2222
scope 3 (inlined core::slice::<impl [T]>::iter) {
2323
debug self => _1;
24-
scope 4 (inlined std::slice::Iter::<'_, T>::new) {
25-
debug slice => _1;
26-
let _4: *const T;
27-
let mut _5: bool;
28-
let mut _6: usize;
29-
let mut _8: usize;
30-
let mut _9: *mut T;
31-
let mut _11: std::ptr::NonNull<T>;
32-
let mut _12: *const T;
33-
scope 5 {
34-
debug ptr => _4;
35-
scope 6 {
36-
let _7: *const T;
37-
scope 7 {
38-
debug end_or_len => _7;
39-
scope 13 (inlined NonNull::<T>::new_unchecked) {
40-
debug ptr => _9;
41-
let mut _10: *const T;
42-
let mut _22: *mut T;
43-
scope 14 {
44-
scope 15 (inlined NonNull::<T>::new_unchecked::runtime::<T>) {
45-
debug ptr => _22;
46-
scope 16 (inlined std::ptr::mut_ptr::<impl *mut T>::is_null) {
47-
debug self => _22;
48-
let mut _23: *mut u8;
49-
scope 17 {
50-
scope 18 (inlined std::ptr::mut_ptr::<impl *mut T>::is_null::runtime_impl) {
51-
debug ptr => _23;
52-
scope 19 (inlined std::ptr::mut_ptr::<impl *mut u8>::addr) {
53-
debug self => _23;
54-
scope 20 {
55-
scope 21 (inlined std::ptr::mut_ptr::<impl *mut u8>::cast::<()>) {
56-
debug self => _23;
57-
}
58-
}
59-
}
60-
}
61-
}
62-
}
63-
}
64-
}
65-
}
66-
}
67-
scope 9 (inlined invalid::<T>) {
68-
debug addr => _8;
69-
scope 10 {
70-
}
71-
}
72-
scope 11 (inlined std::ptr::const_ptr::<impl *const T>::add) {
73-
debug self => _4;
74-
debug count => _6;
75-
scope 12 {
76-
}
77-
}
78-
}
79-
}
80-
scope 8 (inlined core::slice::<impl [T]>::as_ptr) {
81-
debug self => _1;
82-
let mut _3: *const [T];
83-
}
84-
}
8524
}
86-
scope 22 (inlined <std::slice::Iter<'_, T> as IntoIterator>::into_iter) {
87-
debug self => _13;
25+
scope 4 (inlined <std::slice::Iter<'_, T> as IntoIterator>::into_iter) {
26+
debug self => _3;
8827
}
8928

9029
bb0: {
91-
StorageLive(_4);
92-
StorageLive(_3);
93-
_3 = &raw const (*_1);
94-
_4 = move _3 as *const T (PtrToPtr);
95-
StorageDead(_3);
96-
StorageLive(_7);
97-
StorageLive(_5);
98-
_5 = const _;
99-
switchInt(move _5) -> [0: bb1, otherwise: bb2];
30+
_3 = std::slice::Iter::<'_, T>::new(move _1) -> [return: bb1, unwind unreachable];
10031
}
10132

10233
bb1: {
103-
StorageLive(_6);
104-
_6 = Len((*_1));
105-
_7 = Offset(_4, _6);
106-
StorageDead(_6);
107-
goto -> bb3;
34+
StorageLive(_4);
35+
_4 = _3;
36+
goto -> bb2;
10837
}
10938

11039
bb2: {
111-
StorageLive(_8);
112-
_8 = Len((*_1));
113-
_7 = _8 as *const T (Transmute);
114-
StorageDead(_8);
115-
goto -> bb3;
40+
StorageLive(_6);
41+
StorageLive(_5);
42+
_5 = &mut _4;
43+
_6 = <std::slice::Iter<'_, T> as Iterator>::next(move _5) -> [return: bb3, unwind unreachable];
11644
}
11745

11846
bb3: {
11947
StorageDead(_5);
120-
StorageLive(_11);
121-
StorageLive(_9);
122-
_9 = _4 as *mut T (PtrToPtr);
123-
StorageLive(_10);
124-
StorageLive(_22);
125-
StorageLive(_23);
126-
_10 = _9 as *const T (PointerCoercion(MutToConstPointer));
127-
_11 = NonNull::<T> { pointer: _10 };
128-
StorageDead(_23);
129-
StorageDead(_22);
130-
StorageDead(_10);
131-
StorageDead(_9);
132-
StorageLive(_12);
133-
_12 = _7;
134-
_13 = std::slice::Iter::<'_, T> { ptr: move _11, end_or_len: move _12, _marker: const ZeroSized: PhantomData<&T> };
135-
StorageDead(_12);
136-
StorageDead(_11);
137-
StorageDead(_7);
138-
StorageDead(_4);
139-
StorageLive(_14);
140-
_14 = _13;
141-
goto -> bb4;
48+
_7 = discriminant(_6);
49+
switchInt(move _7) -> [0: bb4, 1: bb6, otherwise: bb8];
14250
}
14351

14452
bb4: {
145-
StorageLive(_16);
146-
StorageLive(_15);
147-
_15 = &mut _14;
148-
_16 = <std::slice::Iter<'_, T> as Iterator>::next(move _15) -> [return: bb5, unwind unreachable];
53+
StorageDead(_6);
54+
StorageDead(_4);
55+
drop(_2) -> [return: bb5, unwind unreachable];
14956
}
15057

15158
bb5: {
152-
StorageDead(_15);
153-
_17 = discriminant(_16);
154-
switchInt(move _17) -> [0: bb6, 1: bb8, otherwise: bb10];
59+
return;
15560
}
15661

15762
bb6: {
158-
StorageDead(_16);
159-
StorageDead(_14);
160-
drop(_2) -> [return: bb7, unwind unreachable];
63+
_8 = ((_6 as Some).0: &T);
64+
StorageLive(_9);
65+
_9 = &_2;
66+
StorageLive(_10);
67+
_10 = (_8,);
68+
_11 = <impl Fn(&T) as Fn<(&T,)>>::call(move _9, move _10) -> [return: bb7, unwind unreachable];
16169
}
16270

16371
bb7: {
164-
return;
72+
StorageDead(_10);
73+
StorageDead(_9);
74+
StorageDead(_6);
75+
goto -> bb2;
16576
}
16677

16778
bb8: {
168-
_18 = ((_16 as Some).0: &T);
169-
StorageLive(_19);
170-
_19 = &_2;
171-
StorageLive(_20);
172-
_20 = (_18,);
173-
_21 = <impl Fn(&T) as Fn<(&T,)>>::call(move _19, move _20) -> [return: bb9, unwind unreachable];
174-
}
175-
176-
bb9: {
177-
StorageDead(_20);
178-
StorageDead(_19);
179-
StorageDead(_16);
180-
goto -> bb4;
181-
}
182-
183-
bb10: {
18479
unreachable;
18580
}
18681
}

‎tests/mir-opt/pre-codegen/slice_iter.forward_loop.PreCodegen.after.panic-unwind.mir‎

Lines changed: 40 additions & 145 deletions
Original file line numberDiff line numberDiff line change
@@ -4,191 +4,86 @@ fn forward_loop(_1: &[T], _2: impl Fn(&T)) -> () {
44
debug slice => _1;
55
debug f => _2;
66
let mut _0: ();
7-
let mut _13: std::slice::Iter<'_, T>;
8-
let mut _14: std::slice::Iter<'_, T>;
9-
let mut _15: &mut std::slice::Iter<'_, T>;
10-
let mut _16: std::option::Option<&T>;
11-
let mut _17: isize;
12-
let mut _19: &impl Fn(&T);
13-
let mut _20: (&T,);
14-
let _21: ();
7+
let mut _3: std::slice::Iter<'_, T>;
8+
let mut _4: std::slice::Iter<'_, T>;
9+
let mut _5: &mut std::slice::Iter<'_, T>;
10+
let mut _6: std::option::Option<&T>;
11+
let mut _7: isize;
12+
let mut _9: &impl Fn(&T);
13+
let mut _10: (&T,);
14+
let _11: ();
1515
scope 1 {
16-
debug iter => _14;
17-
let _18: &T;
16+
debug iter => _4;
17+
let _8: &T;
1818
scope 2 {
19-
debug x => _18;
19+
debug x => _8;
2020
}
2121
}
2222
scope 3 (inlined core::slice::<impl [T]>::iter) {
2323
debug self => _1;
24-
scope 4 (inlined std::slice::Iter::<'_, T>::new) {
25-
debug slice => _1;
26-
let _4: *const T;
27-
let mut _5: bool;
28-
let mut _6: usize;
29-
let mut _8: usize;
30-
let mut _9: *mut T;
31-
let mut _11: std::ptr::NonNull<T>;
32-
let mut _12: *const T;
33-
scope 5 {
34-
debug ptr => _4;
35-
scope 6 {
36-
let _7: *const T;
37-
scope 7 {
38-
debug end_or_len => _7;
39-
scope 13 (inlined NonNull::<T>::new_unchecked) {
40-
debug ptr => _9;
41-
let mut _10: *const T;
42-
let mut _22: *mut T;
43-
scope 14 {
44-
scope 15 (inlined NonNull::<T>::new_unchecked::runtime::<T>) {
45-
debug ptr => _22;
46-
scope 16 (inlined std::ptr::mut_ptr::<impl *mut T>::is_null) {
47-
debug self => _22;
48-
let mut _23: *mut u8;
49-
scope 17 {
50-
scope 18 (inlined std::ptr::mut_ptr::<impl *mut T>::is_null::runtime_impl) {
51-
debug ptr => _23;
52-
scope 19 (inlined std::ptr::mut_ptr::<impl *mut u8>::addr) {
53-
debug self => _23;
54-
scope 20 {
55-
scope 21 (inlined std::ptr::mut_ptr::<impl *mut u8>::cast::<()>) {
56-
debug self => _23;
57-
}
58-
}
59-
}
60-
}
61-
}
62-
}
63-
}
64-
}
65-
}
66-
}
67-
scope 9 (inlined invalid::<T>) {
68-
debug addr => _8;
69-
scope 10 {
70-
}
71-
}
72-
scope 11 (inlined std::ptr::const_ptr::<impl *const T>::add) {
73-
debug self => _4;
74-
debug count => _6;
75-
scope 12 {
76-
}
77-
}
78-
}
79-
}
80-
scope 8 (inlined core::slice::<impl [T]>::as_ptr) {
81-
debug self => _1;
82-
let mut _3: *const [T];
83-
}
84-
}
8524
}
86-
scope 22 (inlined <std::slice::Iter<'_, T> as IntoIterator>::into_iter) {
87-
debug self => _13;
25+
scope 4 (inlined <std::slice::Iter<'_, T> as IntoIterator>::into_iter) {
26+
debug self => _3;
8827
}
8928

9029
bb0: {
91-
StorageLive(_4);
92-
StorageLive(_3);
93-
_3 = &raw const (*_1);
94-
_4 = move _3 as *const T (PtrToPtr);
95-
StorageDead(_3);
96-
StorageLive(_7);
97-
StorageLive(_5);
98-
_5 = const _;
99-
switchInt(move _5) -> [0: bb1, otherwise: bb2];
30+
_3 = std::slice::Iter::<'_, T>::new(move _1) -> [return: bb1, unwind: bb9];
10031
}
10132

10233
bb1: {
103-
StorageLive(_6);
104-
_6 = Len((*_1));
105-
_7 = Offset(_4, _6);
106-
StorageDead(_6);
107-
goto -> bb3;
34+
StorageLive(_4);
35+
_4 = _3;
36+
goto -> bb2;
10837
}
10938

11039
bb2: {
111-
StorageLive(_8);
112-
_8 = Len((*_1));
113-
_7 = _8 as *const T (Transmute);
114-
StorageDead(_8);
115-
goto -> bb3;
40+
StorageLive(_6);
41+
StorageLive(_5);
42+
_5 = &mut _4;
43+
_6 = <std::slice::Iter<'_, T> as Iterator>::next(move _5) -> [return: bb3, unwind: bb9];
11644
}
11745

11846
bb3: {
11947
StorageDead(_5);
120-
StorageLive(_11);
121-
StorageLive(_9);
122-
_9 = _4 as *mut T (PtrToPtr);
123-
StorageLive(_10);
124-
StorageLive(_22);
125-
StorageLive(_23);
126-
_10 = _9 as *const T (PointerCoercion(MutToConstPointer));
127-
_11 = NonNull::<T> { pointer: _10 };
128-
StorageDead(_23);
129-
StorageDead(_22);
130-
StorageDead(_10);
131-
StorageDead(_9);
132-
StorageLive(_12);
133-
_12 = _7;
134-
_13 = std::slice::Iter::<'_, T> { ptr: move _11, end_or_len: move _12, _marker: const ZeroSized: PhantomData<&T> };
135-
StorageDead(_12);
136-
StorageDead(_11);
137-
StorageDead(_7);
138-
StorageDead(_4);
139-
StorageLive(_14);
140-
_14 = _13;
141-
goto -> bb4;
48+
_7 = discriminant(_6);
49+
switchInt(move _7) -> [0: bb4, 1: bb6, otherwise: bb8];
14250
}
14351

14452
bb4: {
145-
StorageLive(_16);
146-
StorageLive(_15);
147-
_15 = &mut _14;
148-
_16 = <std::slice::Iter<'_, T> as Iterator>::next(move _15) -> [return: bb5, unwind: bb11];
53+
StorageDead(_6);
54+
StorageDead(_4);
55+
drop(_2) -> [return: bb5, unwind continue];
14956
}
15057

15158
bb5: {
152-
StorageDead(_15);
153-
_17 = discriminant(_16);
154-
switchInt(move _17) -> [0: bb6, 1: bb8, otherwise: bb10];
59+
return;
15560
}
15661

15762
bb6: {
158-
StorageDead(_16);
159-
StorageDead(_14);
160-
drop(_2) -> [return: bb7, unwind continue];
63+
_8 = ((_6 as Some).0: &T);
64+
StorageLive(_9);
65+
_9 = &_2;
66+
StorageLive(_10);
67+
_10 = (_8,);
68+
_11 = <impl Fn(&T) as Fn<(&T,)>>::call(move _9, move _10) -> [return: bb7, unwind: bb9];
16169
}
16270

16371
bb7: {
164-
return;
72+
StorageDead(_10);
73+
StorageDead(_9);
74+
StorageDead(_6);
75+
goto -> bb2;
16576
}
16677

16778
bb8: {
168-
_18 = ((_16 as Some).0: &T);
169-
StorageLive(_19);
170-
_19 = &_2;
171-
StorageLive(_20);
172-
_20 = (_18,);
173-
_21 = <impl Fn(&T) as Fn<(&T,)>>::call(move _19, move _20) -> [return: bb9, unwind: bb11];
174-
}
175-
176-
bb9: {
177-
StorageDead(_20);
178-
StorageDead(_19);
179-
StorageDead(_16);
180-
goto -> bb4;
181-
}
182-
183-
bb10: {
18479
unreachable;
18580
}
18681

187-
bb11 (cleanup): {
188-
drop(_2) -> [return: bb12, unwind terminate(cleanup)];
82+
bb9 (cleanup): {
83+
drop(_2) -> [return: bb10, unwind terminate(cleanup)];
18984
}
19085

191-
bb12 (cleanup): {
86+
bb10 (cleanup): {
19287
resume;
19388
}
19489
}

‎tests/mir-opt/pre-codegen/slice_iter.reverse_loop.PreCodegen.after.panic-abort.mir‎

Lines changed: 47 additions & 152 deletions
Original file line numberDiff line numberDiff line change
@@ -4,198 +4,93 @@ fn reverse_loop(_1: &[T], _2: impl Fn(&T)) -> () {
44
debug slice => _1;
55
debug f => _2;
66
let mut _0: ();
7-
let mut _13: std::slice::Iter<'_, T>;
8-
let mut _14: std::iter::Rev<std::slice::Iter<'_, T>>;
9-
let mut _15: std::iter::Rev<std::slice::Iter<'_, T>>;
10-
let mut _16: &mut std::iter::Rev<std::slice::Iter<'_, T>>;
11-
let mut _18: std::option::Option<&T>;
12-
let mut _19: isize;
13-
let mut _21: &impl Fn(&T);
14-
let mut _22: (&T,);
15-
let _23: ();
7+
let mut _3: std::slice::Iter<'_, T>;
8+
let mut _4: std::iter::Rev<std::slice::Iter<'_, T>>;
9+
let mut _5: std::iter::Rev<std::slice::Iter<'_, T>>;
10+
let mut _6: &mut std::iter::Rev<std::slice::Iter<'_, T>>;
11+
let mut _8: std::option::Option<&T>;
12+
let mut _9: isize;
13+
let mut _11: &impl Fn(&T);
14+
let mut _12: (&T,);
15+
let _13: ();
1616
scope 1 {
17-
debug iter => _15;
18-
let _20: &T;
17+
debug iter => _5;
18+
let _10: &T;
1919
scope 2 {
20-
debug x => _20;
20+
debug x => _10;
2121
}
22-
scope 25 (inlined <Rev<std::slice::Iter<'_, T>> as Iterator>::next) {
23-
debug self => _16;
24-
let mut _17: &mut std::slice::Iter<'_, T>;
22+
scope 7 (inlined <Rev<std::slice::Iter<'_, T>> as Iterator>::next) {
23+
debug self => _6;
24+
let mut _7: &mut std::slice::Iter<'_, T>;
2525
}
2626
}
2727
scope 3 (inlined core::slice::<impl [T]>::iter) {
2828
debug self => _1;
29-
scope 4 (inlined std::slice::Iter::<'_, T>::new) {
30-
debug slice => _1;
31-
let _4: *const T;
32-
let mut _5: bool;
33-
let mut _6: usize;
34-
let mut _8: usize;
35-
let mut _9: *mut T;
36-
let mut _11: std::ptr::NonNull<T>;
37-
let mut _12: *const T;
38-
scope 5 {
39-
debug ptr => _4;
40-
scope 6 {
41-
let _7: *const T;
42-
scope 7 {
43-
debug end_or_len => _7;
44-
scope 13 (inlined NonNull::<T>::new_unchecked) {
45-
debug ptr => _9;
46-
let mut _10: *const T;
47-
let mut _24: *mut T;
48-
scope 14 {
49-
scope 15 (inlined NonNull::<T>::new_unchecked::runtime::<T>) {
50-
debug ptr => _24;
51-
scope 16 (inlined std::ptr::mut_ptr::<impl *mut T>::is_null) {
52-
debug self => _24;
53-
let mut _25: *mut u8;
54-
scope 17 {
55-
scope 18 (inlined std::ptr::mut_ptr::<impl *mut T>::is_null::runtime_impl) {
56-
debug ptr => _25;
57-
scope 19 (inlined std::ptr::mut_ptr::<impl *mut u8>::addr) {
58-
debug self => _25;
59-
scope 20 {
60-
scope 21 (inlined std::ptr::mut_ptr::<impl *mut u8>::cast::<()>) {
61-
debug self => _25;
62-
}
63-
}
64-
}
65-
}
66-
}
67-
}
68-
}
69-
}
70-
}
71-
}
72-
scope 9 (inlined invalid::<T>) {
73-
debug addr => _8;
74-
scope 10 {
75-
}
76-
}
77-
scope 11 (inlined std::ptr::const_ptr::<impl *const T>::add) {
78-
debug self => _4;
79-
debug count => _6;
80-
scope 12 {
81-
}
82-
}
83-
}
84-
}
85-
scope 8 (inlined core::slice::<impl [T]>::as_ptr) {
86-
debug self => _1;
87-
let mut _3: *const [T];
88-
}
89-
}
9029
}
91-
scope 22 (inlined <std::slice::Iter<'_, T> as Iterator>::rev) {
92-
debug self => _13;
93-
scope 23 (inlined Rev::<std::slice::Iter<'_, T>>::new) {
94-
debug iter => _13;
30+
scope 4 (inlined <std::slice::Iter<'_, T> as Iterator>::rev) {
31+
debug self => _3;
32+
scope 5 (inlined Rev::<std::slice::Iter<'_, T>>::new) {
33+
debug iter => _3;
9534
}
9635
}
97-
scope 24 (inlined <Rev<std::slice::Iter<'_, T>> as IntoIterator>::into_iter) {
98-
debug self => _14;
36+
scope 6 (inlined <Rev<std::slice::Iter<'_, T>> as IntoIterator>::into_iter) {
37+
debug self => _4;
9938
}
10039

10140
bb0: {
102-
StorageLive(_13);
103-
StorageLive(_4);
10441
StorageLive(_3);
105-
_3 = &raw const (*_1);
106-
_4 = move _3 as *const T (PtrToPtr);
107-
StorageDead(_3);
108-
StorageLive(_7);
109-
StorageLive(_5);
110-
_5 = const _;
111-
switchInt(move _5) -> [0: bb1, otherwise: bb2];
42+
_3 = std::slice::Iter::<'_, T>::new(move _1) -> [return: bb1, unwind unreachable];
11243
}
11344

11445
bb1: {
115-
StorageLive(_6);
116-
_6 = Len((*_1));
117-
_7 = Offset(_4, _6);
118-
StorageDead(_6);
119-
goto -> bb3;
46+
_4 = Rev::<std::slice::Iter<'_, T>> { iter: _3 };
47+
StorageDead(_3);
48+
StorageLive(_5);
49+
_5 = _4;
50+
goto -> bb2;
12051
}
12152

12253
bb2: {
12354
StorageLive(_8);
124-
_8 = Len((*_1));
125-
_7 = _8 as *const T (Transmute);
126-
StorageDead(_8);
127-
goto -> bb3;
55+
_6 = &mut _5;
56+
StorageLive(_7);
57+
_7 = &mut (_5.0: std::slice::Iter<'_, T>);
58+
_8 = <std::slice::Iter<'_, T> as DoubleEndedIterator>::next_back(move _7) -> [return: bb3, unwind unreachable];
12859
}
12960

13061
bb3: {
131-
StorageDead(_5);
132-
StorageLive(_11);
133-
StorageLive(_9);
134-
_9 = _4 as *mut T (PtrToPtr);
135-
StorageLive(_10);
136-
StorageLive(_24);
137-
StorageLive(_25);
138-
_10 = _9 as *const T (PointerCoercion(MutToConstPointer));
139-
_11 = NonNull::<T> { pointer: _10 };
140-
StorageDead(_25);
141-
StorageDead(_24);
142-
StorageDead(_10);
143-
StorageDead(_9);
144-
StorageLive(_12);
145-
_12 = _7;
146-
_13 = std::slice::Iter::<'_, T> { ptr: move _11, end_or_len: move _12, _marker: const ZeroSized: PhantomData<&T> };
147-
StorageDead(_12);
148-
StorageDead(_11);
14962
StorageDead(_7);
150-
StorageDead(_4);
151-
_14 = Rev::<std::slice::Iter<'_, T>> { iter: _13 };
152-
StorageDead(_13);
153-
StorageLive(_15);
154-
_15 = _14;
155-
goto -> bb4;
63+
_9 = discriminant(_8);
64+
switchInt(move _9) -> [0: bb4, 1: bb6, otherwise: bb8];
15665
}
15766

15867
bb4: {
159-
StorageLive(_18);
160-
_16 = &mut _15;
161-
StorageLive(_17);
162-
_17 = &mut (_15.0: std::slice::Iter<'_, T>);
163-
_18 = <std::slice::Iter<'_, T> as DoubleEndedIterator>::next_back(move _17) -> [return: bb5, unwind unreachable];
68+
StorageDead(_8);
69+
StorageDead(_5);
70+
drop(_2) -> [return: bb5, unwind unreachable];
16471
}
16572

16673
bb5: {
167-
StorageDead(_17);
168-
_19 = discriminant(_18);
169-
switchInt(move _19) -> [0: bb6, 1: bb8, otherwise: bb10];
74+
return;
17075
}
17176

17277
bb6: {
173-
StorageDead(_18);
174-
StorageDead(_15);
175-
drop(_2) -> [return: bb7, unwind unreachable];
78+
_10 = ((_8 as Some).0: &T);
79+
StorageLive(_11);
80+
_11 = &_2;
81+
StorageLive(_12);
82+
_12 = (_10,);
83+
_13 = <impl Fn(&T) as Fn<(&T,)>>::call(move _11, move _12) -> [return: bb7, unwind unreachable];
17684
}
17785

17886
bb7: {
179-
return;
87+
StorageDead(_12);
88+
StorageDead(_11);
89+
StorageDead(_8);
90+
goto -> bb2;
18091
}
18192

18293
bb8: {
183-
_20 = ((_18 as Some).0: &T);
184-
StorageLive(_21);
185-
_21 = &_2;
186-
StorageLive(_22);
187-
_22 = (_20,);
188-
_23 = <impl Fn(&T) as Fn<(&T,)>>::call(move _21, move _22) -> [return: bb9, unwind unreachable];
189-
}
190-
191-
bb9: {
192-
StorageDead(_22);
193-
StorageDead(_21);
194-
StorageDead(_18);
195-
goto -> bb4;
196-
}
197-
198-
bb10: {
19994
unreachable;
20095
}
20196
}

‎tests/mir-opt/pre-codegen/slice_iter.reverse_loop.PreCodegen.after.panic-unwind.mir‎

Lines changed: 50 additions & 155 deletions
Original file line numberDiff line numberDiff line change
@@ -4,206 +4,101 @@ fn reverse_loop(_1: &[T], _2: impl Fn(&T)) -> () {
44
debug slice => _1;
55
debug f => _2;
66
let mut _0: ();
7-
let mut _13: std::slice::Iter<'_, T>;
8-
let mut _14: std::iter::Rev<std::slice::Iter<'_, T>>;
9-
let mut _15: std::iter::Rev<std::slice::Iter<'_, T>>;
10-
let mut _16: &mut std::iter::Rev<std::slice::Iter<'_, T>>;
11-
let mut _18: std::option::Option<&T>;
12-
let mut _19: isize;
13-
let mut _21: &impl Fn(&T);
14-
let mut _22: (&T,);
15-
let _23: ();
7+
let mut _3: std::slice::Iter<'_, T>;
8+
let mut _4: std::iter::Rev<std::slice::Iter<'_, T>>;
9+
let mut _5: std::iter::Rev<std::slice::Iter<'_, T>>;
10+
let mut _6: &mut std::iter::Rev<std::slice::Iter<'_, T>>;
11+
let mut _8: std::option::Option<&T>;
12+
let mut _9: isize;
13+
let mut _11: &impl Fn(&T);
14+
let mut _12: (&T,);
15+
let _13: ();
1616
scope 1 {
17-
debug iter => _15;
18-
let _20: &T;
17+
debug iter => _5;
18+
let _10: &T;
1919
scope 2 {
20-
debug x => _20;
20+
debug x => _10;
2121
}
22-
scope 25 (inlined <Rev<std::slice::Iter<'_, T>> as Iterator>::next) {
23-
debug self => _16;
24-
let mut _17: &mut std::slice::Iter<'_, T>;
22+
scope 7 (inlined <Rev<std::slice::Iter<'_, T>> as Iterator>::next) {
23+
debug self => _6;
24+
let mut _7: &mut std::slice::Iter<'_, T>;
2525
}
2626
}
2727
scope 3 (inlined core::slice::<impl [T]>::iter) {
2828
debug self => _1;
29-
scope 4 (inlined std::slice::Iter::<'_, T>::new) {
30-
debug slice => _1;
31-
let _4: *const T;
32-
let mut _5: bool;
33-
let mut _6: usize;
34-
let mut _8: usize;
35-
let mut _9: *mut T;
36-
let mut _11: std::ptr::NonNull<T>;
37-
let mut _12: *const T;
38-
scope 5 {
39-
debug ptr => _4;
40-
scope 6 {
41-
let _7: *const T;
42-
scope 7 {
43-
debug end_or_len => _7;
44-
scope 13 (inlined NonNull::<T>::new_unchecked) {
45-
debug ptr => _9;
46-
let mut _10: *const T;
47-
let mut _24: *mut T;
48-
scope 14 {
49-
scope 15 (inlined NonNull::<T>::new_unchecked::runtime::<T>) {
50-
debug ptr => _24;
51-
scope 16 (inlined std::ptr::mut_ptr::<impl *mut T>::is_null) {
52-
debug self => _24;
53-
let mut _25: *mut u8;
54-
scope 17 {
55-
scope 18 (inlined std::ptr::mut_ptr::<impl *mut T>::is_null::runtime_impl) {
56-
debug ptr => _25;
57-
scope 19 (inlined std::ptr::mut_ptr::<impl *mut u8>::addr) {
58-
debug self => _25;
59-
scope 20 {
60-
scope 21 (inlined std::ptr::mut_ptr::<impl *mut u8>::cast::<()>) {
61-
debug self => _25;
62-
}
63-
}
64-
}
65-
}
66-
}
67-
}
68-
}
69-
}
70-
}
71-
}
72-
scope 9 (inlined invalid::<T>) {
73-
debug addr => _8;
74-
scope 10 {
75-
}
76-
}
77-
scope 11 (inlined std::ptr::const_ptr::<impl *const T>::add) {
78-
debug self => _4;
79-
debug count => _6;
80-
scope 12 {
81-
}
82-
}
83-
}
84-
}
85-
scope 8 (inlined core::slice::<impl [T]>::as_ptr) {
86-
debug self => _1;
87-
let mut _3: *const [T];
88-
}
89-
}
9029
}
91-
scope 22 (inlined <std::slice::Iter<'_, T> as Iterator>::rev) {
92-
debug self => _13;
93-
scope 23 (inlined Rev::<std::slice::Iter<'_, T>>::new) {
94-
debug iter => _13;
30+
scope 4 (inlined <std::slice::Iter<'_, T> as Iterator>::rev) {
31+
debug self => _3;
32+
scope 5 (inlined Rev::<std::slice::Iter<'_, T>>::new) {
33+
debug iter => _3;
9534
}
9635
}
97-
scope 24 (inlined <Rev<std::slice::Iter<'_, T>> as IntoIterator>::into_iter) {
98-
debug self => _14;
36+
scope 6 (inlined <Rev<std::slice::Iter<'_, T>> as IntoIterator>::into_iter) {
37+
debug self => _4;
9938
}
10039

10140
bb0: {
102-
StorageLive(_13);
103-
StorageLive(_4);
10441
StorageLive(_3);
105-
_3 = &raw const (*_1);
106-
_4 = move _3 as *const T (PtrToPtr);
107-
StorageDead(_3);
108-
StorageLive(_7);
109-
StorageLive(_5);
110-
_5 = const _;
111-
switchInt(move _5) -> [0: bb1, otherwise: bb2];
42+
_3 = std::slice::Iter::<'_, T>::new(move _1) -> [return: bb1, unwind: bb9];
11243
}
11344

11445
bb1: {
115-
StorageLive(_6);
116-
_6 = Len((*_1));
117-
_7 = Offset(_4, _6);
118-
StorageDead(_6);
119-
goto -> bb3;
46+
_4 = Rev::<std::slice::Iter<'_, T>> { iter: _3 };
47+
StorageDead(_3);
48+
StorageLive(_5);
49+
_5 = _4;
50+
goto -> bb2;
12051
}
12152

12253
bb2: {
12354
StorageLive(_8);
124-
_8 = Len((*_1));
125-
_7 = _8 as *const T (Transmute);
126-
StorageDead(_8);
127-
goto -> bb3;
55+
_6 = &mut _5;
56+
StorageLive(_7);
57+
_7 = &mut (_5.0: std::slice::Iter<'_, T>);
58+
_8 = <std::slice::Iter<'_, T> as DoubleEndedIterator>::next_back(move _7) -> [return: bb3, unwind: bb9];
12859
}
12960

13061
bb3: {
131-
StorageDead(_5);
132-
StorageLive(_11);
133-
StorageLive(_9);
134-
_9 = _4 as *mut T (PtrToPtr);
135-
StorageLive(_10);
136-
StorageLive(_24);
137-
StorageLive(_25);
138-
_10 = _9 as *const T (PointerCoercion(MutToConstPointer));
139-
_11 = NonNull::<T> { pointer: _10 };
140-
StorageDead(_25);
141-
StorageDead(_24);
142-
StorageDead(_10);
143-
StorageDead(_9);
144-
StorageLive(_12);
145-
_12 = _7;
146-
_13 = std::slice::Iter::<'_, T> { ptr: move _11, end_or_len: move _12, _marker: const ZeroSized: PhantomData<&T> };
147-
StorageDead(_12);
148-
StorageDead(_11);
14962
StorageDead(_7);
150-
StorageDead(_4);
151-
_14 = Rev::<std::slice::Iter<'_, T>> { iter: _13 };
152-
StorageDead(_13);
153-
StorageLive(_15);
154-
_15 = _14;
155-
goto -> bb4;
63+
_9 = discriminant(_8);
64+
switchInt(move _9) -> [0: bb4, 1: bb6, otherwise: bb8];
15665
}
15766

15867
bb4: {
159-
StorageLive(_18);
160-
_16 = &mut _15;
161-
StorageLive(_17);
162-
_17 = &mut (_15.0: std::slice::Iter<'_, T>);
163-
_18 = <std::slice::Iter<'_, T> as DoubleEndedIterator>::next_back(move _17) -> [return: bb5, unwind: bb11];
68+
StorageDead(_8);
69+
StorageDead(_5);
70+
drop(_2) -> [return: bb5, unwind continue];
16471
}
16572

16673
bb5: {
167-
StorageDead(_17);
168-
_19 = discriminant(_18);
169-
switchInt(move _19) -> [0: bb6, 1: bb8, otherwise: bb10];
74+
return;
17075
}
17176

17277
bb6: {
173-
StorageDead(_18);
174-
StorageDead(_15);
175-
drop(_2) -> [return: bb7, unwind continue];
78+
_10 = ((_8 as Some).0: &T);
79+
StorageLive(_11);
80+
_11 = &_2;
81+
StorageLive(_12);
82+
_12 = (_10,);
83+
_13 = <impl Fn(&T) as Fn<(&T,)>>::call(move _11, move _12) -> [return: bb7, unwind: bb9];
17684
}
17785

17886
bb7: {
179-
return;
87+
StorageDead(_12);
88+
StorageDead(_11);
89+
StorageDead(_8);
90+
goto -> bb2;
18091
}
18192

18293
bb8: {
183-
_20 = ((_18 as Some).0: &T);
184-
StorageLive(_21);
185-
_21 = &_2;
186-
StorageLive(_22);
187-
_22 = (_20,);
188-
_23 = <impl Fn(&T) as Fn<(&T,)>>::call(move _21, move _22) -> [return: bb9, unwind: bb11];
189-
}
190-
191-
bb9: {
192-
StorageDead(_22);
193-
StorageDead(_21);
194-
StorageDead(_18);
195-
goto -> bb4;
196-
}
197-
198-
bb10: {
19994
unreachable;
20095
}
20196

202-
bb11 (cleanup): {
203-
drop(_2) -> [return: bb12, unwind terminate(cleanup)];
97+
bb9 (cleanup): {
98+
drop(_2) -> [return: bb10, unwind terminate(cleanup)];
20499
}
205100

206-
bb12 (cleanup): {
101+
bb10 (cleanup): {
207102
resume;
208103
}
209104
}

0 commit comments

Comments
 (0)
This repository has been archived.