Skip to content

Commit

Permalink
Auto merge of rust-lang#116767 - cjgillot:alloc-normalize, r=oli-obk
Browse files Browse the repository at this point in the history
Normalize alloc-id in tests.

AllocIds are globally numbered in a rustc invocation. This makes them very sensitive to changes unrelated to what is being tested. This commit normalizes them by renumbering, in order of appearance in the output.

The renumbering allows to keep the identity, that a simple `allocN` wouldn't. This is useful when we have memory dumps.

cc `@saethlin`
r? `@oli-obk`
  • Loading branch information
bors committed Oct 16, 2023
2 parents 9ace9da + a8d90ba commit 1c5c949
Show file tree
Hide file tree
Showing 98 changed files with 308 additions and 278 deletions.
1 change: 1 addition & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -697,6 +697,7 @@ dependencies = [
"getopts",
"glob",
"home",
"indexmap 2.0.0",
"lazycell",
"libc",
"miow",
Expand Down
1 change: 1 addition & 0 deletions src/tools/compiletest/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ colored = "2"
diff = "0.1.10"
unified-diff = "0.2.1"
getopts = "0.2"
indexmap = "2.0.0"
miropt-test-tools = { path = "../miropt-test-tools" }
build_helper = { path = "../build_helper" }
tracing = "0.1"
Expand Down
28 changes: 28 additions & 0 deletions src/tools/compiletest/src/runtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4258,6 +4258,34 @@ impl<'test> TestCx<'test> {
V0_BACK_REF_RE.replace_all(&normalized, V0_BACK_REF_PLACEHOLDER).into_owned();
}

// Normalize AllocId counter
{
use std::fmt::Write;

let re = Regex::new(r"(╾a|─a|\balloc)([0-9]+)\b(─|\+0x[0-9]+─)?").unwrap();
let mut seen_allocs = indexmap::IndexSet::new();
normalized = re
.replace_all(&normalized, |caps: &Captures<'_>| {
// Use uppercase to distinguish with the non-normalized version.
let mut ret = caps.get(1).unwrap().as_str().to_uppercase();
// Renumber the captured index.
let index = caps.get(2).unwrap().as_str().to_string();
let (index, _) = seen_allocs.insert_full(index);
write!(&mut ret, "{index}").unwrap();
// If we have a tail finishing with `─`, this means pretty-printing.
// Complete with filler `─` to preserve the pretty-print.
if let Some(tail) = caps.get(3) {
ret.push_str(tail.as_str());
let diff = caps.get(0).unwrap().as_str().len() - ret.len();
for _ in 0..diff {
ret.push('─');
}
}
ret
})
.into_owned();
}

