Skip to content

Commit 0c0cf47

Browse files
committed
Replace locals in debuginfo records during ref_prop
1 parent a31c7c3 commit 0c0cf47

File tree

4 files changed

+23
-3
lines changed

4 files changed

+23
-3
lines changed

compiler/rustc_mir_transform/src/ref_prop.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,20 @@ impl<'tcx> MutVisitor<'tcx> for Replacer<'tcx> {
407407
self.super_var_debug_info(debuginfo);
408408
}
409409

410+
fn visit_statement_debuginfo(
411+
&mut self,
412+
stmt_debuginfo: &mut StmtDebugInfo<'tcx>,
413+
location: Location,
414+
) {
415+
if let StmtDebugInfo::AssignRef(local, _) = stmt_debuginfo
416+
&& let Value::Pointer(target, _) = self.targets[*local]
417+
{
418+
*local = target.local;
419+
self.any_replacement = true;
420+
}
421+
self.super_statement_debuginfo(stmt_debuginfo, location);
422+
}
423+
410424
fn visit_place(&mut self, place: &mut Place<'tcx>, ctxt: PlaceContext, loc: Location) {
411425
loop {
412426
let Some((&PlaceElem::Deref, rest)) = place.projection.split_first() else { return };

tests/mir-opt/debuginfo/ref_prop.remap_debuginfo_locals.ReferencePropagation.diff

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
- StorageDead(_2);
2626
- StorageDead(_3);
2727
- StorageDead(_1);
28-
+ // DBG: _1 = &(*_5);
28+
+ // DBG: _5 = &(*_5);
2929
_0 = const ();
3030
return;
3131
}

tests/mir-opt/debuginfo/ref_prop.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// skip-filecheck
21
//@ test-mir-pass: ReferencePropagation
32
//@ compile-flags: -g -Zub_checks=false -Zinline-mir -Zmir-enable-passes=+DeadStoreElimination-initial
43

@@ -9,6 +8,11 @@ use std::intrinsics::mir::*;
98

109
// EMIT_MIR ref_prop.remap_debuginfo_locals.ReferencePropagation.diff
1110
pub fn remap_debuginfo_locals() {
11+
// CHECK-LABEL: fn remap_debuginfo_locals()
12+
// CHECK: debug a => [[a:_.*]];
13+
// CHECK: bb0:
14+
// CHECK-NEXT: [[a]] = const
15+
// CHECK-NEXT: DBG: [[a]] = &(*[[a]]);
1216
foo(&0);
1317
}
1418

tests/crashes/147485.rs renamed to tests/ui/debuginfo/ref_prop_debuginfo-147485.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
//@ known-bug: #147485
1+
//@ build-pass
22
//@ compile-flags: -g -O
33

4+
// Regression test for #147485.
5+
46
#![crate_type = "lib"]
57

68
pub fn f(x: *const usize) -> &'static usize {

0 commit comments

Comments
 (0)