From 1c048eb5c01040feae731560f3c95f8647beb218 Mon Sep 17 00:00:00 2001 From: ouz-a Date: Thu, 12 May 2022 00:27:06 +0300 Subject: [PATCH] validate derefer, run derefer inside generator --- .../src/transform/validate.rs | 11 +- compiler/rustc_middle/src/mir/mod.rs | 8 +- .../src/deref_separator.rs | 110 ++++++++++-------- compiler/rustc_mir_transform/src/generator.rs | 4 + compiler/rustc_mir_transform/src/inline.rs | 3 +- .../derefer_inline_test.main.Derefer.diff | 69 +++++++++++ src/test/mir-opt/derefer_inline_test.rs | 9 ++ .../inline/dyn_trait.get_query.Inline.diff | 4 + .../dyn_trait.try_execute_query.Inline.diff | 4 + .../inline_any_operand.bar.Inline.after.mir | 4 + .../inline_closure.foo.Inline.after.mir | 4 + ...e_closure_borrows_arg.foo.Inline.after.mir | 4 + ...line_closure_captures.foo.Inline.after.mir | 4 + ...patibility.inlined_no_sanitize.Inline.diff | 4 + ...ibility.inlined_target_feature.Inline.diff | 4 + .../inline/inline_cycle.one.Inline.diff | 4 + .../inline/inline_cycle.two.Inline.diff | 4 + .../inline/inline_diverging.f.Inline.diff | 4 + .../inline/inline_diverging.g.Inline.diff | 4 + .../inline/inline_diverging.h.Inline.diff | 4 + .../inline/inline_generator.main.Inline.diff | 18 ++- ...inline_instruction_set.default.Inline.diff | 4 + .../inline_instruction_set.t32.Inline.diff | 4 + .../inline_options.main.Inline.after.mir | 4 + .../inline/inline_retag.bar.Inline.after.mir | 4 + .../inline/inline_shims.clone.Inline.diff | 4 + .../inline/inline_shims.drop.Inline.diff | 4 + .../inline_specialization.main.Inline.diff | 4 + ...line_trait_method_2.test2.Inline.after.mir | 4 + ...67_inline_as_ref_as_mut.a.Inline.after.mir | 4 + ...67_inline_as_ref_as_mut.b.Inline.after.mir | 4 + ...67_inline_as_ref_as_mut.c.Inline.after.mir | 4 + ...67_inline_as_ref_as_mut.d.Inline.after.mir | 4 + ...ine_scopes_parenting.main.Inline.after.mir | 4 + ...age_markers.main.RemoveStorageMarkers.diff | 4 + ...nneeded_drops.opt.RemoveUnneededDrops.diff | 4 + ....opt_generic_copy.RemoveUnneededDrops.diff | 4 + ...mplify_arm.id_try.SimplifyArmIdentity.diff | 4 + ...implify_arm.id_try.SimplifyBranchSame.diff | 4 + 39 files changed, 297 insertions(+), 59 deletions(-) create mode 100644 src/test/mir-opt/derefer_inline_test.main.Derefer.diff create mode 100644 src/test/mir-opt/derefer_inline_test.rs diff --git a/compiler/rustc_const_eval/src/transform/validate.rs b/compiler/rustc_const_eval/src/transform/validate.rs index 54c2daf9ac20e..665b07c9f89ce 100644 --- a/compiler/rustc_const_eval/src/transform/validate.rs +++ b/compiler/rustc_const_eval/src/transform/validate.rs @@ -4,6 +4,7 @@ use rustc_data_structures::fx::FxHashSet; use rustc_index::bit_set::BitSet; use rustc_infer::infer::TyCtxtInferExt; use rustc_middle::mir::interpret::Scalar; +use rustc_middle::mir::visit::NonUseContext::VarDebugInfo; use rustc_middle::mir::visit::{PlaceContext, Visitor}; use rustc_middle::mir::{ traversal, AggregateKind, BasicBlock, BinOp, Body, BorrowKind, Local, Location, MirPass, @@ -302,9 +303,17 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> { self.super_projection_elem(local, proj_base, elem, context, location); } - fn visit_place(&mut self, place: &Place<'tcx>, _: PlaceContext, _: Location) { + fn visit_place(&mut self, place: &Place<'tcx>, cntxt: PlaceContext, location: Location) { // Set off any `bug!`s in the type computation code let _ = place.ty(&self.body.local_decls, self.tcx); + + if self.mir_phase >= MirPhase::Derefered + && place.projection.len() > 1 + && cntxt != PlaceContext::NonUse(VarDebugInfo) + && place.projection[1..].contains(&ProjectionElem::Deref) + { + self.fail(location, format!("{:?}, has deref at the wrong place", place)); + } } fn visit_rvalue(&mut self, rvalue: &Rvalue<'tcx>, location: Location) { diff --git a/compiler/rustc_middle/src/mir/mod.rs b/compiler/rustc_middle/src/mir/mod.rs index 9f8b22c8afc47..84fb817418eae 100644 --- a/compiler/rustc_middle/src/mir/mod.rs +++ b/compiler/rustc_middle/src/mir/mod.rs @@ -172,12 +172,14 @@ pub enum MirPhase { /// terminator means that the auto-generated drop glue will be invoked. Also, `Copy` operands /// are allowed for non-`Copy` types. DropsLowered = 3, + /// After this projections may only contain deref projections as the first element. + Derefered = 4, /// Beginning with this phase, the following variant is disallowed: /// * [`Rvalue::Aggregate`] for any `AggregateKind` except `Array` /// /// And the following variant is allowed: /// * [`StatementKind::SetDiscriminant`] - Deaggregated = 4, + Deaggregated = 5, /// Before this phase, generators are in the "source code" form, featuring `yield` statements /// and such. With this phase change, they are transformed into a proper state machine. Running /// optimizations before this change can be potentially dangerous because the source code is to @@ -191,8 +193,8 @@ pub enum MirPhase { /// Beginning with this phase, the following variants are disallowed: /// * [`TerminatorKind::Yield`](terminator::TerminatorKind::Yield) /// * [`TerminatorKind::GeneratorDrop`](terminator::TerminatorKind::GeneratorDrop) - GeneratorsLowered = 5, - Optimized = 6, + GeneratorsLowered = 6, + Optimized = 7, } impl MirPhase { diff --git a/compiler/rustc_mir_transform/src/deref_separator.rs b/compiler/rustc_mir_transform/src/deref_separator.rs index 57a95a67df70c..bfb3ad1be2734 100644 --- a/compiler/rustc_mir_transform/src/deref_separator.rs +++ b/compiler/rustc_mir_transform/src/deref_separator.rs @@ -1,9 +1,11 @@ use crate::MirPass; use rustc_index::vec::IndexVec; use rustc_middle::mir::patch::MirPatch; +use rustc_middle::mir::visit::NonUseContext::VarDebugInfo; use rustc_middle::mir::visit::{MutVisitor, PlaceContext}; use rustc_middle::mir::*; use rustc_middle::ty::TyCtxt; + pub struct Derefer; pub struct DerefChecker<'tcx> { @@ -17,63 +19,68 @@ impl<'tcx> MutVisitor<'tcx> for DerefChecker<'tcx> { self.tcx } - fn visit_place(&mut self, place: &mut Place<'tcx>, _: PlaceContext, loc: Location) { - let mut place_local = place.local; - let mut last_len = 0; - let mut last_deref_idx = 0; + fn visit_place(&mut self, place: &mut Place<'tcx>, cntxt: PlaceContext, loc: Location) { + if !place.projection.is_empty() + && cntxt != PlaceContext::NonUse(VarDebugInfo) + && place.projection[1..].contains(&ProjectionElem::Deref) + { + let mut place_local = place.local; + let mut last_len = 0; + let mut last_deref_idx = 0; - let mut prev_temp: Option = None; + let mut prev_temp: Option = None; - for (idx, (p_ref, p_elem)) in place.iter_projections().enumerate() { - if p_elem == ProjectionElem::Deref && !p_ref.projection.is_empty() { - last_deref_idx = idx; - } - } - - for (idx, (p_ref, p_elem)) in place.iter_projections().enumerate() { - if p_elem == ProjectionElem::Deref && !p_ref.projection.is_empty() { - let ty = p_ref.ty(&self.local_decls, self.tcx).ty; - let temp = self.patcher.new_local_with_info( - ty, - self.local_decls[p_ref.local].source_info.span, - Some(Box::new(LocalInfo::DerefTemp)), - ); - - self.patcher.add_statement(loc, StatementKind::StorageLive(temp)); - - // We are adding current p_ref's projections to our - // temp value, excluding projections we already covered. - let deref_place = Place::from(place_local) - .project_deeper(&p_ref.projection[last_len..], self.tcx); - - self.patcher.add_assign( - loc, - Place::from(temp), - Rvalue::Use(Operand::Move(deref_place)), - ); - place_local = temp; - last_len = p_ref.projection.len(); - - // Change `Place` only if we are actually at the Place's last deref - if idx == last_deref_idx { - let temp_place = - Place::from(temp).project_deeper(&place.projection[idx..], self.tcx); - *place = temp_place; + for (idx, elem) in place.projection[0..].iter().enumerate() { + if *elem == ProjectionElem::Deref { + last_deref_idx = idx; } - - // We are destroying the previous temp since it's no longer used. - if let Some(prev_temp) = prev_temp { - self.patcher.add_statement(loc, StatementKind::StorageDead(prev_temp)); + } + for (idx, (p_ref, p_elem)) in place.iter_projections().enumerate() { + if !p_ref.projection.is_empty() && p_elem == ProjectionElem::Deref { + let ty = p_ref.ty(&self.local_decls, self.tcx).ty; + let temp = self.patcher.new_local_with_info( + ty, + self.local_decls[p_ref.local].source_info.span, + Some(Box::new(LocalInfo::DerefTemp)), + ); + + self.patcher.add_statement(loc, StatementKind::StorageLive(temp)); + + // We are adding current p_ref's projections to our + // temp value, excluding projections we already covered. + let deref_place = Place::from(place_local) + .project_deeper(&p_ref.projection[last_len..], self.tcx); + + self.patcher.add_assign( + loc, + Place::from(temp), + Rvalue::Use(Operand::Move(deref_place)), + ); + place_local = temp; + last_len = p_ref.projection.len(); + + // Change `Place` only if we are actually at the Place's last deref + if idx == last_deref_idx { + let temp_place = + Place::from(temp).project_deeper(&place.projection[idx..], self.tcx); + *place = temp_place; + } + + // We are destroying the previous temp since it's no longer used. + if let Some(prev_temp) = prev_temp { + self.patcher.add_statement(loc, StatementKind::StorageDead(prev_temp)); + } + + prev_temp = Some(temp); } - - prev_temp = Some(temp); } - } - // Since we won't be able to reach final temp, we destroy it outside the loop. - if let Some(prev_temp) = prev_temp { - let last_loc = Location { block: loc.block, statement_index: loc.statement_index + 1 }; - self.patcher.add_statement(last_loc, StatementKind::StorageDead(prev_temp)); + // Since we won't be able to reach final temp, we destroy it outside the loop. + if let Some(prev_temp) = prev_temp { + let last_loc = + Location { block: loc.block, statement_index: loc.statement_index + 1 }; + self.patcher.add_statement(last_loc, StatementKind::StorageDead(prev_temp)); + } } } } @@ -92,5 +99,6 @@ pub fn deref_finder<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { impl<'tcx> MirPass<'tcx> for Derefer { fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { deref_finder(tcx, body); + body.phase = MirPhase::Derefered; } } diff --git a/compiler/rustc_mir_transform/src/generator.rs b/compiler/rustc_mir_transform/src/generator.rs index 4a3505ca3ffcf..9eb77f6021373 100644 --- a/compiler/rustc_mir_transform/src/generator.rs +++ b/compiler/rustc_mir_transform/src/generator.rs @@ -49,6 +49,7 @@ //! For generators with state 1 (returned) and state 2 (poisoned) it does nothing. //! Otherwise it drops all the values in scope at the last suspension point. +use crate::deref_separator::deref_finder; use crate::simplify; use crate::util::expand_aggregate; use crate::MirPass; @@ -1368,6 +1369,9 @@ impl<'tcx> MirPass<'tcx> for StateTransform { // Create the Generator::resume function create_generator_resume_function(tcx, transform, body, can_return); + + // Run derefer to fix Derefs that are not in the first place + deref_finder(tcx, body); } } diff --git a/compiler/rustc_mir_transform/src/inline.rs b/compiler/rustc_mir_transform/src/inline.rs index 66fb01bd4646d..9526c0acc66d6 100644 --- a/compiler/rustc_mir_transform/src/inline.rs +++ b/compiler/rustc_mir_transform/src/inline.rs @@ -1,5 +1,5 @@ //! Inlining pass for MIR functions - +use crate::deref_separator::deref_finder; use rustc_attr::InlineAttr; use rustc_index::bit_set::BitSet; use rustc_index::vec::Idx; @@ -53,6 +53,7 @@ impl<'tcx> MirPass<'tcx> for Inline { debug!("running simplify cfg on {:?}", body.source); CfgSimplifier::new(body).simplify(); remove_dead_blocks(tcx, body); + deref_finder(tcx, body); } } } diff --git a/src/test/mir-opt/derefer_inline_test.main.Derefer.diff b/src/test/mir-opt/derefer_inline_test.main.Derefer.diff new file mode 100644 index 0000000000000..e5e049df1db60 --- /dev/null +++ b/src/test/mir-opt/derefer_inline_test.main.Derefer.diff @@ -0,0 +1,69 @@ +- // MIR for `main` before Derefer ++ // MIR for `main` after Derefer + + fn main() -> () { + let mut _0: (); // return place in scope 0 at $DIR/derefer_inline_test.rs:7:11: 7:11 + let _1: std::boxed::Box>; // in scope 0 at $DIR/derefer_inline_test.rs:8:5: 8:12 + let mut _2: usize; // in scope 0 at $DIR/derefer_inline_test.rs:8:5: 8:12 + let mut _3: usize; // in scope 0 at $DIR/derefer_inline_test.rs:8:5: 8:12 + let mut _4: *mut u8; // in scope 0 at $DIR/derefer_inline_test.rs:8:5: 8:12 + let mut _5: std::boxed::Box>; // in scope 0 at $DIR/derefer_inline_test.rs:8:5: 8:12 + let mut _6: (); // in scope 0 at $DIR/derefer_inline_test.rs:8:11: 8:12 + scope 1 { + } + + bb0: { + StorageLive(_1); // scope 0 at $DIR/derefer_inline_test.rs:8:5: 8:12 + _2 = SizeOf(std::boxed::Box); // scope 1 at $DIR/derefer_inline_test.rs:8:5: 8:12 + _3 = AlignOf(std::boxed::Box); // scope 1 at $DIR/derefer_inline_test.rs:8:5: 8:12 + _4 = alloc::alloc::exchange_malloc(move _2, move _3) -> bb1; // scope 1 at $DIR/derefer_inline_test.rs:8:5: 8:12 + // mir::Constant + // + span: $DIR/derefer_inline_test.rs:8:5: 8:12 + // + literal: Const { ty: unsafe fn(usize, usize) -> *mut u8 {alloc::alloc::exchange_malloc}, val: Value(Scalar()) } + } + + bb1: { + StorageLive(_5); // scope 0 at $DIR/derefer_inline_test.rs:8:5: 8:12 + _5 = ShallowInitBox(move _4, std::boxed::Box); // scope 0 at $DIR/derefer_inline_test.rs:8:5: 8:12 + (*_5) = f() -> [return: bb2, unwind: bb5]; // scope 0 at $DIR/derefer_inline_test.rs:8:9: 8:12 + // mir::Constant + // + span: $DIR/derefer_inline_test.rs:8:9: 8:10 + // + literal: Const { ty: fn() -> Box {f}, val: Value(Scalar()) } + } + + bb2: { + _1 = move _5; // scope 0 at $DIR/derefer_inline_test.rs:8:5: 8:12 + goto -> bb3; // scope 0 at $DIR/derefer_inline_test.rs:8:11: 8:12 + } + + bb3: { + StorageDead(_5); // scope 0 at $DIR/derefer_inline_test.rs:8:11: 8:12 + drop(_1) -> [return: bb4, unwind: bb6]; // scope 0 at $DIR/derefer_inline_test.rs:8:12: 8:13 + } + + bb4: { + StorageDead(_1); // scope 0 at $DIR/derefer_inline_test.rs:8:12: 8:13 + _0 = const (); // scope 0 at $DIR/derefer_inline_test.rs:7:11: 9:2 + return; // scope 0 at $DIR/derefer_inline_test.rs:9:2: 9:2 + } + + bb5 (cleanup): { + goto -> bb8; // scope 0 at $DIR/derefer_inline_test.rs:8:11: 8:12 + } + + bb6 (cleanup): { + resume; // scope 0 at $DIR/derefer_inline_test.rs:7:1: 9:2 + } + + bb7 (cleanup): { + _6 = alloc::alloc::box_free::, std::alloc::Global>(move (_5.0: std::ptr::Unique>), move (_5.1: std::alloc::Global)) -> bb6; // scope 0 at $DIR/derefer_inline_test.rs:8:11: 8:12 + // mir::Constant + // + span: $DIR/derefer_inline_test.rs:8:11: 8:12 + // + literal: Const { ty: unsafe fn(Unique>, std::alloc::Global) {alloc::alloc::box_free::, std::alloc::Global>}, val: Value(Scalar()) } + } + + bb8 (cleanup): { + goto -> bb7; // scope 0 at $DIR/derefer_inline_test.rs:8:11: 8:12 + } + } + diff --git a/src/test/mir-opt/derefer_inline_test.rs b/src/test/mir-opt/derefer_inline_test.rs new file mode 100644 index 0000000000000..5f5a06881caf0 --- /dev/null +++ b/src/test/mir-opt/derefer_inline_test.rs @@ -0,0 +1,9 @@ +// EMIT_MIR derefer_inline_test.main.Derefer.diff +#![feature(box_syntax)] +#[inline] +fn f() -> Box { + box 0 +} +fn main() { + box f(); +} diff --git a/src/test/mir-opt/inline/dyn_trait.get_query.Inline.diff b/src/test/mir-opt/inline/dyn_trait.get_query.Inline.diff index 953d7b85c5ba7..d1ab29b8a21ab 100644 --- a/src/test/mir-opt/inline/dyn_trait.get_query.Inline.diff +++ b/src/test/mir-opt/inline/dyn_trait.get_query.Inline.diff @@ -57,6 +57,10 @@ StorageDead(_4); // scope 1 at $DIR/dyn-trait.rs:34:24: 34:25 StorageDead(_2); // scope 0 at $DIR/dyn-trait.rs:35:1: 35:2 return; // scope 0 at $DIR/dyn-trait.rs:35:2: 35:2 ++ } ++ ++ bb3 (cleanup): { ++ resume; // scope 0 at $DIR/dyn-trait.rs:32:1: 35:2 } } diff --git a/src/test/mir-opt/inline/dyn_trait.try_execute_query.Inline.diff b/src/test/mir-opt/inline/dyn_trait.try_execute_query.Inline.diff index 93bba58825d20..0c44c3ada0f8c 100644 --- a/src/test/mir-opt/inline/dyn_trait.try_execute_query.Inline.diff +++ b/src/test/mir-opt/inline/dyn_trait.try_execute_query.Inline.diff @@ -32,6 +32,10 @@ + StorageDead(_4); // scope 1 at $DIR/dyn-trait.rs:21:21: 21:22 StorageDead(_2); // scope 0 at $DIR/dyn-trait.rs:27:15: 27:16 return; // scope 0 at $DIR/dyn-trait.rs:28:2: 28:2 ++ } ++ ++ bb2 (cleanup): { ++ resume; // scope 0 at $DIR/dyn-trait.rs:26:1: 28:2 } } diff --git a/src/test/mir-opt/inline/inline_any_operand.bar.Inline.after.mir b/src/test/mir-opt/inline/inline_any_operand.bar.Inline.after.mir index b2745a17e9717..ade6ccfc7f144 100644 --- a/src/test/mir-opt/inline/inline_any_operand.bar.Inline.after.mir +++ b/src/test/mir-opt/inline/inline_any_operand.bar.Inline.after.mir @@ -41,4 +41,8 @@ fn bar() -> bool { StorageDead(_1); // scope 0 at $DIR/inline-any-operand.rs:13:1: 13:2 return; // scope 0 at $DIR/inline-any-operand.rs:13:2: 13:2 } + + bb1 (cleanup): { + resume; // scope 0 at $DIR/inline-any-operand.rs:10:1: 13:2 + } } diff --git a/src/test/mir-opt/inline/inline_closure.foo.Inline.after.mir b/src/test/mir-opt/inline/inline_closure.foo.Inline.after.mir index 4d6cdafd12dea..66fc5fa80ea26 100644 --- a/src/test/mir-opt/inline/inline_closure.foo.Inline.after.mir +++ b/src/test/mir-opt/inline/inline_closure.foo.Inline.after.mir @@ -46,4 +46,8 @@ fn foo(_1: T, _2: i32) -> i32 { StorageDead(_3); // scope 0 at $DIR/inline-closure.rs:13:1: 13:2 return; // scope 0 at $DIR/inline-closure.rs:13:2: 13:2 } + + bb1 (cleanup): { + resume; // scope 0 at $DIR/inline-closure.rs:10:1: 13:2 + } } diff --git a/src/test/mir-opt/inline/inline_closure_borrows_arg.foo.Inline.after.mir b/src/test/mir-opt/inline/inline_closure_borrows_arg.foo.Inline.after.mir index 45281302f9291..7bb17dab061ad 100644 --- a/src/test/mir-opt/inline/inline_closure_borrows_arg.foo.Inline.after.mir +++ b/src/test/mir-opt/inline/inline_closure_borrows_arg.foo.Inline.after.mir @@ -53,4 +53,8 @@ fn foo(_1: T, _2: &i32) -> i32 { StorageDead(_3); // scope 0 at $DIR/inline-closure-borrows-arg.rs:17:1: 17:2 return; // scope 0 at $DIR/inline-closure-borrows-arg.rs:17:2: 17:2 } + + bb1 (cleanup): { + resume; // scope 0 at $DIR/inline-closure-borrows-arg.rs:11:1: 17:2 + } } diff --git a/src/test/mir-opt/inline/inline_closure_captures.foo.Inline.after.mir b/src/test/mir-opt/inline/inline_closure_captures.foo.Inline.after.mir index 75e37092ff3c3..c6b49b66dc5c0 100644 --- a/src/test/mir-opt/inline/inline_closure_captures.foo.Inline.after.mir +++ b/src/test/mir-opt/inline/inline_closure_captures.foo.Inline.after.mir @@ -66,4 +66,8 @@ fn foo(_1: T, _2: i32) -> (i32, T) { StorageDead(_3); // scope 0 at $DIR/inline-closure-captures.rs:13:1: 13:2 return; // scope 0 at $DIR/inline-closure-captures.rs:13:2: 13:2 } + + bb1 (cleanup): { + resume; // scope 0 at $DIR/inline-closure-captures.rs:10:1: 13:2 + } } diff --git a/src/test/mir-opt/inline/inline_compatibility.inlined_no_sanitize.Inline.diff b/src/test/mir-opt/inline/inline_compatibility.inlined_no_sanitize.Inline.diff index 77eb326cd8263..fd9a540ca16e2 100644 --- a/src/test/mir-opt/inline/inline_compatibility.inlined_no_sanitize.Inline.diff +++ b/src/test/mir-opt/inline/inline_compatibility.inlined_no_sanitize.Inline.diff @@ -19,6 +19,10 @@ StorageDead(_1); // scope 0 at $DIR/inline-compatibility.rs:24:18: 24:19 _0 = const (); // scope 0 at $DIR/inline-compatibility.rs:23:37: 25:2 return; // scope 0 at $DIR/inline-compatibility.rs:25:2: 25:2 ++ } ++ ++ bb1 (cleanup): { ++ resume; // scope 0 at $DIR/inline-compatibility.rs:23:1: 25:2 } } diff --git a/src/test/mir-opt/inline/inline_compatibility.inlined_target_feature.Inline.diff b/src/test/mir-opt/inline/inline_compatibility.inlined_target_feature.Inline.diff index a32db48715c23..e7db7aa382fae 100644 --- a/src/test/mir-opt/inline/inline_compatibility.inlined_target_feature.Inline.diff +++ b/src/test/mir-opt/inline/inline_compatibility.inlined_target_feature.Inline.diff @@ -19,6 +19,10 @@ StorageDead(_1); // scope 0 at $DIR/inline-compatibility.rs:13:21: 13:22 _0 = const (); // scope 0 at $DIR/inline-compatibility.rs:12:40: 14:2 return; // scope 0 at $DIR/inline-compatibility.rs:14:2: 14:2 ++ } ++ ++ bb1 (cleanup): { ++ resume; // scope 0 at $DIR/inline-compatibility.rs:12:1: 14:2 } } diff --git a/src/test/mir-opt/inline/inline_cycle.one.Inline.diff b/src/test/mir-opt/inline/inline_cycle.one.Inline.diff index b6615739a2150..b732e7cdb9bf8 100644 --- a/src/test/mir-opt/inline/inline_cycle.one.Inline.diff +++ b/src/test/mir-opt/inline/inline_cycle.one.Inline.diff @@ -22,6 +22,10 @@ StorageDead(_1); // scope 0 at $DIR/inline-cycle.rs:14:24: 14:25 _0 = const (); // scope 0 at $DIR/inline-cycle.rs:13:10: 15:2 return; // scope 0 at $DIR/inline-cycle.rs:15:2: 15:2 ++ } ++ ++ bb2 (cleanup): { ++ resume; // scope 0 at $DIR/inline-cycle.rs:13:1: 15:2 } } diff --git a/src/test/mir-opt/inline/inline_cycle.two.Inline.diff b/src/test/mir-opt/inline/inline_cycle.two.Inline.diff index 4e46156200443..eac5bf8edec4b 100644 --- a/src/test/mir-opt/inline/inline_cycle.two.Inline.diff +++ b/src/test/mir-opt/inline/inline_cycle.two.Inline.diff @@ -41,6 +41,10 @@ StorageDead(_1); // scope 0 at $DIR/inline-cycle.rs:49:12: 49:13 _0 = const (); // scope 0 at $DIR/inline-cycle.rs:48:10: 50:2 return; // scope 0 at $DIR/inline-cycle.rs:50:2: 50:2 ++ } ++ ++ bb2 (cleanup): { ++ resume; // scope 0 at $DIR/inline-cycle.rs:48:1: 50:2 } } diff --git a/src/test/mir-opt/inline/inline_diverging.f.Inline.diff b/src/test/mir-opt/inline/inline_diverging.f.Inline.diff index eb579b53b6c91..ff25c5b4bc337 100644 --- a/src/test/mir-opt/inline/inline_diverging.f.Inline.diff +++ b/src/test/mir-opt/inline/inline_diverging.f.Inline.diff @@ -19,6 +19,10 @@ + + bb1: { + goto -> bb1; // scope 1 at $DIR/inline-diverging.rs:39:5: 39:12 ++ } ++ ++ bb2 (cleanup): { ++ resume; // scope 0 at $DIR/inline-diverging.rs:7:1: 9:2 } } diff --git a/src/test/mir-opt/inline/inline_diverging.g.Inline.diff b/src/test/mir-opt/inline/inline_diverging.g.Inline.diff index 3ce823a0e33ec..da55260e284ea 100644 --- a/src/test/mir-opt/inline/inline_diverging.g.Inline.diff +++ b/src/test/mir-opt/inline/inline_diverging.g.Inline.diff @@ -44,6 +44,10 @@ + // mir::Constant + // + span: $SRC_DIR/std/src/panic.rs:LL:COL + // + literal: Const { ty: &str, val: Value(Slice(..)) } ++ } ++ ++ bb3 (cleanup): { ++ resume; // scope 0 at $DIR/inline-diverging.rs:12:1: 18:2 } } diff --git a/src/test/mir-opt/inline/inline_diverging.h.Inline.diff b/src/test/mir-opt/inline/inline_diverging.h.Inline.diff index 647c27d11e58e..0a19daa5045c9 100644 --- a/src/test/mir-opt/inline/inline_diverging.h.Inline.diff +++ b/src/test/mir-opt/inline/inline_diverging.h.Inline.diff @@ -52,6 +52,10 @@ + + bb1: { + goto -> bb1; // scope 5 at $DIR/inline-diverging.rs:39:5: 39:12 ++ } ++ ++ bb2 (cleanup): { ++ resume; // scope 0 at $DIR/inline-diverging.rs:21:1: 23:2 } } diff --git a/src/test/mir-opt/inline/inline_generator.main.Inline.diff b/src/test/mir-opt/inline/inline_generator.main.Inline.diff index 48432c1ddd8a3..3e1c4a4670143 100644 --- a/src/test/mir-opt/inline/inline_generator.main.Inline.diff +++ b/src/test/mir-opt/inline/inline_generator.main.Inline.diff @@ -30,6 +30,9 @@ + let mut _10: bool; // in scope 6 at $DIR/inline-generator.rs:15:9: 15:9 + let _11: bool; // in scope 6 at $DIR/inline-generator.rs:15:6: 15:7 + let mut _12: u32; // in scope 6 at $DIR/inline-generator.rs:15:5: 15:41 ++ let mut _13: &mut [generator@$DIR/inline-generator.rs:15:5: 15:41]; // in scope 6 at $DIR/inline-generator.rs:15:5: 15:41 ++ let mut _14: &mut [generator@$DIR/inline-generator.rs:15:5: 15:41]; // in scope 6 at $DIR/inline-generator.rs:15:5: 15:41 ++ let mut _15: &mut [generator@$DIR/inline-generator.rs:15:5: 15:41]; // in scope 6 at $DIR/inline-generator.rs:15:5: 15:41 + } bb0: { @@ -73,7 +76,10 @@ + StorageLive(_10); // scope 0 at $DIR/inline-generator.rs:9:14: 9:46 + StorageLive(_11); // scope 0 at $DIR/inline-generator.rs:9:14: 9:46 + StorageLive(_12); // scope 0 at $DIR/inline-generator.rs:9:14: 9:46 -+ _12 = discriminant((*(_2.0: &mut [generator@$DIR/inline-generator.rs:15:5: 15:41]))); // scope 6 at $DIR/inline-generator.rs:15:5: 15:41 ++ StorageLive(_13); // scope 6 at $DIR/inline-generator.rs:15:5: 15:41 ++ _13 = move (_2.0: &mut [generator@$DIR/inline-generator.rs:15:5: 15:41]); // scope 6 at $DIR/inline-generator.rs:15:5: 15:41 ++ _12 = discriminant((*_13)); // scope 6 at $DIR/inline-generator.rs:15:5: 15:41 ++ StorageDead(_13); // scope 6 at $DIR/inline-generator.rs:15:5: 15:41 + switchInt(move _12) -> [0_u32: bb3, 1_u32: bb8, 3_u32: bb7, otherwise: bb9]; // scope 6 at $DIR/inline-generator.rs:15:5: 15:41 } @@ -118,7 +124,10 @@ + Deinit(_1); // scope 6 at $DIR/inline-generator.rs:15:11: 15:39 + ((_1 as Yielded).0: i32) = move _8; // scope 6 at $DIR/inline-generator.rs:15:11: 15:39 + discriminant(_1) = 0; // scope 6 at $DIR/inline-generator.rs:15:11: 15:39 -+ discriminant((*(_2.0: &mut [generator@$DIR/inline-generator.rs:15:5: 15:41]))) = 3; // scope 6 at $DIR/inline-generator.rs:15:11: 15:39 ++ StorageLive(_14); // scope 6 at $DIR/inline-generator.rs:15:11: 15:39 ++ _14 = move (_2.0: &mut [generator@$DIR/inline-generator.rs:15:5: 15:41]); // scope 6 at $DIR/inline-generator.rs:15:11: 15:39 ++ discriminant((*_14)) = 3; // scope 6 at $DIR/inline-generator.rs:15:11: 15:39 ++ StorageDead(_14); // scope 6 at $DIR/inline-generator.rs:15:11: 15:39 + goto -> bb1; // scope 0 at $DIR/inline-generator.rs:15:11: 15:39 + } + @@ -129,7 +138,10 @@ + Deinit(_1); // scope 6 at $DIR/inline-generator.rs:15:41: 15:41 + ((_1 as Complete).0: bool) = move _10; // scope 6 at $DIR/inline-generator.rs:15:41: 15:41 + discriminant(_1) = 1; // scope 6 at $DIR/inline-generator.rs:15:41: 15:41 -+ discriminant((*(_2.0: &mut [generator@$DIR/inline-generator.rs:15:5: 15:41]))) = 1; // scope 6 at $DIR/inline-generator.rs:15:41: 15:41 ++ StorageLive(_15); // scope 6 at $DIR/inline-generator.rs:15:41: 15:41 ++ _15 = move (_2.0: &mut [generator@$DIR/inline-generator.rs:15:5: 15:41]); // scope 6 at $DIR/inline-generator.rs:15:41: 15:41 ++ discriminant((*_15)) = 1; // scope 6 at $DIR/inline-generator.rs:15:41: 15:41 ++ StorageDead(_15); // scope 6 at $DIR/inline-generator.rs:15:41: 15:41 + goto -> bb1; // scope 0 at $DIR/inline-generator.rs:15:41: 15:41 + } + diff --git a/src/test/mir-opt/inline/inline_instruction_set.default.Inline.diff b/src/test/mir-opt/inline/inline_instruction_set.default.Inline.diff index 916244f1f6afb..65891cbb660e1 100644 --- a/src/test/mir-opt/inline/inline_instruction_set.default.Inline.diff +++ b/src/test/mir-opt/inline/inline_instruction_set.default.Inline.diff @@ -39,6 +39,10 @@ StorageDead(_3); // scope 0 at $DIR/inline-instruction-set.rs:53:30: 53:31 _0 = const (); // scope 0 at $DIR/inline-instruction-set.rs:50:18: 54:2 return; // scope 0 at $DIR/inline-instruction-set.rs:54:2: 54:2 ++ } ++ ++ bb3 (cleanup): { ++ resume; // scope 0 at $DIR/inline-instruction-set.rs:50:1: 54:2 } } diff --git a/src/test/mir-opt/inline/inline_instruction_set.t32.Inline.diff b/src/test/mir-opt/inline/inline_instruction_set.t32.Inline.diff index 8907bae9177aa..20e1d0ae4d5da 100644 --- a/src/test/mir-opt/inline/inline_instruction_set.t32.Inline.diff +++ b/src/test/mir-opt/inline/inline_instruction_set.t32.Inline.diff @@ -41,6 +41,10 @@ StorageDead(_3); // scope 0 at $DIR/inline-instruction-set.rs:46:30: 46:31 _0 = const (); // scope 0 at $DIR/inline-instruction-set.rs:41:14: 47:2 return; // scope 0 at $DIR/inline-instruction-set.rs:47:2: 47:2 ++ } ++ ++ bb3 (cleanup): { ++ resume; // scope 0 at $DIR/inline-instruction-set.rs:41:1: 47:2 } } diff --git a/src/test/mir-opt/inline/inline_options.main.Inline.after.mir b/src/test/mir-opt/inline/inline_options.main.Inline.after.mir index 9fd08f141dc76..eca76df576bf6 100644 --- a/src/test/mir-opt/inline/inline_options.main.Inline.after.mir +++ b/src/test/mir-opt/inline/inline_options.main.Inline.after.mir @@ -52,4 +52,8 @@ fn main() -> () { _0 = const (); // scope 0 at $DIR/inline-options.rs:8:11: 11:2 return; // scope 0 at $DIR/inline-options.rs:11:2: 11:2 } + + bb5 (cleanup): { + resume; // scope 0 at $DIR/inline-options.rs:8:1: 11:2 + } } diff --git a/src/test/mir-opt/inline/inline_retag.bar.Inline.after.mir b/src/test/mir-opt/inline/inline_retag.bar.Inline.after.mir index 1aa859484f6f9..2d85ff9a0cbc2 100644 --- a/src/test/mir-opt/inline/inline_retag.bar.Inline.after.mir +++ b/src/test/mir-opt/inline/inline_retag.bar.Inline.after.mir @@ -69,4 +69,8 @@ fn bar() -> bool { StorageDead(_4); // scope 0 at $DIR/inline-retag.rs:13:1: 13:2 return; // scope 0 at $DIR/inline-retag.rs:13:2: 13:2 } + + bb1 (cleanup): { + resume; // scope 0 at $DIR/inline-retag.rs:10:1: 13:2 + } } diff --git a/src/test/mir-opt/inline/inline_shims.clone.Inline.diff b/src/test/mir-opt/inline/inline_shims.clone.Inline.diff index a7e0a52f7438e..7170cd4057200 100644 --- a/src/test/mir-opt/inline/inline_shims.clone.Inline.diff +++ b/src/test/mir-opt/inline/inline_shims.clone.Inline.diff @@ -21,6 +21,10 @@ + _0 = (*_2); // scope 1 at $SRC_DIR/core/src/clone.rs:LL:COL StorageDead(_2); // scope 0 at $DIR/inline-shims.rs:6:13: 6:14 return; // scope 0 at $DIR/inline-shims.rs:7:2: 7:2 ++ } ++ ++ bb1 (cleanup): { ++ resume; // scope 0 at $DIR/inline-shims.rs:5:1: 7:2 } } diff --git a/src/test/mir-opt/inline/inline_shims.drop.Inline.diff b/src/test/mir-opt/inline/inline_shims.drop.Inline.diff index b6d5f51c17306..aa55c90fcfb55 100644 --- a/src/test/mir-opt/inline/inline_shims.drop.Inline.diff +++ b/src/test/mir-opt/inline/inline_shims.drop.Inline.diff @@ -51,6 +51,10 @@ + + bb3: { + drop((((*_5) as Some).0: B)) -> bb2; // scope 3 at $SRC_DIR/core/src/ptr/mod.rs:LL:COL ++ } ++ ++ bb4 (cleanup): { ++ resume; // scope 0 at $DIR/inline-shims.rs:10:1: 13:2 } } diff --git a/src/test/mir-opt/inline/inline_specialization.main.Inline.diff b/src/test/mir-opt/inline/inline_specialization.main.Inline.diff index 97ff6f75f24bd..8e93baf6a7050 100644 --- a/src/test/mir-opt/inline/inline_specialization.main.Inline.diff +++ b/src/test/mir-opt/inline/inline_specialization.main.Inline.diff @@ -23,6 +23,10 @@ _0 = const (); // scope 0 at $DIR/inline-specialization.rs:4:11: 6:2 StorageDead(_1); // scope 0 at $DIR/inline-specialization.rs:6:1: 6:2 return; // scope 0 at $DIR/inline-specialization.rs:6:2: 6:2 ++ } ++ ++ bb1 (cleanup): { ++ resume; // scope 0 at $DIR/inline-specialization.rs:4:1: 6:2 } } diff --git a/src/test/mir-opt/inline/inline_trait_method_2.test2.Inline.after.mir b/src/test/mir-opt/inline/inline_trait_method_2.test2.Inline.after.mir index 9d8818e657ebd..64375b6edc93e 100644 --- a/src/test/mir-opt/inline/inline_trait_method_2.test2.Inline.after.mir +++ b/src/test/mir-opt/inline/inline_trait_method_2.test2.Inline.after.mir @@ -29,4 +29,8 @@ fn test2(_1: &dyn X) -> bool { StorageDead(_2); // scope 0 at $DIR/inline-trait-method_2.rs:5:11: 5:12 return; // scope 0 at $DIR/inline-trait-method_2.rs:6:2: 6:2 } + + bb2 (cleanup): { + resume; // scope 0 at $DIR/inline-trait-method_2.rs:4:1: 6:2 + } } diff --git a/src/test/mir-opt/inline/issue_58867_inline_as_ref_as_mut.a.Inline.after.mir b/src/test/mir-opt/inline/issue_58867_inline_as_ref_as_mut.a.Inline.after.mir index e9c02cf2c6767..56a23cde0c7e1 100644 --- a/src/test/mir-opt/inline/issue_58867_inline_as_ref_as_mut.a.Inline.after.mir +++ b/src/test/mir-opt/inline/issue_58867_inline_as_ref_as_mut.a.Inline.after.mir @@ -27,4 +27,8 @@ fn a(_1: &mut [T]) -> &mut [T] { StorageDead(_2); // scope 0 at $DIR/issue-58867-inline-as-ref-as-mut.rs:4:1: 4:2 return; // scope 0 at $DIR/issue-58867-inline-as-ref-as-mut.rs:4:2: 4:2 } + + bb1 (cleanup): { + resume; // scope 0 at $DIR/issue-58867-inline-as-ref-as-mut.rs:2:1: 4:2 + } } diff --git a/src/test/mir-opt/inline/issue_58867_inline_as_ref_as_mut.b.Inline.after.mir b/src/test/mir-opt/inline/issue_58867_inline_as_ref_as_mut.b.Inline.after.mir index a18ff0e35fe9a..0bb3445a2d0d2 100644 --- a/src/test/mir-opt/inline/issue_58867_inline_as_ref_as_mut.b.Inline.after.mir +++ b/src/test/mir-opt/inline/issue_58867_inline_as_ref_as_mut.b.Inline.after.mir @@ -35,4 +35,8 @@ fn b(_1: &mut Box) -> &mut T { StorageDead(_2); // scope 0 at $DIR/issue-58867-inline-as-ref-as-mut.rs:9:1: 9:2 return; // scope 0 at $DIR/issue-58867-inline-as-ref-as-mut.rs:9:2: 9:2 } + + bb1 (cleanup): { + resume; // scope 0 at $DIR/issue-58867-inline-as-ref-as-mut.rs:7:1: 9:2 + } } diff --git a/src/test/mir-opt/inline/issue_58867_inline_as_ref_as_mut.c.Inline.after.mir b/src/test/mir-opt/inline/issue_58867_inline_as_ref_as_mut.c.Inline.after.mir index 23f33daaa57f2..326b2ad71c0e5 100644 --- a/src/test/mir-opt/inline/issue_58867_inline_as_ref_as_mut.c.Inline.after.mir +++ b/src/test/mir-opt/inline/issue_58867_inline_as_ref_as_mut.c.Inline.after.mir @@ -19,4 +19,8 @@ fn c(_1: &[T]) -> &[T] { StorageDead(_2); // scope 0 at $DIR/issue-58867-inline-as-ref-as-mut.rs:14:1: 14:2 return; // scope 0 at $DIR/issue-58867-inline-as-ref-as-mut.rs:14:2: 14:2 } + + bb1 (cleanup): { + resume; // scope 0 at $DIR/issue-58867-inline-as-ref-as-mut.rs:12:1: 14:2 + } } diff --git a/src/test/mir-opt/inline/issue_58867_inline_as_ref_as_mut.d.Inline.after.mir b/src/test/mir-opt/inline/issue_58867_inline_as_ref_as_mut.d.Inline.after.mir index d079ba59ffc3d..c22852b99f4e9 100644 --- a/src/test/mir-opt/inline/issue_58867_inline_as_ref_as_mut.d.Inline.after.mir +++ b/src/test/mir-opt/inline/issue_58867_inline_as_ref_as_mut.d.Inline.after.mir @@ -23,4 +23,8 @@ fn d(_1: &Box) -> &T { StorageDead(_2); // scope 0 at $DIR/issue-58867-inline-as-ref-as-mut.rs:19:1: 19:2 return; // scope 0 at $DIR/issue-58867-inline-as-ref-as-mut.rs:19:2: 19:2 } + + bb1 (cleanup): { + resume; // scope 0 at $DIR/issue-58867-inline-as-ref-as-mut.rs:17:1: 19:2 + } } diff --git a/src/test/mir-opt/inline/issue_76997_inline_scopes_parenting.main.Inline.after.mir b/src/test/mir-opt/inline/issue_76997_inline_scopes_parenting.main.Inline.after.mir index b9ddbacc0e75b..7c3048a69af61 100644 --- a/src/test/mir-opt/inline/issue_76997_inline_scopes_parenting.main.Inline.after.mir +++ b/src/test/mir-opt/inline/issue_76997_inline_scopes_parenting.main.Inline.after.mir @@ -39,4 +39,8 @@ fn main() -> () { StorageDead(_1); // scope 0 at $DIR/issue-76997-inline-scopes-parenting.rs:7:1: 7:2 return; // scope 0 at $DIR/issue-76997-inline-scopes-parenting.rs:7:2: 7:2 } + + bb1 (cleanup): { + resume; // scope 0 at $DIR/issue-76997-inline-scopes-parenting.rs:4:1: 7:2 + } } diff --git a/src/test/mir-opt/remove_storage_markers.main.RemoveStorageMarkers.diff b/src/test/mir-opt/remove_storage_markers.main.RemoveStorageMarkers.diff index 5131e2f088d3d..447fe654c0cca 100644 --- a/src/test/mir-opt/remove_storage_markers.main.RemoveStorageMarkers.diff +++ b/src/test/mir-opt/remove_storage_markers.main.RemoveStorageMarkers.diff @@ -96,5 +96,9 @@ _10 = discriminant(_7); // scope 2 at $DIR/remove_storage_markers.rs:8:14: 8:19 switchInt(move _10) -> [0_isize: bb3, otherwise: bb2]; // scope 2 at $DIR/remove_storage_markers.rs:8:14: 8:19 } + + bb5 (cleanup): { + resume; // scope 0 at $DIR/remove_storage_markers.rs:6:1: 11:2 + } } diff --git a/src/test/mir-opt/remove_unneeded_drops.opt.RemoveUnneededDrops.diff b/src/test/mir-opt/remove_unneeded_drops.opt.RemoveUnneededDrops.diff index 714136a9e245e..44eda308bdf90 100644 --- a/src/test/mir-opt/remove_unneeded_drops.opt.RemoveUnneededDrops.diff +++ b/src/test/mir-opt/remove_unneeded_drops.opt.RemoveUnneededDrops.diff @@ -22,6 +22,10 @@ StorageDead(_2); // scope 0 at $DIR/remove_unneeded_drops.rs:4:12: 4:13 - nop; // scope 0 at $DIR/remove_unneeded_drops.rs:3:17: 5:2 return; // scope 0 at $DIR/remove_unneeded_drops.rs:5:2: 5:2 +- } +- +- bb2 (cleanup): { +- resume; // scope 0 at $DIR/remove_unneeded_drops.rs:3:1: 5:2 } } diff --git a/src/test/mir-opt/remove_unneeded_drops.opt_generic_copy.RemoveUnneededDrops.diff b/src/test/mir-opt/remove_unneeded_drops.opt_generic_copy.RemoveUnneededDrops.diff index 3dca9f3e1b162..85de00e7001a7 100644 --- a/src/test/mir-opt/remove_unneeded_drops.opt_generic_copy.RemoveUnneededDrops.diff +++ b/src/test/mir-opt/remove_unneeded_drops.opt_generic_copy.RemoveUnneededDrops.diff @@ -22,6 +22,10 @@ StorageDead(_2); // scope 0 at $DIR/remove_unneeded_drops.rs:14:12: 14:13 - nop; // scope 0 at $DIR/remove_unneeded_drops.rs:13:36: 15:2 return; // scope 0 at $DIR/remove_unneeded_drops.rs:15:2: 15:2 +- } +- +- bb2 (cleanup): { +- resume; // scope 0 at $DIR/remove_unneeded_drops.rs:13:1: 15:2 } } diff --git a/src/test/mir-opt/simplify_arm.id_try.SimplifyArmIdentity.diff b/src/test/mir-opt/simplify_arm.id_try.SimplifyArmIdentity.diff index 5da2ad1a27dc9..d2dbfbe1093a8 100644 --- a/src/test/mir-opt/simplify_arm.id_try.SimplifyArmIdentity.diff +++ b/src/test/mir-opt/simplify_arm.id_try.SimplifyArmIdentity.diff @@ -85,5 +85,9 @@ bb4: { return; // scope 0 at $DIR/simplify-arm.rs:41:2: 41:2 } + + bb5 (cleanup): { + resume; // scope 0 at $DIR/simplify-arm.rs:35:1: 41:2 + } } diff --git a/src/test/mir-opt/simplify_arm.id_try.SimplifyBranchSame.diff b/src/test/mir-opt/simplify_arm.id_try.SimplifyBranchSame.diff index 528828ad075ad..a993ea73665c4 100644 --- a/src/test/mir-opt/simplify_arm.id_try.SimplifyBranchSame.diff +++ b/src/test/mir-opt/simplify_arm.id_try.SimplifyBranchSame.diff @@ -85,5 +85,9 @@ bb4: { return; // scope 0 at $DIR/simplify-arm.rs:41:2: 41:2 } + + bb5 (cleanup): { + resume; // scope 0 at $DIR/simplify-arm.rs:35:1: 41:2 + } }