Skip to content

Commit 2063067

Browse files
committed
Fix ub-int-array test for big-endian platforms
As of commit 7767cbb, the tests/ui/consts/const-eval/ub-int-array.rs test is failing on big-endian platforms (in particular s390x), as the stderr output contains a hex dump that depends on endianness. Since this point intentionally verifies the hex dump to check the uninitialized byte markers, I think we should not simply standardize away the hex dump as is done with some of the other tests in this directory. However, most of the test is already endian-independent. The only exception is one line of hex dump, which can also be made endian-independent by choosing appropriate constants in the source code. Since the 32bit and 64bit stderr outputs were already (and remain) identical, I've merged them and removed the stderr-per-bitwidth marker. Fixes (again) rust-lang#105383.
1 parent 0b31792 commit 2063067

File tree

3 files changed

+10
-42
lines changed

3 files changed

+10
-42
lines changed

tests/ui/consts/const-eval/ub-int-array.64bit.stderr

-36
This file was deleted.

tests/ui/consts/const-eval/ub-int-array.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// stderr-per-bitwidth
21
//! Test the "array of int" fast path in validity checking, and in particular whether it
32
//! points at the right array element.
43
@@ -19,7 +18,12 @@ impl<T: Copy> MaybeUninit<T> {
1918
const UNINIT_INT_0: [u32; 3] = unsafe {
2019
//~^ ERROR it is undefined behavior to use this value
2120
//~| invalid value at [0]
22-
mem::transmute([MaybeUninit { uninit: () }, MaybeUninit::new(1), MaybeUninit::new(2)])
21+
mem::transmute([
22+
MaybeUninit { uninit: () },
23+
// Constants chosen to achieve endianness-independent hex dump.
24+
MaybeUninit::new(0x11111111),
25+
MaybeUninit::new(0x22222222),
26+
])
2327
};
2428
const UNINIT_INT_1: [u32; 3] = unsafe {
2529
//~^ ERROR it is undefined behavior to use this value

tests/ui/consts/const-eval/ub-int-array.32bit.stderr renamed to tests/ui/consts/const-eval/ub-int-array.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
error[E0080]: it is undefined behavior to use this value
2-
--> $DIR/ub-int-array.rs:19:1
2+
--> $DIR/ub-int-array.rs:18:1
33
|
44
LL | const UNINIT_INT_0: [u32; 3] = unsafe {
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at [0]: encountered uninitialized memory, but expected an integer
66
|
77
= note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior.
88
= note: the raw bytes of the constant (size: 12, align: 4) {
9-
__ __ __ __ 01 00 00 00 02 00 00 00 │ ░░░░........
9+
__ __ __ __ 11 11 11 11 22 22 22 22 │ ░░░░....""""
1010
}
1111

1212
error[E0080]: it is undefined behavior to use this value
13-
--> $DIR/ub-int-array.rs:24:1
13+
--> $DIR/ub-int-array.rs:28:1
1414
|
1515
LL | const UNINIT_INT_1: [u32; 3] = unsafe {
1616
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at [1]: encountered uninitialized memory, but expected an integer
@@ -21,7 +21,7 @@ LL | const UNINIT_INT_1: [u32; 3] = unsafe {
2121
}
2222

2323
error[E0080]: it is undefined behavior to use this value
24-
--> $DIR/ub-int-array.rs:42:1
24+
--> $DIR/ub-int-array.rs:46:1
2525
|
2626
LL | const UNINIT_INT_2: [u32; 3] = unsafe {
2727
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at [2]: encountered uninitialized memory, but expected an integer

0 commit comments

Comments
 (0)