Skip to content

Commit

Permalink
More mir-opt test fixes for big-endian platforms
Browse files Browse the repository at this point in the history
A number of mir-opt test cases are failing again on big-endian
platforms, due to endian-specific binary encodings in the output
files that are being checked by the test.  To fix those, one of
the following two strategies is used:

a) Where a binary encoded value directly originates from some
immediate constant in the test case source code, change that
constant to an endian-invariant value (like 0x11000011).

b) Where that is not easily possible or would change the essence
of what the test is checking for, disable the test on big-endian
platforms.

Fixes (again) rust-lang#105383.
  • Loading branch information
uweigand committed Jul 10, 2024
1 parent c092b28 commit 73caae4
Show file tree
Hide file tree
Showing 52 changed files with 150 additions and 142 deletions.
1 change: 1 addition & 0 deletions tests/mir-opt/const_debuginfo.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//@ test-mir-pass: SingleUseConsts
//@ compile-flags: -C overflow-checks=no -Zmir-enable-passes=+GVN
//@ ignore-endian-big

#![allow(unused)]

Expand Down
10 changes: 5 additions & 5 deletions tests/mir-opt/const_prop/address_of_pair.fn0.GVN.diff
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@

bb0: {
StorageLive(_2);
- _2 = (const 1_i32, const false);
+ _2 = const (1_i32, false);
- _2 = (const 285212689_i32, const false);
+ _2 = const (285212689_i32, false);
StorageLive(_3);
_3 = &raw mut (_2.1: bool);
- _2 = (const 1_i32, const false);
+ _2 = const (1_i32, false);
- _2 = (const 285212689_i32, const false);
+ _2 = const (285212689_i32, false);
StorageLive(_4);
(*_3) = const true;
_4 = const ();
Expand All @@ -47,6 +47,6 @@
+ }
+
+ ALLOC0 (size: 8, align: 4) {
+ 01 00 00 00 00 __ __ __ │ .....░░░
+ 11 00 00 11 00 __ __ __ │ .....░░░
}

4 changes: 2 additions & 2 deletions tests/mir-opt/const_prop/address_of_pair.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ pub fn fn0() -> bool {
// CHECK-NOT: = const false;
// CHECK-NOT: = const true;
// CHECK: _0 = [[ret]];
let mut pair = (1, false);
let mut pair = (0x11000011, false); // Endian-invariant value.
let ptr = core::ptr::addr_of_mut!(pair.1);
pair = (1, false);
pair = (0x11000011, false);
unsafe {
*ptr = true;
}
Expand Down
12 changes: 6 additions & 6 deletions tests/mir-opt/const_prop/checked_add.main.GVN.panic-abort.diff
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,22 @@

bb0: {
StorageLive(_1);
- _2 = AddWithOverflow(const 1_u32, const 1_u32);
- assert(!move (_2.1: bool), "attempt to compute `{} + {}`, which would overflow", const 1_u32, const 1_u32) -> [success: bb1, unwind unreachable];
+ _2 = const (2_u32, false);
+ assert(!const false, "attempt to compute `{} + {}`, which would overflow", const 1_u32, const 1_u32) -> [success: bb1, unwind unreachable];
- _2 = AddWithOverflow(const 285212689_u32, const 285212689_u32);
- assert(!move (_2.1: bool), "attempt to compute `{} + {}`, which would overflow", const 285212689_u32, const 285212689_u32) -> [success: bb1, unwind unreachable];
+ _2 = const (570425378_u32, false);
+ assert(!const false, "attempt to compute `{} + {}`, which would overflow", const 285212689_u32, const 285212689_u32) -> [success: bb1, unwind unreachable];
}

bb1: {
- _1 = move (_2.0: u32);
+ _1 = const 2_u32;
+ _1 = const 570425378_u32;
_0 = const ();
StorageDead(_1);
return;
}
+ }
+
+ ALLOC0 (size: 8, align: 4) {
+ 02 00 00 00 00 __ __ __ │ .....░░░
+ 22 00 00 22 00 __ __ __ │ "..".░░░
}

12 changes: 6 additions & 6 deletions tests/mir-opt/const_prop/checked_add.main.GVN.panic-unwind.diff
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,22 @@

