diff options
| author | dianqk <dianqk@dianqk.net> | 2025-05-22 22:55:27 +0800 |
|---|---|---|
| committer | dianqk <dianqk@dianqk.net> | 2025-05-24 11:01:18 +0800 |
| commit | 145d2266d930d8d8b4119eb230590269d0626c05 (patch) | |
| tree | cf3f3dc1cfa659afa0d20920b18889aefefb3cf9 /compiler/rustc_mir_transform/src | |
| parent | 80c34983c63968c204096e79b9126c0039790741 (diff) | |
| download | rust-145d2266d930d8d8b4119eb230590269d0626c05.tar.gz rust-145d2266d930d8d8b4119eb230590269d0626c05.zip | |
mir-opt: Create an indirect BB to add `StorageDead`
Diffstat (limited to 'compiler/rustc_mir_transform/src')
| -rw-r--r-- | compiler/rustc_mir_transform/src/early_otherwise_branch.rs | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/compiler/rustc_mir_transform/src/early_otherwise_branch.rs b/compiler/rustc_mir_transform/src/early_otherwise_branch.rs index c7feb9e949b..e7cd74a1f54 100644 --- a/compiler/rustc_mir_transform/src/early_otherwise_branch.rs +++ b/compiler/rustc_mir_transform/src/early_otherwise_branch.rs @@ -193,8 +193,20 @@ impl<'tcx> crate::MirPass<'tcx> for EarlyOtherwiseBranch { let eq_bb = patch.new_block(eq_switch); // Jump to it on the basis of the inequality comparison - let true_case = opt_data.destination; - let false_case = eq_bb; + let mut true_case = opt_data.destination; + let mut false_case = eq_bb; + // Create an indirect BB to add `StorageDead` If the jump target is itself. + for bb in [&mut false_case, &mut true_case].into_iter() { + if *bb == parent { + *bb = patch.new_block(BasicBlockData::new( + Some(Terminator { + kind: TerminatorKind::Goto { target: parent }, + source_info: bbs[parent].terminator().source_info, + }), + bbs[parent].is_cleanup, + )); + } + } patch.patch_terminator( parent, TerminatorKind::if_(Operand::Move(Place::from(comp_temp)), true_case, false_case), @@ -210,9 +222,9 @@ impl<'tcx> crate::MirPass<'tcx> for EarlyOtherwiseBranch { // Generate a StorageDead for comp_temp in each of the targets, since we moved it into // the switch - for bb in [false_case, true_case].iter() { + for bb in [false_case, true_case].into_iter() { patch.add_statement( - Location { block: *bb, statement_index: 0 }, + Location { block: bb, statement_index: 0 }, StatementKind::StorageDead(comp_temp), ); } |
