Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When deduplicating unreachable blocks, erase the source information. #128628

Merged
merged 1 commit into from
Aug 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions compiler/rustc_mir_transform/src/simplify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ use rustc_index::{Idx, IndexSlice, IndexVec};
use rustc_middle::mir::visit::{MutVisitor, MutatingUseContext, PlaceContext, Visitor};
use rustc_middle::mir::*;
use rustc_middle::ty::TyCtxt;
use rustc_span::DUMMY_SP;
use smallvec::SmallVec;

pub enum SimplifyCfg {
Expand Down Expand Up @@ -318,6 +319,7 @@ pub(crate) fn remove_dead_blocks(body: &mut Body<'_>) {
let mut orig_index = 0;
let mut used_index = 0;
let mut kept_unreachable = None;
let mut deduplicated_unreachable = false;
basic_blocks.raw.retain(|bbdata| {
let orig_bb = BasicBlock::new(orig_index);
if !reachable.contains(orig_bb) {
Expand All @@ -330,6 +332,7 @@ pub(crate) fn remove_dead_blocks(body: &mut Body<'_>) {
let kept_unreachable = *kept_unreachable.get_or_insert(used_bb);
if kept_unreachable != used_bb {
replacements[orig_index] = kept_unreachable;
deduplicated_unreachable = true;
orig_index += 1;
return false;
}
Expand All @@ -341,6 +344,14 @@ pub(crate) fn remove_dead_blocks(body: &mut Body<'_>) {
true
});

// If we deduplicated unreachable blocks we erase their source_info as we
// can no longer attribute their code to a particular location in the
// source.
if deduplicated_unreachable {
basic_blocks[kept_unreachable.unwrap()].terminator_mut().source_info =
SourceInfo { span: DUMMY_SP, scope: OUTERMOST_SOURCE_SCOPE };
}

for block in basic_blocks {
for target in block.terminator_mut().successors_mut() {
*target = replacements[target.index()];
Expand Down
Loading