Skip to content

Commit 73e7207

Browse files
committed
Fix ui constant tests for big-endian platforms
A number of tests under ui/const-ptr and ui/consts are currently failing on big-endian platforms as the binary encoding of some constants is hard-coded in the stderr test files. Fix this by providing a normalize-stderr-test rule that strips out the raw bytes hex dump, so the comparison can be done in an endianness-independent manner. Note that in most cases, this means the tests are now also independent of word size, so the 32bit and 64bit cases can be re-unified. To keep tests that verify the details of those raw bytes dumps, a new test case raw-bytes.rs performs the tests where the hex dumps were stripped out a second time, but only on little- endian platforms. In addition, src/test/ui/const-ptr/forbidden_slices.rs exposes an endian-specific difference in this diagnostic output: constructing invalid value at .<deref>[0]: encountered 0x11, but expected a boolean depending on which byte of D0 is not a boolean value (0 or 1). Fixed this by choosing a value of D0 that differs from 0 or 1 in all bytes. Fixes part of #105383.
1 parent 2d8651a commit 73e7207

30 files changed

+1716
-1130
lines changed

src/test/ui/const-ptr/forbidden_slices.64bit.stderr

-240
This file was deleted.

src/test/ui/const-ptr/forbidden_slices.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
// stderr-per-bitwidth
2-
// normalize-stderr-test "╾─*a(lloc)?[0-9]+(\+[a-z0-9]+)?─*╼" -> "╾ALLOC_ID$2╼"
1+
// Strip out raw byte dumps to make comparison platform-independent:
2+
// normalize-stderr-test "(the raw bytes of the constant) \(size: [0-9]*, align: [0-9]*\)" -> "$1 (size: $$SIZE, align: $$ALIGN)"
3+
// normalize-stderr-test "([0-9a-f][0-9a-f] |╾─*a(lloc)?[0-9]+(\+[a-z0-9]+)?─*╼ )+ *│.*" -> "HEX_DUMP"
34
// normalize-stderr-test "alloc\d+" -> "allocN"
45
// error-pattern: could not evaluate static initializer
56
#![feature(
@@ -78,7 +79,7 @@ pub static R8: &[u64] = unsafe {
7879
pub static R9: &[u32] = unsafe { from_ptr_range(&D0..(&D0 as *const u32).add(1)) };
7980
pub static R10: &[u32] = unsafe { from_ptr_range(&D0..&D0) };
8081

81-
const D0: u32 = 0x11;
82+
const D0: u32 = 0x11111111; // Constant chosen for endianness-independent behavior.
8283
const D1: MaybeUninit<&u32> = MaybeUninit::uninit();
8384
const D2: Struct = Struct { a: 1, b: 2, c: 3, d: 4 };
8485
const D3: &u32 = &42;

0 commit comments

Comments
 (0)