// Custom normalization rules
for rule in custom_rules {
let re = Regex::new(&rule.0).expect("bad regex in custom normalization rule");
Expand Down
8 changes: 4 additions & 4 deletions tests/mir-opt/building/custom/consts.statics.built.after.mir
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ fn statics() -> () {
let mut _2: *mut i32;

bb0: {
_1 = const {alloc1: &i32};
_2 = const {alloc2: *mut i32};
_1 = const {ALLOC0: &i32};
_2 = const {ALLOC1: *mut i32};
return;
}
}

alloc2 (static: T, size: 4, align: 4) {
ALLOC1 (static: T, size: 4, align: 4) {
0a 0a 0a 0a │ ....
}

alloc1 (static: S, size: 4, align: 4) {
ALLOC0 (static: S, size: 4, align: 4) {
05 05 05 05 │ ....
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ fn main() -> () {
}
}

alloc1 (size: 3, align: 1) {
ALLOC0 (size: 3, align: 1) {
66 6f 6f │ foo
}
36 changes: 18 additions & 18 deletions tests/mir-opt/const_allocation.main.ConstProp.after.32bit.mir
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ fn main() -> () {
bb0: {
StorageLive(_1);
StorageLive(_2);
_2 = const {alloc1: &&[(Option<i32>, &[&str])]};
_2 = const {ALLOC0: &&[(Option<i32>, &[&str])]};
_1 = (*_2);
StorageDead(_2);
StorageDead(_1);
Expand All @@ -17,43 +17,43 @@ fn main() -> () {
}
}

alloc1 (static: FOO, size: 8, align: 4) {
╾─alloc19─╼ 03 00 00 00 │ ╾──╼....
ALLOC0 (static: FOO, size: 8, align: 4) {
╾─ALLOC1─╼ 03 00 00 00 │ ╾──╼....
}

alloc19 (size: 48, align: 4) {
0x0000 00 00 00 __ __ __ __ ╾─alloc6──╼ 00 00 00 00 │ ....░░░░╾──╼....
0x1000 00 00 00 __ __ __ __ ╾─alloc10─╼ 02 00 00 00 │ ....░░░░╾──╼....
0x2001 00 00 00 2a 00 00 00 ╾─alloc15─╼ 03 00 00 00 │ ....*...╾──╼....
ALLOC1 (size: 48, align: 4) {
0x0000 00 00 00 __ __ __ __ ╾─ALLOC2──╼ 00 00 00 00 │ ....░░░░╾──╼....
0x1000 00 00 00 __ __ __ __ ╾─ALLOC3─╼ 02 00 00 00 │ ....░░░░╾──╼....
0x2001 00 00 00 2a 00 00 00 ╾─ALLOC4─╼ 03 00 00 00 │ ....*...╾──╼....
}

alloc6 (size: 0, align: 4) {}
ALLOC2 (size: 0, align: 4) {}

alloc10 (size: 16, align: 4) {
╾─alloc9──╼ 03 00 00 00 ╾─alloc11─╼ 03 00 00 00 │ ╾──╼....╾──╼....
ALLOC3 (size: 16, align: 4) {
╾─ALLOC5──╼ 03 00 00 00 ╾─ALLOC6─╼ 03 00 00 00 │ ╾──╼....╾──╼....
}

alloc9 (size: 3, align: 1) {
ALLOC5 (size: 3, align: 1) {
66 6f 6f │ foo
}

alloc11 (size: 3, align: 1) {
ALLOC6 (size: 3, align: 1) {
62 61 72 │ bar
}

alloc15 (size: 24, align: 4) {
0x00 │ ╾─alloc14─03 00 00 00 ╾─alloc16─╼ 03 00 00 00 │ ╾──╼....╾──╼....
0x10 │ ╾─alloc17─╼ 04 00 00 00 │ ╾──╼....
ALLOC4 (size: 24, align: 4) {
0x00 │ ╾─ALLOC7──03 00 00 00 ╾─ALLOC8─╼ 03 00 00 00 │ ╾──╼....╾──╼....
0x10 │ ╾─ALLOC9─╼ 04 00 00 00 │ ╾──╼....
}

alloc14 (size: 3, align: 1) {
ALLOC7 (size: 3, align: 1) {
6d 65 68 │ meh
}

alloc16 (size: 3, align: 1) {
ALLOC8 (size: 3, align: 1) {
6d 6f 70 │ mop
}

alloc17 (size: 4, align: 1) {
ALLOC9 (size: 4, align: 1) {
6d c3 b6 70 │ m..p
}
40 changes: 20 additions & 20 deletions tests/mir-opt/const_allocation.main.ConstProp.after.64bit.mir
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ fn main() -> () {
bb0: {
StorageLive(_1);
StorageLive(_2);
_2 = const {alloc1: &&[(Option<i32>, &[&str])]};
_2 = const {ALLOC0: &&[(Option<i32>, &[&str])]};
_1 = (*_2);
StorageDead(_2);
StorageDead(_1);
Expand All @@ -17,47 +17,47 @@ fn main() -> () {
}
}

alloc1 (static: FOO, size: 16, align: 8) {
╾───────alloc19───────╼ 03 00 00 00 00 00 00 00 │ ╾──────╼........
ALLOC0 (static: FOO, size: 16, align: 8) {
╾───────ALLOC1───────╼ 03 00 00 00 00 00 00 00 │ ╾──────╼........
}

alloc19 (size: 72, align: 8) {
0x0000 00 00 00 __ __ __ __ ╾───────alloc6────────╼ │ ....░░░░╾──────╼
ALLOC1 (size: 72, align: 8) {
0x0000 00 00 00 __ __ __ __ ╾───────ALLOC2────────╼ │ ....░░░░╾──────╼
0x1000 00 00 00 00 00 00 00 00 00 00 00 __ __ __ __ │ ............░░░░
0x20 │ ╾───────alloc10───────╼ 02 00 00 00 00 00 00 00 │ ╾──────╼........
0x3001 00 00 00 2a 00 00 00 ╾───────alloc15───────╼ │ ....*...╾──────╼
0x20 │ ╾───────ALLOC3───────╼ 02 00 00 00 00 00 00 00 │ ╾──────╼........
0x3001 00 00 00 2a 00 00 00 ╾───────ALLOC4───────╼ │ ....*...╾──────╼
0x4003 00 00 00 00 00 00 00 │ ........
}

alloc6 (size: 0, align: 8) {}
ALLOC2 (size: 0, align: 8) {}

alloc10 (size: 32, align: 8) {
0x00 │ ╾───────alloc9────────╼ 03 00 00 00 00 00 00 00 │ ╾──────╼........
0x10 │ ╾───────alloc11───────╼ 03 00 00 00 00 00 00 00 │ ╾──────╼........
ALLOC3 (size: 32, align: 8) {
0x00 │ ╾───────ALLOC5────────╼ 03 00 00 00 00 00 00 00 │ ╾──────╼........
0x10 │ ╾───────ALLOC6───────╼ 03 00 00 00 00 00 00 00 │ ╾──────╼........
}

alloc9 (size: 3, align: 1) {
ALLOC5 (size: 3, align: 1) {
66 6f 6f │ foo
}

alloc11 (size: 3, align: 1) {
ALLOC6 (size: 3, align: 1) {
62 61 72 │ bar
}

alloc15 (size: 48, align: 8) {
0x00 │ ╾───────alloc14───────╼ 03 00 00 00 00 00 00 00 │ ╾──────╼........
0x10 │ ╾───────alloc16───────╼ 03 00 00 00 00 00 00 00 │ ╾──────╼........
0x20 │ ╾───────alloc17───────╼ 04 00 00 00 00 00 00 00 │ ╾──────╼........
ALLOC4 (size: 48, align: 8) {
0x00 │ ╾───────ALLOC7───────╼ 03 00 00 00 00 00 00 00 │ ╾──────╼........
0x10 │ ╾───────ALLOC8───────╼ 03 00 00 00 00 00 00 00 │ ╾──────╼........
0x20 │ ╾───────ALLOC9───────╼ 04 00 00 00 00 00 00 00 │ ╾──────╼........
}

alloc14 (size: 3, align: 1) {
ALLOC7 (size: 3, align: 1) {
6d 65 68 │ meh
}

alloc16 (size: 3, align: 1) {
ALLOC8 (size: 3, align: 1) {
6d 6f 70 │ mop
}

alloc17 (size: 4, align: 1) {
ALLOC9 (size: 4, align: 1) {
6d c3 b6 70 │ m..p
}
34 changes: 17 additions & 17 deletions tests/mir-opt/const_allocation2.main.ConstProp.after.32bit.mir
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ fn main() -> () {
bb0: {
StorageLive(_1);
StorageLive(_2);
_2 = const {alloc1: &&[(Option<i32>, &[&u8])]};
_2 = const {ALLOC0: &&[(Option<i32>, &[&u8])]};
_1 = (*_2);
StorageDead(_2);
StorageDead(_1);
Expand All @@ -17,42 +17,42 @@ fn main() -> () {
}
}

alloc1 (static: FOO, size: 8, align: 4) {
╾─alloc23─╼ 03 00 00 00 │ ╾──╼....
ALLOC0 (static: FOO, size: 8, align: 4) {
╾─ALLOC1─╼ 03 00 00 00 │ ╾──╼....
}

alloc23 (size: 48, align: 4) {
0x0000 00 00 00 __ __ __ __ ╾─alloc10─╼ 00 00 00 00 │ ....░░░░╾──╼....
0x1000 00 00 00 __ __ __ __ ╾─alloc15─╼ 02 00 00 00 │ ....░░░░╾──╼....
0x2001 00 00 00 2a 00 00 00 ╾─alloc21─╼ 03 00 00 00 │ ....*...╾──╼....
ALLOC1 (size: 48, align: 4) {
0x0000 00 00 00 __ __ __ __ ╾─ALLOC2─╼ 00 00 00 00 │ ....░░░░╾──╼....
0x1000 00 00 00 __ __ __ __ ╾─ALLOC3─╼ 02 00 00 00 │ ....░░░░╾──╼....
0x2001 00 00 00 2a 00 00 00 ╾─ALLOC4─╼ 03 00 00 00 │ ....*...╾──╼....
}

alloc10 (size: 0, align: 4) {}
ALLOC2 (size: 0, align: 4) {}

alloc15 (size: 8, align: 4) {
╾─alloc13─╼ ╾─alloc14─╼ │ ╾──╼╾──╼
ALLOC3 (size: 8, align: 4) {
╾─ALLOC5──╼ ╾─ALLOC6─╼ │ ╾──╼╾──╼
}

alloc13 (size: 1, align: 1) {
ALLOC5 (size: 1, align: 1) {
05.
}

alloc14 (size: 1, align: 1) {
ALLOC6 (size: 1, align: 1) {
06.
}

alloc21 (size: 12, align: 4) {
╾─a18+0x3─╼ ╾─alloc19─╼ ╾─a20+0x2─╼ │ ╾──╼╾──╼╾──╼
ALLOC4 (size: 12, align: 4) {
╾─A7+0x3╼ ╾─ALLOC8──╼ ╾─A9+0x2─╼ │ ╾──╼╾──╼╾──╼
}

alloc18 (size: 4, align: 1) {
ALLOC7 (size: 4, align: 1) {
2a 45 15 6f │ *E.o
}

alloc19 (size: 1, align: 1) {
ALLOC8 (size: 1, align: 1) {
2a │ *
}

alloc20 (size: 4, align: 1) {
ALLOC9 (size: 4, align: 1) {
2a 45 15 6f │ *E.o
}
36 changes: 18 additions & 18 deletions tests/mir-opt/const_allocation2.main.ConstProp.after.64bit.mir
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ fn main() -> () {
bb0: {
StorageLive(_1);
StorageLive(_2);
_2 = const {alloc1: &&[(Option<i32>, &[&u8])]};
_2 = const {ALLOC0: &&[(Option<i32>, &[&u8])]};
_1 = (*_2);
StorageDead(_2);
StorageDead(_1);
Expand All @@ -17,45 +17,45 @@ fn main() -> () {
}
}

alloc1 (static: FOO, size: 16, align: 8) {
╾───────alloc23───────╼ 03 00 00 00 00 00 00 00 │ ╾──────╼........
ALLOC0 (static: FOO, size: 16, align: 8) {
╾───────ALLOC1───────╼ 03 00 00 00 00 00 00 00 │ ╾──────╼........
}

alloc23 (size: 72, align: 8) {
0x0000 00 00 00 __ __ __ __ ╾───────alloc10───────╼ │ ....░░░░╾──────╼
ALLOC1 (size: 72, align: 8) {
0x0000 00 00 00 __ __ __ __ ╾───────ALLOC2───────╼ │ ....░░░░╾──────╼
0x1000 00 00 00 00 00 00 00 00 00 00 00 __ __ __ __ │ ............░░░░
0x20 │ ╾───────alloc15───────╼ 02 00 00 00 00 00 00 00 │ ╾──────╼........
0x3001 00 00 00 2a 00 00 00 ╾───────alloc21───────╼ │ ....*...╾──────╼
0x20 │ ╾───────ALLOC3───────╼ 02 00 00 00 00 00 00 00 │ ╾──────╼........
0x3001 00 00 00 2a 00 00 00 ╾───────ALLOC4───────╼ │ ....*...╾──────╼
0x4003 00 00 00 00 00 00 00 │ ........
}

alloc10 (size: 0, align: 8) {}
ALLOC2 (size: 0, align: 8) {}

alloc15 (size: 16, align: 8) {
╾───────alloc13───────╼ ╾───────alloc14───────╼ │ ╾──────╼╾──────╼
ALLOC3 (size: 16, align: 8) {
╾───────ALLOC5───────╼ ╾───────ALLOC6───────╼ │ ╾──────╼╾──────╼
}

alloc13 (size: 1, align: 1) {
ALLOC5 (size: 1, align: 1) {
05.
}

alloc14 (size: 1, align: 1) {
ALLOC6 (size: 1, align: 1) {
06.
}

alloc21 (size: 24, align: 8) {
0x00 │ ╾─────alloc18+0x3─────╼ ╾───────alloc19───────╼ │ ╾──────╼╾──────╼
0x10 │ ╾─────alloc20+0x2─────╼ │ ╾──────╼
ALLOC4 (size: 24, align: 8) {
0x00 │ ╾─────ALLOC7+0x3─────╼ ╾───────ALLOC8───────╼ │ ╾──────╼╾──────╼
0x10 │ ╾─────ALLOC9+0x2─────╼ │ ╾──────╼
}

alloc18 (size: 4, align: 1) {
ALLOC7 (size: 4, align: 1) {
2a 45 15 6f │ *E.o
}

alloc19 (size: 1, align: 1) {
ALLOC8 (size: 1, align: 1) {
2a │ *
}

alloc20 (size: 4, align: 1) {
ALLOC9 (size: 4, align: 1) {
2a 45 15 6f │ *E.o
}
Loading

0 comments on commit 1c5c949

Please sign in to comment.