diff --git a/compiler/rustc_mir_transform/src/dead_store_elimination.rs b/compiler/rustc_mir_transform/src/dead_store_elimination.rs index f473073083af4..71feca0c5d730 100644 --- a/compiler/rustc_mir_transform/src/dead_store_elimination.rs +++ b/compiler/rustc_mir_transform/src/dead_store_elimination.rs @@ -13,7 +13,7 @@ //! use rustc_middle::bug; -use rustc_middle::mir::visit::Visitor; +use rustc_middle::mir::visit::*; use rustc_middle::mir::*; use rustc_middle::ty::TyCtxt; use rustc_mir_dataflow::debuginfo::debuginfo_locals; @@ -21,6 +21,7 @@ use rustc_mir_dataflow::impls::{ borrowed_locals, LivenessTransferFunction, MaybeTransitiveLiveLocals, }; use rustc_mir_dataflow::Analysis; +use rustc_session::config::DebugInfo; use crate::util::is_within_packed; @@ -31,10 +32,15 @@ use crate::util::is_within_packed; pub fn eliminate<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { let borrowed_locals = borrowed_locals(body); - // If the user requests complete debuginfo, mark the locals that appear in it as live, so - // we don't remove assignements to them. - let mut always_live = debuginfo_locals(body); - always_live.union(&borrowed_locals); + let always_live = if tcx.sess.opts.debuginfo == DebugInfo::Full { + // If the user requests complete debuginfo, mark the locals that appear in it as live, so + // we don't remove assignements to them. + let mut always_live = debuginfo_locals(body); + always_live.union(&borrowed_locals); + always_live + } else { + borrowed_locals.clone() + }; let mut live = MaybeTransitiveLiveLocals::new(&always_live) .into_engine(tcx, body) @@ -89,7 +95,7 @@ pub fn eliminate<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { if !place.is_indirect() && !always_live.contains(place.local) { live.seek_before_primary_effect(loc); if !live.get().contains(place.local) { - patch.push(loc); + patch.push((place.local, loc)); } } } @@ -114,8 +120,31 @@ pub fn eliminate<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { } let bbs = body.basic_blocks.as_mut_preserves_cfg(); - for Location { block, statement_index } in patch { + for (local, Location { block, statement_index }) in patch { bbs[block].statements[statement_index].make_nop(); + if bbs[block].statements.iter().all(|stmt| match stmt.kind { + StatementKind::Assign(box (place, _)) + | StatementKind::SetDiscriminant { place: box place, .. } + | StatementKind::Deinit(box place) => place.local != local, + _ => true, + }) { + if let Some(storage_live_index) = bbs[block] + .statements + .iter() + .take(statement_index) + .position(|stmt| stmt.kind == StatementKind::StorageLive(local)) + { + if let Some(storage_dead_index) = bbs[block] + .statements + .iter() + .skip(statement_index) + .position(|stmt| stmt.kind == StatementKind::StorageDead(local)) + { + bbs[block].statements[storage_live_index].make_nop(); + bbs[block].statements[storage_dead_index + statement_index].make_nop(); + } + } + } } for (block, argument_index) in call_operands_to_move { let TerminatorKind::Call { ref mut args, .. } = bbs[block].terminator_mut().kind else { diff --git a/tests/mir-opt/issue_101973.inner.GVN.panic-abort.diff b/tests/mir-opt/issue_101973.inner.GVN.panic-abort.diff index ac88fe67bb86f..3ea7387a48d3c 100644 --- a/tests/mir-opt/issue_101973.inner.GVN.panic-abort.diff +++ b/tests/mir-opt/issue_101973.inner.GVN.panic-abort.diff @@ -30,7 +30,6 @@ StorageLive(_4); StorageLive(_5); _5 = copy _1; - nop; - StorageLive(_14); - _14 = BitAnd(copy _5, const 255_u32); - _4 = BitOr(const 0_u32, move _14); diff --git a/tests/mir-opt/issue_101973.inner.GVN.panic-unwind.diff b/tests/mir-opt/issue_101973.inner.GVN.panic-unwind.diff index 96c3cae2d334a..832db856b2cf9 100644 --- a/tests/mir-opt/issue_101973.inner.GVN.panic-unwind.diff +++ b/tests/mir-opt/issue_101973.inner.GVN.panic-unwind.diff @@ -30,7 +30,6 @@ StorageLive(_4); StorageLive(_5); _5 = copy _1; - nop; - StorageLive(_14); - _14 = BitAnd(copy _5, const 255_u32); - _4 = BitOr(const 0_u32, move _14); diff --git a/tests/mir-opt/issue_76432.test.SimplifyComparisonIntegral.panic-abort.diff b/tests/mir-opt/issue_76432.test.SimplifyComparisonIntegral.panic-abort.diff index f03691ad67316..59e0a99d1d0d1 100644 --- a/tests/mir-opt/issue_76432.test.SimplifyComparisonIntegral.panic-abort.diff +++ b/tests/mir-opt/issue_76432.test.SimplifyComparisonIntegral.panic-abort.diff @@ -37,15 +37,6 @@ } bb2: { - StorageLive(_7); - _7 = &(*_2)[0 of 3]; - StorageLive(_8); - _8 = &(*_2)[1 of 3]; - StorageLive(_9); - _9 = &(*_2)[2 of 3]; - StorageDead(_9); - StorageDead(_8); - StorageDead(_7); StorageDead(_4); return; } diff --git a/tests/mir-opt/issue_76432.test.SimplifyComparisonIntegral.panic-unwind.diff b/tests/mir-opt/issue_76432.test.SimplifyComparisonIntegral.panic-unwind.diff index 633e5c740a1a8..ba486cb201228 100644 --- a/tests/mir-opt/issue_76432.test.SimplifyComparisonIntegral.panic-unwind.diff +++ b/tests/mir-opt/issue_76432.test.SimplifyComparisonIntegral.panic-unwind.diff @@ -37,15 +37,6 @@ } bb2: { - StorageLive(_7); - _7 = &(*_2)[0 of 3]; - StorageLive(_8); - _8 = &(*_2)[1 of 3]; - StorageLive(_9); - _9 = &(*_2)[2 of 3]; - StorageDead(_9); - StorageDead(_8); - StorageDead(_7); StorageDead(_4); return; } diff --git a/tests/mir-opt/pre-codegen/issue_117368_print_invalid_constant.main.GVN.32bit.panic-abort.diff b/tests/mir-opt/pre-codegen/issue_117368_print_invalid_constant.main.GVN.32bit.panic-abort.diff index 6cac8b109eea6..b680af4142169 100644 --- a/tests/mir-opt/pre-codegen/issue_117368_print_invalid_constant.main.GVN.32bit.panic-abort.diff +++ b/tests/mir-opt/pre-codegen/issue_117368_print_invalid_constant.main.GVN.32bit.panic-abort.diff @@ -98,20 +98,16 @@ } bb6: { - _5 = move ((_6 as Ok).0: std::ptr::NonNull<[u8]>); + nop; StorageDead(_16); StorageDead(_12); StorageDead(_6); -- StorageLive(_17); -+ nop; - _17 = copy (_5.0: *const [u8]); -- _4 = move _17 as *mut [u8] (PtrToPtr); -- StorageDead(_17); -+ _4 = copy _17 as *mut [u8] (PtrToPtr); -+ nop; + nop; + nop; + nop; + nop; StorageDead(_5); -- _3 = move _4 as *mut u8 (PtrToPtr); -+ _3 = copy _17 as *mut u8 (PtrToPtr); + nop; StorageDead(_4); StorageDead(_3); - StorageDead(_1); diff --git a/tests/mir-opt/pre-codegen/issue_117368_print_invalid_constant.main.GVN.32bit.panic-unwind.diff b/tests/mir-opt/pre-codegen/issue_117368_print_invalid_constant.main.GVN.32bit.panic-unwind.diff index 5fcece2280d48..6884c5041a16f 100644 --- a/tests/mir-opt/pre-codegen/issue_117368_print_invalid_constant.main.GVN.32bit.panic-unwind.diff +++ b/tests/mir-opt/pre-codegen/issue_117368_print_invalid_constant.main.GVN.32bit.panic-unwind.diff @@ -45,16 +45,12 @@ bb1: { StorageDead(_6); -- StorageLive(_12); -+ nop; - _12 = copy (_5.0: *const [u8]); -- _4 = move _12 as *mut [u8] (PtrToPtr); -- StorageDead(_12); -+ _4 = copy _12 as *mut [u8] (PtrToPtr); -+ nop; + nop; + nop; + nop; + nop; StorageDead(_5); -- _3 = move _4 as *mut u8 (PtrToPtr); -+ _3 = copy _12 as *mut u8 (PtrToPtr); + nop; StorageDead(_4); StorageDead(_3); - StorageDead(_1); diff --git a/tests/mir-opt/pre-codegen/issue_117368_print_invalid_constant.main.GVN.64bit.panic-abort.diff b/tests/mir-opt/pre-codegen/issue_117368_print_invalid_constant.main.GVN.64bit.panic-abort.diff index 10fde25e3178b..d6b76faf52c2d 100644 --- a/tests/mir-opt/pre-codegen/issue_117368_print_invalid_constant.main.GVN.64bit.panic-abort.diff +++ b/tests/mir-opt/pre-codegen/issue_117368_print_invalid_constant.main.GVN.64bit.panic-abort.diff @@ -98,20 +98,16 @@ } bb6: { - _5 = move ((_6 as Ok).0: std::ptr::NonNull<[u8]>); + nop; StorageDead(_16); StorageDead(_12); StorageDead(_6); -- StorageLive(_17); -+ nop; - _17 = copy (_5.0: *const [u8]); -- _4 = move _17 as *mut [u8] (PtrToPtr); -- StorageDead(_17); -+ _4 = copy _17 as *mut [u8] (PtrToPtr); -+ nop; + nop; + nop; + nop; + nop; StorageDead(_5); -- _3 = move _4 as *mut u8 (PtrToPtr); -+ _3 = copy _17 as *mut u8 (PtrToPtr); + nop; StorageDead(_4); StorageDead(_3); - StorageDead(_1); diff --git a/tests/mir-opt/pre-codegen/issue_117368_print_invalid_constant.main.GVN.64bit.panic-unwind.diff b/tests/mir-opt/pre-codegen/issue_117368_print_invalid_constant.main.GVN.64bit.panic-unwind.diff index 0821ea272bf50..911bebaf2129b 100644 --- a/tests/mir-opt/pre-codegen/issue_117368_print_invalid_constant.main.GVN.64bit.panic-unwind.diff +++ b/tests/mir-opt/pre-codegen/issue_117368_print_invalid_constant.main.GVN.64bit.panic-unwind.diff @@ -45,16 +45,12 @@ bb1: { StorageDead(_6); -- StorageLive(_12); -+ nop; - _12 = copy (_5.0: *const [u8]); -- _4 = move _12 as *mut [u8] (PtrToPtr); -- StorageDead(_12); -+ _4 = copy _12 as *mut [u8] (PtrToPtr); -+ nop; + nop; + nop; + nop; + nop; StorageDead(_5); -- _3 = move _4 as *mut u8 (PtrToPtr); -+ _3 = copy _12 as *mut u8 (PtrToPtr); + nop; StorageDead(_4); StorageDead(_3); - StorageDead(_1); diff --git a/tests/mir-opt/pre-codegen/loops.vec_move.PreCodegen.after.mir b/tests/mir-opt/pre-codegen/loops.vec_move.PreCodegen.after.mir index e537dd6a28ef8..7daf85fb9c787 100644 --- a/tests/mir-opt/pre-codegen/loops.vec_move.PreCodegen.after.mir +++ b/tests/mir-opt/pre-codegen/loops.vec_move.PreCodegen.after.mir @@ -3,72 +3,370 @@ fn vec_move(_1: Vec) -> () { debug v => _1; let mut _0: (); - let mut _2: std::vec::IntoIter; - let mut _3: std::vec::IntoIter; - let mut _4: &mut std::vec::IntoIter; - let mut _5: std::option::Option; - let mut _6: isize; - let _8: (); + let mut _2: std::ptr::NonNull; + let mut _3: std::marker::PhantomData; + let mut _4: alloc::raw_vec::Cap; + let mut _5: std::alloc::Global; + let mut _6: std::marker::PhantomData; + let mut _7: usize; + let mut _21: std::vec::IntoIter; + let mut _22: std::vec::IntoIter; + let mut _23: &mut std::vec::IntoIter; + let mut _24: std::option::Option; + let mut _25: isize; + let _27: (); scope 1 { - debug iter => _3; - let _7: impl Sized; + debug iter => _22; + let _26: impl Sized; scope 2 { - debug x => _7; + debug x => _26; + } + } + scope 3 (inlined as IntoIterator>::into_iter) { + debug (((((self: Vec).0: alloc::raw_vec::RawVec).0: alloc::raw_vec::RawVecInner).0: std::ptr::Unique).0: std::ptr::NonNull) => _2; + debug (((((self: Vec).0: alloc::raw_vec::RawVec).0: alloc::raw_vec::RawVecInner).0: std::ptr::Unique).1: std::marker::PhantomData) => _3; + debug ((((self: Vec).0: alloc::raw_vec::RawVec).0: alloc::raw_vec::RawVecInner).1: alloc::raw_vec::Cap) => _4; + debug ((((self: Vec).0: alloc::raw_vec::RawVec).0: alloc::raw_vec::RawVecInner).2: std::alloc::Global) => _5; + debug (((self: Vec).0: alloc::raw_vec::RawVec).1: std::marker::PhantomData) => _6; + debug ((self: Vec).1: usize) => _7; + let mut _12: *mut impl Sized; + let mut _13: *const impl Sized; + let mut _19: usize; + let mut _20: *const impl Sized; + let _28: std::mem::ManuallyDrop>; + let mut _29: *const std::alloc::Global; + let mut _30: &std::vec::Vec; + let mut _31: &std::mem::ManuallyDrop>; + let mut _32: &alloc::raw_vec::RawVec; + let mut _33: &std::mem::ManuallyDrop>; + let mut _34: &std::vec::Vec; + let mut _35: &std::mem::ManuallyDrop>; + let mut _36: &std::vec::Vec; + let mut _37: &std::mem::ManuallyDrop>; + let mut _38: &alloc::raw_vec::RawVec; + let mut _39: &std::mem::ManuallyDrop>; + scope 4 { + debug me => _28; + scope 5 { + debug alloc => const ManuallyDrop:: {{ value: std::alloc::Global }}; + let _10: std::ptr::NonNull; + scope 6 { + debug buf => _10; + let _11: *mut impl Sized; + scope 7 { + debug begin => _11; + let _14: *const impl Sized; + scope 8 { + debug end => _14; + let _18: usize; + scope 9 { + debug cap => _18; + } + scope 39 (inlined > as Deref>::deref) { + debug self => _39; + } + scope 40 (inlined alloc::raw_vec::RawVec::::capacity) { + debug self => _38; + let mut _17: usize; + let mut _47: &alloc::raw_vec::RawVecInner; + scope 41 (inlined std::mem::size_of::) { + } + scope 42 (inlined alloc::raw_vec::RawVecInner::capacity) { + debug self => _47; + debug elem_size => _17; + } + } + } + scope 27 (inlined > as Deref>::deref) { + debug self => _35; + } + scope 28 (inlined Vec::::len) { + debug self => _34; + } + scope 29 (inlined std::ptr::mut_ptr::::wrapping_byte_add) { + debug self => _11; + debug count => _7; + let mut _43: *mut u8; + let mut _44: *mut u8; + let mut _45: *const impl Sized; + scope 30 (inlined std::ptr::mut_ptr::::cast::) { + debug self => _11; + } + scope 31 (inlined std::ptr::mut_ptr::::wrapping_add) { + debug self => _44; + debug count => _7; + let mut _15: isize; + scope 32 (inlined std::ptr::mut_ptr::::wrapping_offset) { + debug self => _44; + debug count => _15; + let mut _16: *const u8; + } + } + scope 33 (inlined std::ptr::mut_ptr::::with_metadata_of::) { + debug self => _43; + debug meta => _45; + let mut _46: *mut (); + scope 34 (inlined std::ptr::metadata::) { + debug ptr => _45; + } + scope 35 (inlined std::ptr::from_raw_parts_mut::) { + debug data_pointer => _46; + debug metadata => const (); + } + } + } + scope 36 (inlined > as Deref>::deref) { + debug self => _37; + } + scope 37 (inlined Vec::::len) { + debug self => _36; + } + scope 38 (inlined std::ptr::mut_ptr::::add) { + debug self => _11; + debug count => _7; + } + } + scope 26 (inlined NonNull::::as_ptr) { + debug self => _10; + } + } + scope 17 (inlined > as Deref>::deref) { + debug self => _33; + } + scope 18 (inlined alloc::raw_vec::RawVec::::non_null) { + debug self => _32; + let mut _42: &alloc::raw_vec::RawVecInner; + scope 19 (inlined alloc::raw_vec::RawVecInner::non_null::) { + debug self => _42; + scope 20 (inlined Unique::::cast::) { + debug ((self: Unique).0: std::ptr::NonNull) => _2; + debug ((self: Unique).1: std::marker::PhantomData) => const PhantomData::; + scope 21 (inlined NonNull::::cast::) { + debug self => _2; + let mut _9: *const impl Sized; + scope 22 (inlined NonNull::::as_ptr) { + debug self => _2; + let mut _8: *const u8; + } + } + } + scope 23 (inlined #[track_caller] as Into>>::into) { + debug ((self: Unique).0: std::ptr::NonNull) => _10; + debug ((self: Unique).1: std::marker::PhantomData) => const ZeroSized: PhantomData; + scope 24 (inlined as From>>::from) { + debug ((unique: Unique).0: std::ptr::NonNull) => _10; + debug ((unique: Unique).1: std::marker::PhantomData) => const ZeroSized: PhantomData; + scope 25 (inlined Unique::::as_non_null_ptr) { + debug ((self: Unique).0: std::ptr::NonNull) => _10; + debug ((self: Unique).1: std::marker::PhantomData) => const ZeroSized: PhantomData; + } + } + } + } + } + } + scope 11 (inlined > as Deref>::deref) { + debug self => _31; + } + scope 12 (inlined Vec::::allocator) { + debug self => _30; + let mut _40: &alloc::raw_vec::RawVec; + scope 13 (inlined alloc::raw_vec::RawVec::::allocator) { + debug self => _40; + let mut _41: &alloc::raw_vec::RawVecInner; + scope 14 (inlined alloc::raw_vec::RawVecInner::allocator) { + debug self => _41; + } + } + } + scope 15 (inlined std::ptr::read::) { + debug src => _29; + } + scope 16 (inlined ManuallyDrop::::new) { + debug value => const std::alloc::Global; + } + } + scope 10 (inlined ManuallyDrop::>::new) { + debug (((((value: Vec).0: alloc::raw_vec::RawVec).0: alloc::raw_vec::RawVecInner).0: std::ptr::Unique).0: std::ptr::NonNull) => _2; + debug (((((value: Vec).0: alloc::raw_vec::RawVec).0: alloc::raw_vec::RawVecInner).0: std::ptr::Unique).1: std::marker::PhantomData) => _3; + debug ((((value: Vec).0: alloc::raw_vec::RawVec).0: alloc::raw_vec::RawVecInner).1: alloc::raw_vec::Cap) => _4; + debug ((((value: Vec).0: alloc::raw_vec::RawVec).0: alloc::raw_vec::RawVecInner).2: std::alloc::Global) => _5; + debug (((value: Vec).0: alloc::raw_vec::RawVec).1: std::marker::PhantomData) => _6; + debug ((value: Vec).1: usize) => _7; } } bb0: { - StorageLive(_2); - _2 = as IntoIterator>::into_iter(move _1) -> [return: bb1, unwind continue]; + StorageLive(_21); + StorageLive(_3); + StorageLive(_4); + StorageLive(_5); + StorageLive(_6); + _2 = move ((((_1.0: alloc::raw_vec::RawVec).0: alloc::raw_vec::RawVecInner).0: std::ptr::Unique).0: std::ptr::NonNull); + _3 = move ((((_1.0: alloc::raw_vec::RawVec).0: alloc::raw_vec::RawVecInner).0: std::ptr::Unique).1: std::marker::PhantomData); + _4 = move (((_1.0: alloc::raw_vec::RawVec).0: alloc::raw_vec::RawVecInner).1: alloc::raw_vec::Cap); + _5 = move (((_1.0: alloc::raw_vec::RawVec).0: alloc::raw_vec::RawVecInner).2: std::alloc::Global); + _6 = move ((_1.0: alloc::raw_vec::RawVec).1: std::marker::PhantomData); + _7 = move (_1.1: usize); + StorageLive(_29); + StorageLive(_30); + StorageLive(_31); + StorageLive(_10); + StorageLive(_32); + StorageLive(_33); + StorageLive(_11); + StorageLive(_34); + StorageLive(_35); + StorageLive(_36); + StorageLive(_37); + StorageLive(_39); + StorageLive(_9); + StorageLive(_8); + StorageLive(_16); + StorageLive(_46); + StorageLive(_28); + StorageLive(_40); + StorageLive(_41); + StorageDead(_41); + StorageDead(_40); + StorageLive(_42); + _8 = copy (_2.0: *const u8); + _9 = copy _8 as *const impl Sized (PtrToPtr); + _10 = NonNull:: { pointer: copy _9 }; + StorageDead(_42); + _11 = copy _8 as *mut impl Sized (PtrToPtr); + StorageLive(_14); + switchInt(const ::IS_ZST) -> [0: bb1, otherwise: bb2]; } bb1: { - StorageLive(_3); - _3 = move _2; - goto -> bb2; + StorageLive(_13); + StorageLive(_12); + _12 = Offset(copy _11, copy _7); + _13 = move _12 as *const impl Sized (PtrToPtr); + StorageDead(_12); + _14 = move _13; + StorageDead(_13); + goto -> bb4; } bb2: { - StorageLive(_5); - _4 = &mut _3; - _5 = as Iterator>::next(move _4) -> [return: bb3, unwind: bb9]; + StorageLive(_45); + StorageLive(_43); + StorageLive(_44); + StorageLive(_15); + _15 = copy _7 as isize (IntToInt); + _16 = arith_offset::(move _8, move _15) -> [return: bb3, unwind unreachable]; } bb3: { - _6 = discriminant(_5); - switchInt(move _6) -> [0: bb4, 1: bb6, otherwise: bb8]; + StorageDead(_15); + StorageDead(_44); + StorageDead(_43); + StorageDead(_45); + _14 = copy _16 as *const impl Sized (PtrToPtr); + goto -> bb4; } bb4: { - StorageDead(_5); - drop(_3) -> [return: bb5, unwind continue]; + StorageLive(_18); + StorageLive(_38); + StorageLive(_47); + StorageLive(_17); + _17 = SizeOf(impl Sized); + switchInt(move _17) -> [0: bb5, otherwise: bb6]; } bb5: { - StorageDead(_3); - StorageDead(_2); - return; + _18 = const core::num::::MAX; + goto -> bb7; } bb6: { - _7 = move ((_5 as Some).0: impl Sized); - _8 = opaque::(move _7) -> [return: bb7, unwind: bb9]; + _18 = copy (_4.0: usize); + goto -> bb7; } bb7: { + StorageDead(_17); + StorageDead(_47); + StorageDead(_38); + StorageLive(_19); + _19 = copy _18; + StorageLive(_20); + _20 = copy _14; + _21 = std::vec::IntoIter:: { buf: copy _10, phantom: const ZeroSized: PhantomData, cap: move _19, alloc: const ManuallyDrop:: {{ value: std::alloc::Global }}, ptr: copy _10, end: move _20 }; + StorageDead(_20); + StorageDead(_19); + StorageDead(_18); + StorageDead(_14); + StorageDead(_28); + StorageDead(_46); + StorageDead(_16); + StorageDead(_8); + StorageDead(_9); + StorageDead(_39); + StorageDead(_37); + StorageDead(_36); + StorageDead(_35); + StorageDead(_34); + StorageDead(_11); + StorageDead(_33); + StorageDead(_32); + StorageDead(_10); + StorageDead(_31); + StorageDead(_30); + StorageDead(_29); + StorageDead(_3); + StorageDead(_4); StorageDead(_5); - goto -> bb2; + StorageDead(_6); + StorageLive(_22); + _22 = move _21; + goto -> bb8; } bb8: { + StorageLive(_24); + _23 = &mut _22; + _24 = as Iterator>::next(move _23) -> [return: bb9, unwind: bb15]; + } + + bb9: { + _25 = discriminant(_24); + switchInt(move _25) -> [0: bb10, 1: bb12, otherwise: bb14]; + } + + bb10: { + StorageDead(_24); + drop(_22) -> [return: bb11, unwind continue]; + } + + bb11: { + StorageDead(_22); + StorageDead(_21); + return; + } + + bb12: { + _26 = move ((_24 as Some).0: impl Sized); + _27 = opaque::(move _26) -> [return: bb13, unwind: bb15]; + } + + bb13: { + StorageDead(_24); + goto -> bb8; + } + + bb14: { unreachable; } - bb9 (cleanup): { - drop(_3) -> [return: bb10, unwind terminate(cleanup)]; + bb15 (cleanup): { + drop(_22) -> [return: bb16, unwind terminate(cleanup)]; } - bb10 (cleanup): { + bb16 (cleanup): { resume; } } diff --git a/tests/mir-opt/pre-codegen/optimizes_into_variable.rs b/tests/mir-opt/pre-codegen/optimizes_into_variable.rs index 44b4b0ad888a5..65dc065d7262c 100644 --- a/tests/mir-opt/pre-codegen/optimizes_into_variable.rs +++ b/tests/mir-opt/pre-codegen/optimizes_into_variable.rs @@ -1,6 +1,6 @@ // skip-filecheck // EMIT_MIR_FOR_EACH_PANIC_STRATEGY -//@ compile-flags: -C overflow-checks=on -Zdump-mir-exclude-alloc-bytes +//@ compile-flags: -C overflow-checks=on -Zdump-mir-exclude-alloc-bytes -Cdebuginfo=full struct Point { x: u32, diff --git a/tests/mir-opt/pre-codegen/vec_deref.vec_deref_to_slice.PreCodegen.after.panic-abort.mir b/tests/mir-opt/pre-codegen/vec_deref.vec_deref_to_slice.PreCodegen.after.panic-abort.mir index ce1e4a0abd61f..d02a3617724b7 100644 --- a/tests/mir-opt/pre-codegen/vec_deref.vec_deref_to_slice.PreCodegen.after.panic-abort.mir +++ b/tests/mir-opt/pre-codegen/vec_deref.vec_deref_to_slice.PreCodegen.after.panic-abort.mir @@ -5,53 +5,54 @@ fn vec_deref_to_slice(_1: &Vec) -> &[u8] { let mut _0: &[u8]; scope 1 (inlined as Deref>::deref) { debug self => _1; - let mut _7: usize; + let mut _4: usize; + let mut _6: *const u8; scope 2 (inlined Vec::::as_ptr) { debug self => _1; - let mut _2: &alloc::raw_vec::RawVec; + let mut _7: &alloc::raw_vec::RawVec; scope 3 (inlined alloc::raw_vec::RawVec::::ptr) { - debug self => _2; - let mut _3: &alloc::raw_vec::RawVecInner; + debug self => _7; + let mut _8: &alloc::raw_vec::RawVecInner; scope 4 (inlined alloc::raw_vec::RawVecInner::ptr::) { - debug self => _3; - let mut _6: std::ptr::NonNull; + debug self => _8; + let mut _9: std::ptr::NonNull; scope 5 (inlined alloc::raw_vec::RawVecInner::non_null::) { - debug self => _3; - let mut _4: std::ptr::NonNull; + debug self => _8; + let mut _2: std::ptr::NonNull; scope 6 (inlined Unique::::cast::) { - debug ((self: Unique).0: std::ptr::NonNull) => _4; + debug ((self: Unique).0: std::ptr::NonNull) => _2; debug ((self: Unique).1: std::marker::PhantomData) => const PhantomData::; scope 7 (inlined NonNull::::cast::) { - debug self => _4; + debug self => _2; scope 8 (inlined NonNull::::as_ptr) { - debug self => _4; - let mut _5: *const u8; + debug self => _2; + let mut _3: *const u8; } } } scope 9 (inlined #[track_caller] as Into>>::into) { - debug ((self: Unique).0: std::ptr::NonNull) => _6; + debug ((self: Unique).0: std::ptr::NonNull) => _9; debug ((self: Unique).1: std::marker::PhantomData) => const PhantomData::; scope 10 (inlined as From>>::from) { - debug ((unique: Unique).0: std::ptr::NonNull) => _6; + debug ((unique: Unique).0: std::ptr::NonNull) => _9; debug ((unique: Unique).1: std::marker::PhantomData) => const PhantomData::; scope 11 (inlined Unique::::as_non_null_ptr) { - debug ((self: Unique).0: std::ptr::NonNull) => _6; + debug ((self: Unique).0: std::ptr::NonNull) => _9; debug ((self: Unique).1: std::marker::PhantomData) => const PhantomData::; } } } } scope 12 (inlined NonNull::::as_ptr) { - debug self => _6; + debug self => _9; } } } } scope 13 (inlined std::slice::from_raw_parts::<'_, u8>) { - debug data => _5; - debug len => _7; - let _8: *const [u8]; + debug data => _6; + debug len => _4; + let _5: *const [u8]; scope 14 (inlined core::ub_checks::check_language_ub) { scope 15 (inlined core::ub_checks::check_language_ub::runtime) { } @@ -61,37 +62,38 @@ fn vec_deref_to_slice(_1: &Vec) -> &[u8] { scope 17 (inlined align_of::) { } scope 18 (inlined slice_from_raw_parts::) { - debug data => _5; - debug len => _7; + debug data => _6; + debug len => _4; scope 19 (inlined std::ptr::from_raw_parts::<[u8], u8>) { - debug data_pointer => _5; - debug metadata => _7; + debug data_pointer => _6; + debug metadata => _4; } } } } bb0: { - StorageLive(_2); - _2 = &((*_1).0: alloc::raw_vec::RawVec); StorageLive(_3); - _3 = &(((*_1).0: alloc::raw_vec::RawVec).0: alloc::raw_vec::RawVecInner); StorageLive(_6); - StorageLive(_4); - _4 = copy (((((*_1).0: alloc::raw_vec::RawVec).0: alloc::raw_vec::RawVecInner).0: std::ptr::Unique).0: std::ptr::NonNull); - _5 = copy (_4.0: *const u8); - _6 = NonNull:: { pointer: copy _5 }; - StorageDead(_4); - StorageDead(_6); - StorageDead(_3); - StorageDead(_2); StorageLive(_7); - _7 = copy ((*_1).1: usize); StorageLive(_8); - _8 = *const [u8] from (copy _5, copy _7); - _0 = &(*_8); + StorageLive(_9); + StorageLive(_2); + _2 = copy (((((*_1).0: alloc::raw_vec::RawVec).0: alloc::raw_vec::RawVecInner).0: std::ptr::Unique).0: std::ptr::NonNull); + _3 = copy (_2.0: *const u8); + StorageDead(_2); + StorageDead(_9); StorageDead(_8); StorageDead(_7); + StorageLive(_4); + _4 = copy ((*_1).1: usize); + StorageLive(_5); + _5 = *const [u8] from (copy _3, copy _4); + _0 = &(*_5); + StorageDead(_5); + StorageDead(_4); + StorageDead(_6); + StorageDead(_3); return; } } diff --git a/tests/mir-opt/pre-codegen/vec_deref.vec_deref_to_slice.PreCodegen.after.panic-unwind.mir b/tests/mir-opt/pre-codegen/vec_deref.vec_deref_to_slice.PreCodegen.after.panic-unwind.mir index ce1e4a0abd61f..d02a3617724b7 100644 --- a/tests/mir-opt/pre-codegen/vec_deref.vec_deref_to_slice.PreCodegen.after.panic-unwind.mir +++ b/tests/mir-opt/pre-codegen/vec_deref.vec_deref_to_slice.PreCodegen.after.panic-unwind.mir @@ -5,53 +5,54 @@ fn vec_deref_to_slice(_1: &Vec) -> &[u8] { let mut _0: &[u8]; scope 1 (inlined as Deref>::deref) { debug self => _1; - let mut _7: usize; + let mut _4: usize; + let mut _6: *const u8; scope 2 (inlined Vec::::as_ptr) { debug self => _1; - let mut _2: &alloc::raw_vec::RawVec; + let mut _7: &alloc::raw_vec::RawVec; scope 3 (inlined alloc::raw_vec::RawVec::::ptr) { - debug self => _2; - let mut _3: &alloc::raw_vec::RawVecInner; + debug self => _7; + let mut _8: &alloc::raw_vec::RawVecInner; scope 4 (inlined alloc::raw_vec::RawVecInner::ptr::) { - debug self => _3; - let mut _6: std::ptr::NonNull; + debug self => _8; + let mut _9: std::ptr::NonNull; scope 5 (inlined alloc::raw_vec::RawVecInner::non_null::) { - debug self => _3; - let mut _4: std::ptr::NonNull; + debug self => _8; + let mut _2: std::ptr::NonNull; scope 6 (inlined Unique::::cast::) { - debug ((self: Unique).0: std::ptr::NonNull) => _4; + debug ((self: Unique).0: std::ptr::NonNull) => _2; debug ((self: Unique).1: std::marker::PhantomData) => const PhantomData::; scope 7 (inlined NonNull::::cast::) { - debug self => _4; + debug self => _2; scope 8 (inlined NonNull::::as_ptr) { - debug self => _4; - let mut _5: *const u8; + debug self => _2; + let mut _3: *const u8; } } } scope 9 (inlined #[track_caller] as Into>>::into) { - debug ((self: Unique).0: std::ptr::NonNull) => _6; + debug ((self: Unique).0: std::ptr::NonNull) => _9; debug ((self: Unique).1: std::marker::PhantomData) => const PhantomData::; scope 10 (inlined as From>>::from) { - debug ((unique: Unique).0: std::ptr::NonNull) => _6; + debug ((unique: Unique).0: std::ptr::NonNull) => _9; debug ((unique: Unique).1: std::marker::PhantomData) => const PhantomData::; scope 11 (inlined Unique::::as_non_null_ptr) { - debug ((self: Unique).0: std::ptr::NonNull) => _6; + debug ((self: Unique).0: std::ptr::NonNull) => _9; debug ((self: Unique).1: std::marker::PhantomData) => const PhantomData::; } } } } scope 12 (inlined NonNull::::as_ptr) { - debug self => _6; + debug self => _9; } } } } scope 13 (inlined std::slice::from_raw_parts::<'_, u8>) { - debug data => _5; - debug len => _7; - let _8: *const [u8]; + debug data => _6; + debug len => _4; + let _5: *const [u8]; scope 14 (inlined core::ub_checks::check_language_ub) { scope 15 (inlined core::ub_checks::check_language_ub::runtime) { } @@ -61,37 +62,38 @@ fn vec_deref_to_slice(_1: &Vec) -> &[u8] { scope 17 (inlined align_of::) { } scope 18 (inlined slice_from_raw_parts::) { - debug data => _5; - debug len => _7; + debug data => _6; + debug len => _4; scope 19 (inlined std::ptr::from_raw_parts::<[u8], u8>) { - debug data_pointer => _5; - debug metadata => _7; + debug data_pointer => _6; + debug metadata => _4; } } } } bb0: { - StorageLive(_2); - _2 = &((*_1).0: alloc::raw_vec::RawVec); StorageLive(_3); - _3 = &(((*_1).0: alloc::raw_vec::RawVec).0: alloc::raw_vec::RawVecInner); StorageLive(_6); - StorageLive(_4); - _4 = copy (((((*_1).0: alloc::raw_vec::RawVec).0: alloc::raw_vec::RawVecInner).0: std::ptr::Unique).0: std::ptr::NonNull); - _5 = copy (_4.0: *const u8); - _6 = NonNull:: { pointer: copy _5 }; - StorageDead(_4); - StorageDead(_6); - StorageDead(_3); - StorageDead(_2); StorageLive(_7); - _7 = copy ((*_1).1: usize); StorageLive(_8); - _8 = *const [u8] from (copy _5, copy _7); - _0 = &(*_8); + StorageLive(_9); + StorageLive(_2); + _2 = copy (((((*_1).0: alloc::raw_vec::RawVec).0: alloc::raw_vec::RawVecInner).0: std::ptr::Unique).0: std::ptr::NonNull); + _3 = copy (_2.0: *const u8); + StorageDead(_2); + StorageDead(_9); StorageDead(_8); StorageDead(_7); + StorageLive(_4); + _4 = copy ((*_1).1: usize); + StorageLive(_5); + _5 = *const [u8] from (copy _3, copy _4); + _0 = &(*_5); + StorageDead(_5); + StorageDead(_4); + StorageDead(_6); + StorageDead(_3); return; } } diff --git a/tests/mir-opt/separate_const_switch.too_complex.JumpThreading.diff b/tests/mir-opt/separate_const_switch.too_complex.JumpThreading.diff index c88c63e0c1334..ed3f54e9653e8 100644 --- a/tests/mir-opt/separate_const_switch.too_complex.JumpThreading.diff +++ b/tests/mir-opt/separate_const_switch.too_complex.JumpThreading.diff @@ -54,10 +54,7 @@ } bb5: { - StorageLive(_8); - _8 = copy ((_2 as Break).0: usize); _0 = const Option::::None; - StorageDead(_8); goto -> bb7; } diff --git a/tests/ui/consts/required-consts/collect-in-promoted-const.rs b/tests/ui/consts/required-consts/collect-in-promoted-const.rs index 4a3ce92e8f90d..a55ad47f71ef7 100644 --- a/tests/ui/consts/required-consts/collect-in-promoted-const.rs +++ b/tests/ui/consts/required-consts/collect-in-promoted-const.rs @@ -1,7 +1,7 @@ //@revisions: noopt opt //@ build-fail //@[noopt] compile-flags: -Copt-level=0 -//@[opt] compile-flags: -O +//@[opt] compile-flags: -O -Cdebuginfo=full //! Make sure we error on erroneous consts even if they get promoted. struct Fail(T);