bb0: {
StorageLive(_1);
- _2 = AddWithOverflow(const 1_u32, const 1_u32);
- assert(!move (_2.1: bool), "attempt to compute `{} + {}`, which would overflow", const 1_u32, const 1_u32) -> [success: bb1, unwind continue];
+ _2 = const (2_u32, false);
+ assert(!const false, "attempt to compute `{} + {}`, which would overflow", const 1_u32, const 1_u32) -> [success: bb1, unwind continue];
- _2 = AddWithOverflow(const 285212689_u32, const 285212689_u32);
- assert(!move (_2.1: bool), "attempt to compute `{} + {}`, which would overflow", const 285212689_u32, const 285212689_u32) -> [success: bb1, unwind continue];
+ _2 = const (570425378_u32, false);
+ assert(!const false, "attempt to compute `{} + {}`, which would overflow", const 285212689_u32, const 285212689_u32) -> [success: bb1, unwind continue];
}

bb1: {
- _1 = move (_2.0: u32);
+ _1 = const 2_u32;
+ _1 = const 570425378_u32;
_0 = const ();
StorageDead(_1);
return;
}
+ }
+
+ ALLOC0 (size: 8, align: 4) {
+ 02 00 00 00 00 __ __ __ │ .....░░░
+ 22 00 00 22 00 __ __ __ │ "..".░░░
}

