From 2063067a8159d9527f98630af7d79397a358fcd3 Mon Sep 17 00:00:00 2001 From: Ulrich Weigand Date: Thu, 24 Aug 2023 12:44:42 +0200 Subject: [PATCH] Fix ub-int-array test for big-endian platforms As of commit 7767cbb3b0b332fd0a46e347ea7f68f20109d768, 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) https://github.com/rust-lang/rust/issues/105383. --- .../const-eval/ub-int-array.64bit.stderr | 36 ------------------- tests/ui/consts/const-eval/ub-int-array.rs | 8 +++-- ...array.32bit.stderr => ub-int-array.stderr} | 8 ++--- 3 files changed, 10 insertions(+), 42 deletions(-) delete mode 100644 tests/ui/consts/const-eval/ub-int-array.64bit.stderr rename tests/ui/consts/const-eval/{ub-int-array.32bit.stderr => ub-int-array.stderr} (91%) diff --git a/tests/ui/consts/const-eval/ub-int-array.64bit.stderr b/tests/ui/consts/const-eval/ub-int-array.64bit.stderr deleted file mode 100644 index b3df41304ac33..0000000000000 --- a/tests/ui/consts/const-eval/ub-int-array.64bit.stderr +++ /dev/null @@ -1,36 +0,0 @@ -error[E0080]: it is undefined behavior to use this value - --> $DIR/ub-int-array.rs:19:1 - | -LL | const UNINIT_INT_0: [u32; 3] = unsafe { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at [0]: encountered uninitialized memory, but expected an integer - | - = 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. - = note: the raw bytes of the constant (size: 12, align: 4) { - __ __ __ __ 01 00 00 00 02 00 00 00 │ ░░░░........ - } - -error[E0080]: it is undefined behavior to use this value - --> $DIR/ub-int-array.rs:24:1 - | -LL | const UNINIT_INT_1: [u32; 3] = unsafe { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at [1]: encountered uninitialized memory, but expected an integer - | - = 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. - = note: the raw bytes of the constant (size: 12, align: 4) { - 00 00 00 00 01 __ 01 01 02 02 __ 02 │ .....░....░. - } - -error[E0080]: it is undefined behavior to use this value - --> $DIR/ub-int-array.rs:42:1 - | -LL | const UNINIT_INT_2: [u32; 3] = unsafe { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at [2]: encountered uninitialized memory, but expected an integer - | - = 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. - = note: the raw bytes of the constant (size: 12, align: 4) { - 00 00 00 00 01 01 01 01 02 02 02 __ │ ...........░ - } - -error: aborting due to 3 previous errors - -For more information about this error, try `rustc --explain E0080`. diff --git a/tests/ui/consts/const-eval/ub-int-array.rs b/tests/ui/consts/const-eval/ub-int-array.rs index adcf376b9c765..cde0749dc5fb5 100644 --- a/tests/ui/consts/const-eval/ub-int-array.rs +++ b/tests/ui/consts/const-eval/ub-int-array.rs @@ -1,4 +1,3 @@ -// stderr-per-bitwidth //! Test the "array of int" fast path in validity checking, and in particular whether it //! points at the right array element. @@ -19,7 +18,12 @@ impl MaybeUninit { const UNINIT_INT_0: [u32; 3] = unsafe { //~^ ERROR it is undefined behavior to use this value //~| invalid value at [0] - mem::transmute([MaybeUninit { uninit: () }, MaybeUninit::new(1), MaybeUninit::new(2)]) + mem::transmute([ + MaybeUninit { uninit: () }, + // Constants chosen to achieve endianness-independent hex dump. + MaybeUninit::new(0x11111111), + MaybeUninit::new(0x22222222), + ]) }; const UNINIT_INT_1: [u32; 3] = unsafe { //~^ ERROR it is undefined behavior to use this value diff --git a/tests/ui/consts/const-eval/ub-int-array.32bit.stderr b/tests/ui/consts/const-eval/ub-int-array.stderr similarity index 91% rename from tests/ui/consts/const-eval/ub-int-array.32bit.stderr rename to tests/ui/consts/const-eval/ub-int-array.stderr index b3df41304ac33..c8efd7e1bd35d 100644 --- a/tests/ui/consts/const-eval/ub-int-array.32bit.stderr +++ b/tests/ui/consts/const-eval/ub-int-array.stderr @@ -1,16 +1,16 @@ error[E0080]: it is undefined behavior to use this value - --> $DIR/ub-int-array.rs:19:1 + --> $DIR/ub-int-array.rs:18:1 | LL | const UNINIT_INT_0: [u32; 3] = unsafe { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at [0]: encountered uninitialized memory, but expected an integer | = 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. = note: the raw bytes of the constant (size: 12, align: 4) { - __ __ __ __ 01 00 00 00 02 00 00 00 │ ░░░░........ + __ __ __ __ 11 11 11 11 22 22 22 22 │ ░░░░...."""" } error[E0080]: it is undefined behavior to use this value - --> $DIR/ub-int-array.rs:24:1 + --> $DIR/ub-int-array.rs:28:1 | LL | const UNINIT_INT_1: [u32; 3] = unsafe { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at [1]: encountered uninitialized memory, but expected an integer @@ -21,7 +21,7 @@ LL | const UNINIT_INT_1: [u32; 3] = unsafe { } error[E0080]: it is undefined behavior to use this value - --> $DIR/ub-int-array.rs:42:1 + --> $DIR/ub-int-array.rs:46:1 | LL | const UNINIT_INT_2: [u32; 3] = unsafe { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at [2]: encountered uninitialized memory, but expected an integer