Skip to content

Commit c427438

Browse files
committed
sync alloc dump and pointer printing
1 parent ec1f28f commit c427438

File tree

8 files changed

+51
-48
lines changed

8 files changed

+51
-48
lines changed

src/librustc_mir/interpret/memory.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -672,7 +672,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
672672
/// control for this.
673673
pub fn dump_allocs(&self, mut allocs: Vec<AllocId>) {
674674
// Cannot be a closure because it is generic in `Tag`, `Extra`.
675-
fn write_allocation_track_relocs<'tcx, Tag, Extra>(
675+
fn write_allocation_track_relocs<'tcx, Tag: Copy + fmt::Debug, Extra>(
676676
tcx: TyCtxtAt<'tcx>,
677677
allocs_to_print: &mut VecDeque<AllocId>,
678678
alloc: &Allocation<Tag, Extra>,

src/librustc_mir/util/pretty.rs

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
1+
use std::collections::BTreeSet;
2+
use std::fmt::{Debug, Display};
3+
use std::fmt::Write as _;
4+
use std::fs;
5+
use std::io::{self, Write};
6+
use std::path::{Path, PathBuf};
7+
18
use super::graphviz::write_mir_fn_graphviz;
29
use crate::transform::MirSource;
310
use either::Either;
411
use rustc_data_structures::fx::FxHashMap;
512
use rustc_hir::def_id::{DefId, LOCAL_CRATE};
613
use rustc_index::vec::Idx;
714
use rustc_middle::mir::interpret::{
8-
read_target_uint, AllocId, Allocation, ConstValue, GlobalAlloc,
15+
read_target_uint, AllocId, Allocation, ConstValue, GlobalAlloc, Pointer,
916
};
1017
use rustc_middle::mir::visit::Visitor;
1118
use rustc_middle::mir::*;
1219
use rustc_middle::ty::{self, TyCtxt, TypeFoldable, TypeVisitor};
1320
use rustc_target::abi::Size;
14-
use std::collections::BTreeSet;
15-
use std::fmt::Display;
16-
use std::fmt::Write as _;
17-
use std::fs;
18-
use std::io::{self, Write};
19-
use std::path::{Path, PathBuf};
2021

2122
const INDENT: &str = " ";
2223
/// Alignment for lining up comments following MIR statements
@@ -635,7 +636,7 @@ pub fn write_allocations<'tcx>(
635636
/// After the hex dump, an ascii dump follows, replacing all unprintable characters (control
636637
/// characters or characters whose value is larger than 127) with a `.`
637638
/// This also prints relocations adequately.
638-
pub fn write_allocation<Tag, Extra>(
639+
pub fn write_allocation<Tag: Copy + Debug, Extra>(
639640
tcx: TyCtxt<'tcx>,
640641
alloc: &Allocation<Tag, Extra>,
641642
w: &mut dyn Write,
@@ -679,7 +680,7 @@ fn write_allocation_newline(
679680
/// The `prefix` argument allows callers to add an arbitrary prefix before each line (even if there
680681
/// is only one line). Note that your prefix should contain a trailing space as the lines are
681682
/// printed directly after it.
682-
fn write_allocation_bytes<Tag, Extra>(
683+
fn write_allocation_bytes<Tag: Copy + Debug, Extra>(
683684
tcx: TyCtxt<'tcx>,
684685
alloc: &Allocation<Tag, Extra>,
685686
w: &mut dyn Write,
@@ -715,14 +716,16 @@ fn write_allocation_bytes<Tag, Extra>(
715716
if i != line_start {
716717
write!(w, " ")?;
717718
}
718-
if let Some(&(_, target_id)) = alloc.relocations().get(&i) {
719+
if let Some(&(tag, target_id)) = alloc.relocations().get(&i) {
719720
// Memory with a relocation must be defined
720721
let j = i.bytes_usize();
721722
let offset =
722723
alloc.inspect_with_undef_and_ptr_outside_interpreter(j..j + ptr_size.bytes_usize());
723724
let offset = read_target_uint(tcx.data_layout.endian, offset).unwrap();
725+
let offset = Size::from_bytes(offset);
724726
let relocation_width = |bytes| bytes * 3;
725-
let mut target = format!("{}+{}", target_id, offset);
727+
let ptr = Pointer::new_with_tag(target_id, offset, tag);
728+
let mut target = format!("{:?}", ptr);
726729
if ((i - line_start) + ptr_size).bytes_usize() > BYTES_PER_LINE {
727730
// This branch handles the situation where a relocation starts in the current line
728731
// but ends in the next one.

src/test/mir-opt/const_allocation/32bit/rustc.main.ConstProp.after.mir

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,19 @@ fn main() -> () {
3030
}
3131

3232
alloc0 (static: FOO, size: 8, align: 4) {
33-
╾alloc17+0╼ 03 00 00 00 │ ╾──╼....
33+
╾alloc17+0x0 (4 ptr bytes)╼ 03 00 00 00 │ ╾──╼....
3434
}
3535

3636
alloc17 (size: 48, align: 4) {
37-
0x00 │ 00 00 00 00 __ __ __ __ ╾alloc4+0─╼ 00 00 00 00 │ ....░░░░╾──╼....
38-
0x10 │ 00 00 00 00 __ __ __ __ ╾alloc8+0─╼ 02 00 00 00 │ ....░░░░╾──╼....
39-
0x20 │ 01 00 00 00 2a 00 00 00 ╾alloc13+0╼ 03 00 00 00 │ ....*...╾──╼....
37+
0x00 │ 00 00 00 00 __ __ __ __ ╾alloc4+0x0 (4 ptr bytes)╼ 00 00 00 00 │ ....░░░░╾──╼....
38+
0x10 │ 00 00 00 00 __ __ __ __ ╾alloc8+0x0 (4 ptr bytes)╼ 02 00 00 00 │ ....░░░░╾──╼....
39+
0x20 │ 01 00 00 00 2a 00 00 00 ╾alloc13+0x0 (4 ptr bytes)╼ 03 00 00 00 │ ....*...╾──╼....
4040
}
4141

4242
alloc4 (size: 0, align: 4) {}
4343

4444
alloc8 (size: 16, align: 4) {
45-
╾alloc7+0─╼ 03 00 00 00 ╾alloc9+0─╼ 03 00 00 00 │ ╾──╼....╾──╼....
45+
╾alloc7+0x0 (4 ptr bytes)╼ 03 00 00 00 ╾alloc9+0x0 (4 ptr bytes)╼ 03 00 00 00 │ ╾──╼....╾──╼....
4646
}
4747

4848
alloc7 (size: 3, align: 1) {
@@ -54,8 +54,8 @@ alloc9 (size: 3, align: 1) {
5454
}
5555

5656
alloc13 (size: 24, align: 4) {
57-
0x00 │ ╾alloc12+0╼ 03 00 00 00 ╾alloc14+0╼ 03 00 00 00 │ ╾──╼....╾──╼....
58-
0x10 │ ╾alloc15+0╼ 04 00 00 00 │ ╾──╼....
57+
0x00 │ ╾alloc12+0x0 (4 ptr bytes)╼ 03 00 00 00 ╾alloc14+0x0 (4 ptr bytes)╼ 03 00 00 00 │ ╾──╼....╾──╼....
58+
0x10 │ ╾alloc15+0x0 (4 ptr bytes)╼ 04 00 00 00 │ ╾──╼....
5959
}
6060

6161
alloc12 (size: 3, align: 1) {

src/test/mir-opt/const_allocation/64bit/rustc.main.ConstProp.after.mir

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,22 +30,22 @@ fn main() -> () {
3030
}
3131

3232
alloc0 (static: FOO, size: 16, align: 8) {
33-
╾─────alloc17+0──────╼ 03 00 00 00 00 00 00 00 │ ╾──────╼........
33+
╾─────alloc17+0x0─────╼ 03 00 00 00 00 00 00 00 │ ╾──────╼........
3434
}
3535

3636
alloc17 (size: 72, align: 8) {
37-
0x00 │ 00 00 00 00 __ __ __ __ ╾─────alloc4+0───────╼ │ ....░░░░╾──────╼
37+
0x00 │ 00 00 00 00 __ __ __ __ ╾─────alloc4+0x0──────╼ │ ....░░░░╾──────╼
3838
0x10 │ 00 00 00 00 00 00 00 00 00 00 00 00 __ __ __ __ │ ............░░░░
39-
0x20 │ ╾─────alloc8+0───────╼ 02 00 00 00 00 00 00 00 │ ╾──────╼........
40-
0x30 │ 01 00 00 00 2a 00 00 00 ╾─────alloc13+0──────╼ │ ....*...╾──────╼
39+
0x20 │ ╾─────alloc8+0x0──────╼ 02 00 00 00 00 00 00 00 │ ╾──────╼........
40+
0x30 │ 01 00 00 00 2a 00 00 00 ╾─────alloc13+0x0─────╼ │ ....*...╾──────╼
4141
0x40 │ 03 00 00 00 00 00 00 00 │ ........
4242
}
4343

4444
alloc4 (size: 0, align: 8) {}
4545

4646
alloc8 (size: 32, align: 8) {
47-
0x00 │ ╾─────alloc7+0───────╼ 03 00 00 00 00 00 00 00 │ ╾──────╼........
48-
0x10 │ ╾─────alloc9+0───────╼ 03 00 00 00 00 00 00 00 │ ╾──────╼........
47+
0x00 │ ╾─────alloc7+0x0──────╼ 03 00 00 00 00 00 00 00 │ ╾──────╼........
48+
0x10 │ ╾─────alloc9+0x0──────╼ 03 00 00 00 00 00 00 00 │ ╾──────╼........
4949
}
5050

5151
alloc7 (size: 3, align: 1) {
@@ -57,9 +57,9 @@ alloc9 (size: 3, align: 1) {
5757
}
5858

5959
alloc13 (size: 48, align: 8) {
60-
0x00 │ ╾─────alloc12+0──────╼ 03 00 00 00 00 00 00 00 │ ╾──────╼........
61-
0x10 │ ╾─────alloc14+0──────╼ 03 00 00 00 00 00 00 00 │ ╾──────╼........
62-
0x20 │ ╾─────alloc15+0──────╼ 04 00 00 00 00 00 00 00 │ ╾──────╼........
60+
0x00 │ ╾─────alloc12+0x0─────╼ 03 00 00 00 00 00 00 00 │ ╾──────╼........
61+
0x10 │ ╾─────alloc14+0x0─────╼ 03 00 00 00 00 00 00 00 │ ╾──────╼........
62+
0x20 │ ╾─────alloc15+0x0─────╼ 04 00 00 00 00 00 00 00 │ ╾──────╼........
6363
}
6464

6565
alloc12 (size: 3, align: 1) {

src/test/mir-opt/const_allocation2/32bit/rustc.main.ConstProp.after.mir

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,19 @@ fn main() -> () {
3030
}
3131

3232
alloc0 (static: FOO, size: 8, align: 4) {
33-
╾alloc21+0╼ 03 00 00 00 │ ╾──╼....
33+
╾alloc21+0x0 (4 ptr bytes)╼ 03 00 00 00 │ ╾──╼....
3434
}
3535

3636
alloc21 (size: 48, align: 4) {
37-
0x00 │ 00 00 00 00 __ __ __ __ ╾alloc4+0─╼ 00 00 00 00 │ ....░░░░╾──╼....
38-
0x10 │ 00 00 00 00 __ __ __ __ ╾alloc9+0─╼ 02 00 00 00 │ ....░░░░╾──╼....
39-
0x20 │ 01 00 00 00 2a 00 00 00 ╾alloc19+0╼ 03 00 00 00 │ ....*...╾──╼....
37+
0x00 │ 00 00 00 00 __ __ __ __ ╾alloc4+0x0 (4 ptr bytes)╼ 00 00 00 00 │ ....░░░░╾──╼....
38+
0x10 │ 00 00 00 00 __ __ __ __ ╾alloc9+0x0 (4 ptr bytes)╼ 02 00 00 00 │ ....░░░░╾──╼....
39+
0x20 │ 01 00 00 00 2a 00 00 00 ╾alloc19+0x0 (4 ptr bytes)╼ 03 00 00 00 │ ....*...╾──╼....
4040
}
4141

4242
alloc4 (size: 0, align: 4) {}
4343

4444
alloc9 (size: 8, align: 4) {
45-
╾alloc7+0─╼ ╾alloc8+0─╼ │ ╾──╼╾──╼
45+
╾alloc7+0x0 (4 ptr bytes)╼ ╾alloc8+0x0 (4 ptr bytes)╼ │ ╾──╼╾──╼
4646
}
4747

4848
alloc7 (size: 1, align: 1) {
@@ -54,7 +54,7 @@ alloc8 (size: 1, align: 1) {
5454
}
5555

5656
alloc19 (size: 12, align: 4) {
57-
╾alloc15+3╼ ╾alloc16+0╼ ╾alloc18+2╼ │ ╾──╼╾──╼╾──╼
57+
╾alloc15+0x3 (4 ptr bytes)╼ ╾alloc16+0x0 (4 ptr bytes)╼ ╾alloc18+0x2 (4 ptr bytes)╼ │ ╾──╼╾──╼╾──╼
5858
}
5959

6060
alloc15 (size: 4, align: 1) {

src/test/mir-opt/const_allocation2/64bit/rustc.main.ConstProp.after.mir

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,21 +30,21 @@ fn main() -> () {
3030
}
3131

3232
alloc0 (static: FOO, size: 16, align: 8) {
33-
╾─────alloc21+0──────╼ 03 00 00 00 00 00 00 00 │ ╾──────╼........
33+
╾─────alloc21+0x0─────╼ 03 00 00 00 00 00 00 00 │ ╾──────╼........
3434
}
3535

3636
alloc21 (size: 72, align: 8) {
37-
0x00 │ 00 00 00 00 __ __ __ __ ╾─────alloc4+0───────╼ │ ....░░░░╾──────╼
37+
0x00 │ 00 00 00 00 __ __ __ __ ╾─────alloc4+0x0──────╼ │ ....░░░░╾──────╼
3838
0x10 │ 00 00 00 00 00 00 00 00 00 00 00 00 __ __ __ __ │ ............░░░░
39-
0x20 │ ╾─────alloc9+0───────╼ 02 00 00 00 00 00 00 00 │ ╾──────╼........
40-
0x30 │ 01 00 00 00 2a 00 00 00 ╾─────alloc19+0──────╼ │ ....*...╾──────╼
39+
0x20 │ ╾─────alloc9+0x0──────╼ 02 00 00 00 00 00 00 00 │ ╾──────╼........
40+
0x30 │ 01 00 00 00 2a 00 00 00 ╾─────alloc19+0x0─────╼ │ ....*...╾──────╼
4141
0x40 │ 03 00 00 00 00 00 00 00 │ ........
4242
}
4343

4444
alloc4 (size: 0, align: 8) {}
4545

4646
alloc9 (size: 16, align: 8) {
47-
╾─────alloc7+0──────╼ ╾─────alloc8+0───────╼ │ ╾──────╼╾──────╼
47+
╾─────alloc7+0x0──────╼ ╾─────alloc8+0x0──────╼ │ ╾──────╼╾──────╼
4848
}
4949

5050
alloc7 (size: 1, align: 1) {
@@ -56,8 +56,8 @@ alloc8 (size: 1, align: 1) {
5656
}
5757

5858
alloc19 (size: 24, align: 8) {
59-
0x00 │ ╾─────alloc15+3─────╼ ╾─────alloc16+0──────╼ │ ╾──────╼╾──────╼
60-
0x10 │ ╾─────alloc18+2──────╼ │ ╾──────╼
59+
0x00 │ ╾─────alloc15+0x3─────╼ ╾─────alloc16+0x0─────╼ │ ╾──────╼╾──────╼
60+
0x10 │ ╾─────alloc18+0x2─────╼ │ ╾──────╼
6161
}
6262

6363
alloc15 (size: 4, align: 1) {

src/test/mir-opt/const_allocation3/32bit/rustc.main.ConstProp.after.mir

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,20 @@ fn main() -> () {
3030
}
3131

3232
alloc0 (static: FOO, size: 4, align: 4) {
33-
╾alloc9+0─╼ │ ╾──╼
33+
╾alloc9+0x0 (4 ptr bytes)╼ │ ╾──╼
3434
}
3535

3636
alloc9 (size: 168, align: 1) {
3737
0x00 │ ab ab ab ab ab ab ab ab ab ab ab ab ab ab ab ab │ ................
38-
0x10 │ ab ab ab ab ab ab ab ab ab ab ab ab ╾alloc4+0─╼ │ ............╾──╼
38+
0x10 │ ab ab ab ab ab ab ab ab ab ab ab ab ╾alloc4+0x0 (4 ptr bytes)╼ │ ............╾──╼
3939
0x20 │ 01 ef cd ab 00 00 00 00 00 00 00 00 00 00 00 00 │ ................
4040
0x30 │ 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 │ ................
4141
0x40 │ 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 │ ................
4242
0x50 │ 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 │ ................
4343
0x60 │ 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 │ ................
4444
0x70 │ 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 │ ................
45-
0x80 │ 00 00 00 00 00 00 00 00 00 00 ╾alloc6+0─╼ 00 00 │ ..........╾──╼..
46-
0x90 │ ╾alloc7+99╼ 00 00 00 00 00 00 00 00 00 00 00 00 │ ╾──╼............
45+
0x80 │ 00 00 00 00 00 00 00 00 00 00 ╾alloc6+0x0 (4 ptr bytes)╼ 00 00 │ ..........╾──╼..
46+
0x90 │ ╾alloc7+0x63 (4 ptr bytes)╼ 00 00 00 00 00 00 00 00 00 00 00 00 │ ╾──╼............
4747
0xa0 │ 00 00 00 00 00 00 00 00 │ ........
4848
}
4949

src/test/mir-opt/const_allocation3/64bit/rustc.main.ConstProp.after.mir

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,20 @@ fn main() -> () {
3030
}
3131

3232
alloc0 (static: FOO, size: 8, align: 8) {
33-
╾─────alloc9+0───────╼ │ ╾──────╼
33+
╾─────alloc9+0x0──────╼ │ ╾──────╼
3434
}
3535

3636
alloc9 (size: 180, align: 1) {
3737
0x00 │ ab ab ab ab ab ab ab ab ab ab ab ab ab ab ab ab │ ................
38-
0x10 │ ab ab ab ab ab ab ab ab ab ab ab ab ╾alloc4+0─ │ ............╾───
38+
0x10 │ ab ab ab ab ab ab ab ab ab ab ab ab ╾alloc4+0x0 │ ............╾───
3939
0x20 │ ──────────╼ 01 ef cd ab 00 00 00 00 00 00 00 00 │ ───╼............
4040
0x30 │ 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 │ ................
4141
0x40 │ 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 │ ................
4242
0x50 │ 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 │ ................
4343
0x60 │ 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 │ ................
4444
0x70 │ 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 │ ................
4545
0x80 │ 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ╾──── │ ..............╾─
46-
0x90 │ ───alloc6+0───╼ 00 00 ╾─────alloc7+99──────╼ │ ─────╼..╾──────╼
46+
0x90 │ ───alloc6+0x0───╼ 00 00 ╾─────alloc7+0x63─────╼ │ ─────╼..╾──────╼
4747
0xa0 │ 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 │ ................
4848
0xb0 │ 00 00 00 00 │ ....
4949
}

0 commit comments

Comments
 (0)