Skip to content

Commit 2eeaff4

Browse files
authored
Unrolled build for rust-lang#128628
Rollup merge of rust-lang#128628 - khuey:simply-cfg-erase-source-info, r=nnethercote When deduplicating unreachable blocks, erase the source information. After deduplication the block conceptually belongs to multiple locations in the source. Although these blocks are unreachable, in rust-lang#123341 we did come across a real side effect, an unreachable block that survives into the compiled code can cause a debugger to set a breakpoint on the wrong instruction. Erasing the source information ensures that a debugger will never be misled into thinking that the unreachable block is worth setting a breakpoint on, especially after rust-lang#128627. Technically we don't need to erase the source information if all the deduplicated blocks have identical source information, but tracking that seems like more effort than it's worth. I'll let njn redirect this one too. r? `@nnethercote`
2 parents 804be74 + 709406f commit 2eeaff4

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

compiler/rustc_mir_transform/src/simplify.rs

+11
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ use rustc_index::{Idx, IndexSlice, IndexVec};
3131
use rustc_middle::mir::visit::{MutVisitor, MutatingUseContext, PlaceContext, Visitor};
3232
use rustc_middle::mir::*;
3333
use rustc_middle::ty::TyCtxt;
34+
use rustc_span::DUMMY_SP;
3435
use smallvec::SmallVec;
3536

3637
pub enum SimplifyCfg {
@@ -318,6 +319,7 @@ pub(crate) fn remove_dead_blocks(body: &mut Body<'_>) {
318319
let mut orig_index = 0;
319320
let mut used_index = 0;
320321
let mut kept_unreachable = None;
322+
let mut deduplicated_unreachable = false;
321323
basic_blocks.raw.retain(|bbdata| {
322324
let orig_bb = BasicBlock::new(orig_index);
323325
if !reachable.contains(orig_bb) {
@@ -330,6 +332,7 @@ pub(crate) fn remove_dead_blocks(body: &mut Body<'_>) {
330332
let kept_unreachable = *kept_unreachable.get_or_insert(used_bb);
331333
if kept_unreachable != used_bb {
332334
replacements[orig_index] = kept_unreachable;
335+
deduplicated_unreachable = true;
333336
orig_index += 1;
334337
return false;
335338
}
@@ -341,6 +344,14 @@ pub(crate) fn remove_dead_blocks(body: &mut Body<'_>) {
341344
true
342345
});
343346

347+
// If we deduplicated unreachable blocks we erase their source_info as we
348+
// can no longer attribute their code to a particular location in the
349+
// source.
350+
if deduplicated_unreachable {
351+
basic_blocks[kept_unreachable.unwrap()].terminator_mut().source_info =
352+
SourceInfo { span: DUMMY_SP, scope: OUTERMOST_SOURCE_SCOPE };
353+
}
354+
344355
for block in basic_blocks {
345356
for target in block.terminator_mut().successors_mut() {
346357
*target = replacements[target.index()];

0 commit comments

Comments
 (0)