Skip to content

Commit 9d648ac

Browse files
committed
Stop invalidating in CleanupPostBorrowck.
1 parent 0c0f27a commit 9d648ac

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

compiler/rustc_mir_transform/src/cleanup_post_borrowck.rs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,27 @@
1717
//! [`SpanMarker`]: rustc_middle::mir::coverage::CoverageKind::SpanMarker
1818
1919
use rustc_middle::mir::coverage::CoverageKind;
20-
use rustc_middle::mir::{Body, BorrowKind, CastKind, Rvalue, StatementKind, TerminatorKind};
20+
use rustc_middle::mir::*;
2121
use rustc_middle::ty::TyCtxt;
2222
use rustc_middle::ty::adjustment::PointerCoercion;
2323

2424
pub(super) struct CleanupPostBorrowck;
2525

2626
impl<'tcx> crate::MirPass<'tcx> for CleanupPostBorrowck {
2727
fn run_pass(&self, _tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
28-
for basic_block in body.basic_blocks.as_mut() {
28+
let any_false_edge = body.basic_blocks.iter().any(|basic_block| {
29+
matches!(
30+
basic_block.terminator().kind,
31+
TerminatorKind::FalseEdge { .. } | TerminatorKind::FalseUnwind { .. }
32+
)
33+
});
34+
35+
let basic_blocks = if any_false_edge {
36+
body.basic_blocks.as_mut()
37+
} else {
38+
body.basic_blocks.as_mut_preserves_cfg()
39+
};
40+
for basic_block in basic_blocks.iter_mut() {
2941
for statement in basic_block.statements.iter_mut() {
3042
match statement.kind {
3143
StatementKind::AscribeUserType(..)
@@ -59,10 +71,14 @@ impl<'tcx> crate::MirPass<'tcx> for CleanupPostBorrowck {
5971
_ => (),
6072
}
6173
}
74+
75+
// If we change any terminator, we need to ensure that we invalidated the CFG cache.
76+
// This is tracked by `any_false_edge` flag above.
6277
let terminator = basic_block.terminator_mut();
6378
match terminator.kind {
6479
TerminatorKind::FalseEdge { real_target, .. }
6580
| TerminatorKind::FalseUnwind { real_target, .. } => {
81+
debug_assert!(any_false_edge);
6682
terminator.kind = TerminatorKind::Goto { target: real_target };
6783
}
6884
_ => {}

0 commit comments

Comments
 (0)