4 changes: 2 additions & 2 deletions tests/mir-opt/const_prop/checked_add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ fn main() {
// CHECK-LABEL: fn main(
// CHECK: debug x => [[x:_.*]];
// CHECK: assert(!const false,
// CHECK: [[x]] = const 2_u32;
let x: u32 = 1 + 1;
// CHECK: [[x]] = const 570425378_u32;
let x: u32 = 0x11000011 + 0x11000011; // Endian-invariant value.
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

bb0: {
StorageLive(_1);
- _1 = (const 42_i32, const 43_i32);
+ _1 = const (42_i32, 43_i32);
- _1 = (const 285212689_i32, const 570425378_i32);
+ _1 = const (285212689_i32, 570425378_i32);
(_1.1: i32) = const 99_i32;
StorageLive(_2);
_2 = _1;
Expand All @@ -27,6 +27,6 @@
+ }
+
+ ALLOC0 (size: 8, align: 4) {
+ 2a 00 00 00 2b 00 00 00*...+...
+ 11 00 00 11 22 00 00 22 │ ....".."
}

4 changes: 2 additions & 2 deletions tests/mir-opt/const_prop/mutable_variable_aggregate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ fn main() {
// CHECK-LABEL: fn main(
// CHECK: debug x => [[x:_.*]];
// CHECK: debug y => [[y:_.*]];
// CHECK: [[x]] = const (42_i32, 43_i32);
// CHECK: [[x]] = const (285212689_i32, 570425378_i32);
// CHECK: ([[x]].1: i32) = const 99_i32;
// CHECK: [[y]] = [[x]];
let mut x = (42, 43);
let mut x = (0x11000011, 0x22000022); // Endian-invariant values.
x.1 = 99;
let y = x;
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@

bb0: {
StorageLive(_1);
- _1 = (const 42_i32, const 43_i32);
+ _1 = const (42_i32, 43_i32);
- _1 = (const 285212689_i32, const 570425378_i32);
+ _1 = const (285212689_i32, 570425378_i32);
StorageLive(_2);
_2 = &mut _1;
((*_2).1: i32) = const 99_i32;
Expand All @@ -34,6 +34,6 @@
+ }
+
+ ALLOC0 (size: 8, align: 4) {
+ 2a 00 00 00 2b 00 00 00*...+...
+ 11 00 00 11 22 00 00 22 │ ....".."
}

Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ fn main() {
// CHECK: debug x => [[x:_.*]];
// CHECK: debug z => [[z:_.*]];
// CHECK: debug y => [[y:_.*]];
// CHECK: [[x]] = const (42_i32, 43_i32);
// CHECK: [[x]] = const (285212689_i32, 570425378_i32);
// CHECK: [[z]] = &mut [[x]];
// CHECK: ((*[[z]]).1: i32) = const 99_i32;
// CHECK: [[y]] = [[x]];
let mut x = (42, 43);
let mut x = (0x11000011, 0x22000022); // Endian-invariant values.
let z = &mut x;
z.1 = 99;
let y = x;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@

bb1: {
StorageLive(_2);
- _2 = (const 1_i32, const 2_i32);
+ _2 = const (1_i32, 2_i32);
- _2 = (const 285212689_i32, const 570425378_i32);
+ _2 = const (285212689_i32, 570425378_i32);
StorageLive(_3);
_3 = _1;
- (_2.1: i32) = move _3;
Expand All @@ -51,6 +51,6 @@
+ }
+
+ ALLOC0 (size: 8, align: 4) {
+ 01 00 00 00 02 00 00 00 │ ........
+ 11 00 00 11 22 00 00 22 │ ....".."
}

Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@

bb1: {
StorageLive(_2);
- _2 = (const 1_i32, const 2_i32);
+ _2 = const (1_i32, 2_i32);
- _2 = (const 285212689_i32, const 570425378_i32);
+ _2 = const (285212689_i32, 570425378_i32);
StorageLive(_3);
_3 = _1;
- (_2.1: i32) = move _3;
Expand All @@ -51,6 +51,6 @@
+ }
+
+ ALLOC0 (size: 8, align: 4) {
+ 01 00 00 00 02 00 00 00 │ ........
+ 11 00 00 11 22 00 00 22 │ ....".."
}

4 changes: 2 additions & 2 deletions tests/mir-opt/const_prop/mutable_variable_unprop_assign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ fn main() {
// CHECK: debug y => [[y:_.*]];
// CHECK: debug z => [[z:_.*]];
// CHECK: [[a]] = foo()
// CHECK: [[x]] = const (1_i32, 2_i32);
// CHECK: [[x]] = const (285212689_i32, 570425378_i32);
// CHECK: ([[x]].1: i32) = [[a]];
// CHECK: [[y]] = ([[x]].1: i32);
// CHECK: [[z]] = ([[x]].0: i32);
let a = foo();
let mut x: (i32, i32) = (1, 2);
let mut x: (i32, i32) = (0x11000011, 0x22000022); // Endian-invariant values.
x.1 = a;
let y = x.1;
let z = x.0;
Expand Down
12 changes: 6 additions & 6 deletions tests/mir-opt/const_prop/return_place.add.GVN.panic-abort.diff
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,20 @@
let mut _1: (u32, bool);

bb0: {
- _1 = AddWithOverflow(const 2_u32, const 2_u32);
- assert(!move (_1.1: bool), "attempt to compute `{} + {}`, which would overflow", const 2_u32, const 2_u32) -> [success: bb1, unwind unreachable];
+ _1 = const (4_u32, false);
+ assert(!const false, "attempt to compute `{} + {}`, which would overflow", const 2_u32, const 2_u32) -> [success: bb1, unwind unreachable];
- _1 = AddWithOverflow(const 285212689_u32, const 285212689_u32);
- assert(!move (_1.1: bool), "attempt to compute `{} + {}`, which would overflow", const 285212689_u32, const 285212689_u32) -> [success: bb1, unwind unreachable];
+ _1 = const (570425378_u32, false);
+ assert(!const false, "attempt to compute `{} + {}`, which would overflow", const 285212689_u32, const 285212689_u32) -> [success: bb1, unwind unreachable];
}

bb1: {
- _0 = move (_1.0: u32);
+ _0 = const 4_u32;
+ _0 = const 570425378_u32;
return;
}
+ }
+
+ ALLOC0 (size: 8, align: 4) {
+ 04 00 00 00 00 __ __ __ │ .....░░░
+ 22 00 00 22 00 __ __ __ │ "..".░░░
}

12 changes: 6 additions & 6 deletions tests/mir-opt/const_prop/return_place.add.GVN.panic-unwind.diff
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,20 @@
let mut _1: (u32, bool);

bb0: {
- _1 = AddWithOverflow(const 2_u32, const 2_u32);
- assert(!move (_1.1: bool), "attempt to compute `{} + {}`, which would overflow", const 2_u32, const 2_u32) -> [success: bb1, unwind continue];
+ _1 = const (4_u32, false);
+ assert(!const false, "attempt to compute `{} + {}`, which would overflow", const 2_u32, const 2_u32) -> [success: bb1, unwind continue];
- _1 = AddWithOverflow(const 285212689_u32, const 285212689_u32);
- assert(!move (_1.1: bool), "attempt to compute `{} + {}`, which would overflow", const 285212689_u32, const 285212689_u32) -> [success: bb1, unwind continue];
+ _1 = const (570425378_u32, false);
+ assert(!const false, "attempt to compute `{} + {}`, which would overflow", const 285212689_u32, const 285212689_u32) -> [success: bb1, unwind continue];
}

bb1: {
- _0 = move (_1.0: u32);
+ _0 = const 4_u32;
+ _0 = const 570425378_u32;
return;
}
+ }
+
+ ALLOC0 (size: 8, align: 4) {
+ 04 00 00 00 00 __ __ __ │ .....░░░
+ 22 00 00 22 00 __ __ __ │ "..".░░░
}

Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ fn add() -> u32 {
let mut _1: (u32, bool);

bb0: {
_1 = const (4_u32, false);
assert(!const false, "attempt to compute `{} + {}`, which would overflow", const 2_u32, const 2_u32) -> [success: bb1, unwind unreachable];
_1 = const (570425378_u32, false);
assert(!const false, "attempt to compute `{} + {}`, which would overflow", const 285212689_u32, const 285212689_u32) -> [success: bb1, unwind unreachable];
}

bb1: {
_0 = const 4_u32;
_0 = const 570425378_u32;
return;
}
}

ALLOC0 (size: 8, align: 4) {
04 00 00 00 00 __ __ __ │ .....░░░
22 00 00 22 00 __ __ __ │ "..".░░░
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ fn add() -> u32 {
let mut _1: (u32, bool);

bb0: {
_1 = const (4_u32, false);
assert(!const false, "attempt to compute `{} + {}`, which would overflow", const 2_u32, const 2_u32) -> [success: bb1, unwind continue];
_1 = const (570425378_u32, false);
assert(!const false, "attempt to compute `{} + {}`, which would overflow", const 285212689_u32, const 285212689_u32) -> [success: bb1, unwind continue];
}

bb1: {
_0 = const 4_u32;
_0 = const 570425378_u32;
return;
}
}

ALLOC0 (size: 8, align: 4) {
04 00 00 00 00 __ __ __ │ .....░░░
22 00 00 22 00 __ __ __ │ "..".░░░
}
4 changes: 2 additions & 2 deletions tests/mir-opt/const_prop/return_place.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
// EMIT_MIR return_place.add.PreCodegen.before.mir
fn add() -> u32 {
// CHECK-LABEL: fn add(
// CHECK: _0 = const 4_u32;
2 + 2
// CHECK: _0 = const 570425378_u32;
0x11000011 + 0x11000011 // Endian-invariant value.
}

fn main() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@

bb1: {
- _1 = (*_2)[_6];
+ _1 = const 2_u32;
+ _1 = const 570425378_u32;
StorageDead(_6);
StorageDead(_4);
StorageDead(_2);
Expand All @@ -52,6 +52,6 @@
+ }
+
+ ALLOC0 (size: 12, align: 4) {
+ 01 00 00 00 02 00 00 00 03 00 00 00 │ ............
+ 11 00 00 11 22 00 00 22 33 00 00 33 │ ....".."3..3
}

Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@

bb1: {
- _1 = (*_2)[_6];
+ _1 = const 2_u32;
+ _1 = const 570425378_u32;
StorageDead(_6);
StorageDead(_4);
StorageDead(_2);
Expand All @@ -52,6 +52,6 @@
+ }
+
+ ALLOC0 (size: 12, align: 4) {
+ 01 00 00 00 02 00 00 00 03 00 00 00 │ ............
+ 11 00 00 11 22 00 00 22 33 00 00 33 │ ....".."3..3
}

Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@

bb1: {
- _1 = (*_2)[_6];
+ _1 = const 2_u32;
+ _1 = const 570425378_u32;
StorageDead(_6);
StorageDead(_4);
StorageDead(_2);
Expand All @@ -52,6 +52,6 @@
+ }
+
+ ALLOC0 (size: 12, align: 4) {
+ 01 00 00 00 02 00 00 00 03 00 00 00 │ ............
+ 11 00 00 11 22 00 00 22 33 00 00 33 │ ....".."3..3
}

Loading

0 comments on commit 73caae4

Please sign in to comment.