mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-05 03:23:25 +00:00
test fast path offset reporting
This commit is contained in:
parent
0d01ce6a1b
commit
69423bf049
65
src/test/ui/consts/const-eval/ub-int-array.rs
Normal file
65
src/test/ui/consts/const-eval/ub-int-array.rs
Normal file
@ -0,0 +1,65 @@
|
||||
#![feature(const_transmute)]
|
||||
#![allow(const_err)] // make sure we cannot allow away the errors tested here
|
||||
|
||||
//! Test the "array of int" fast path in validity checking, and in particular whether it
|
||||
//! points at the right array element.
|
||||
|
||||
use std::mem;
|
||||
|
||||
#[repr(C)]
|
||||
union MaybeUninit<T: Copy> {
|
||||
uninit: (),
|
||||
init: T,
|
||||
}
|
||||
|
||||
const UNINIT_INT_0: [u32; 3] = unsafe {
|
||||
//~^ ERROR it is undefined behavior to use this value
|
||||
//~| type validation failed: encountered uninitialized bytes at [0]
|
||||
[
|
||||
MaybeUninit { uninit: () }.init,
|
||||
1,
|
||||
2,
|
||||
]
|
||||
};
|
||||
const UNINIT_INT_1: [u32; 3] = unsafe {
|
||||
//~^ ERROR it is undefined behavior to use this value
|
||||
//~| type validation failed: encountered uninitialized bytes at [1]
|
||||
mem::transmute(
|
||||
[
|
||||
0u8,
|
||||
0u8,
|
||||
0u8,
|
||||
0u8,
|
||||
1u8,
|
||||
MaybeUninit { uninit: () }.init,
|
||||
1u8,
|
||||
1u8,
|
||||
2u8,
|
||||
2u8,
|
||||
MaybeUninit { uninit: () }.init,
|
||||
2u8,
|
||||
]
|
||||
)
|
||||
};
|
||||
const UNINIT_INT_2: [u32; 3] = unsafe {
|
||||
//~^ ERROR it is undefined behavior to use this value
|
||||
//~| type validation failed: encountered uninitialized bytes at [2]
|
||||
mem::transmute(
|
||||
[
|
||||
0u8,
|
||||
0u8,
|
||||
0u8,
|
||||
0u8,
|
||||
1u8,
|
||||
1u8,
|
||||
1u8,
|
||||
1u8,
|
||||
2u8,
|
||||
2u8,
|
||||
2u8,
|
||||
MaybeUninit { uninit: () }.init,
|
||||
]
|
||||
)
|
||||
};
|
||||
|
||||
fn main() {}
|
45
src/test/ui/consts/const-eval/ub-int-array.stderr
Normal file
45
src/test/ui/consts/const-eval/ub-int-array.stderr
Normal file
@ -0,0 +1,45 @@
|
||||
error[E0080]: it is undefined behavior to use this value
|
||||
--> $DIR/ub-int-array.rs:15:1
|
||||
|
|
||||
LL | / const UNINIT_INT_0: [u32; 3] = unsafe {
|
||||
LL | |
|
||||
LL | |
|
||||
LL | | [
|
||||
... |
|
||||
LL | | ]
|
||||
LL | | };
|
||||
| |__^ type validation failed: encountered uninitialized bytes at [0]
|
||||
|
|
||||
= 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.
|
||||
|
||||
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 {
|
||||
LL | |
|
||||
LL | |
|
||||
LL | | mem::transmute(
|
||||
... |
|
||||
LL | | )
|
||||
LL | | };
|
||||
| |__^ type validation failed: encountered uninitialized bytes at [1]
|
||||
|
|
||||
= 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.
|
||||
|
||||
error[E0080]: it is undefined behavior to use this value
|
||||
--> $DIR/ub-int-array.rs:44:1
|
||||
|
|
||||
LL | / const UNINIT_INT_2: [u32; 3] = unsafe {
|
||||
LL | |
|
||||
LL | |
|
||||
LL | | mem::transmute(
|
||||
... |
|
||||
LL | | )
|
||||
LL | | };
|
||||
| |__^ type validation failed: encountered uninitialized bytes at [2]
|
||||
|
|
||||
= 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.
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0080`.
|
@ -6,11 +6,11 @@ use std::mem;
|
||||
|
||||
const UNALIGNED: &u16 = unsafe { mem::transmute(&[0u8; 4]) };
|
||||
//~^ ERROR it is undefined behavior to use this value
|
||||
//~^^ type validation failed: encountered an unaligned reference (required 2 byte alignment but found 1)
|
||||
//~| type validation failed: encountered an unaligned reference (required 2 byte alignment but found 1)
|
||||
|
||||
const UNALIGNED_BOX: Box<u16> = unsafe { mem::transmute(&[0u8; 4]) };
|
||||
//~^ ERROR it is undefined behavior to use this value
|
||||
//~^^ type validation failed: encountered an unaligned box (required 2 byte alignment but found 1)
|
||||
//~| type validation failed: encountered an unaligned box (required 2 byte alignment but found 1)
|
||||
|
||||
const NULL: &u16 = unsafe { mem::transmute(0usize) };
|
||||
//~^ ERROR it is undefined behavior to use this value
|
||||
|
Loading…
Reference in New Issue
Block a user