forgot to add alignment test loop in one test
This commit is contained in:
parent
066fa629f2
commit
d5b15297ac
@ -1 +1 @@
|
|||||||
8cdc94e84040ce797fd33d0a7cfda4ec4f2f2421
|
515c9fa505e18a65d7f61bc3e9eb833b79a68618
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
// error-pattern: but alignment 4 is required
|
// error-pattern: but alignment 4 is required
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
// No retry needed, this fails reliably.
|
||||||
|
|
||||||
let mut x = [0u8; 20];
|
let mut x = [0u8; 20];
|
||||||
let x_ptr: *mut u8 = x.as_mut_ptr();
|
let x_ptr: *mut u8 = x.as_mut_ptr();
|
||||||
// At least one of these is definitely unaligned.
|
// At least one of these is definitely unaligned.
|
||||||
|
@ -8,6 +8,6 @@ fn main() {
|
|||||||
let zptr = &z as *const _ as *const u64;
|
let zptr = &z as *const _ as *const u64;
|
||||||
unsafe {
|
unsafe {
|
||||||
::std::intrinsics::atomic_load(zptr);
|
::std::intrinsics::atomic_load(zptr);
|
||||||
//~^ ERROR accessing memory with alignment 4, but alignment 8 is required
|
//~^ERROR accessing memory with alignment 4, but alignment 8 is required
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,14 +6,16 @@
|
|||||||
struct MuchAlign;
|
struct MuchAlign;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let buf = [0u32; 256];
|
for _ in 0..10 { // Try many times as this might work by chance.
|
||||||
// `buf` is sufficiently aligned for `layout.align` on a `dyn Debug`, but not
|
let buf = [0u32; 256];
|
||||||
// for the actual alignment required by `MuchAlign`.
|
// `buf` is sufficiently aligned for `layout.align` on a `dyn Debug`, but not
|
||||||
// We craft a wide reference `&dyn Debug` with the vtable for `MuchAlign`. That should be UB,
|
// for the actual alignment required by `MuchAlign`.
|
||||||
// as the reference is not aligned to its dynamic alignment requirements.
|
// We craft a wide reference `&dyn Debug` with the vtable for `MuchAlign`. That should be UB,
|
||||||
let mut ptr = &MuchAlign as &dyn std::fmt::Debug;
|
// as the reference is not aligned to its dynamic alignment requirements.
|
||||||
// Overwrite the data part of `ptr` so it points to `buf`.
|
let mut ptr = &MuchAlign as &dyn std::fmt::Debug;
|
||||||
unsafe { (&mut ptr as *mut _ as *mut *const u8).write(&buf as *const _ as *const u8); }
|
// Overwrite the data part of `ptr` so it points to `buf`.
|
||||||
// Re-borrow that. This should be UB.
|
unsafe { (&mut ptr as *mut _ as *mut *const u8).write(&buf as *const _ as *const u8); }
|
||||||
let _ptr = &*ptr; //~ ERROR alignment 256 is required
|
// Re-borrow that. This should be UB.
|
||||||
|
let _ptr = &*ptr; //~ERROR alignment 256 is required
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,8 +9,9 @@
|
|||||||
fn main() {
|
fn main() {
|
||||||
let x = &mut [0u8; 3];
|
let x = &mut [0u8; 3];
|
||||||
let base_addr = x as *mut _ as usize;
|
let base_addr = x as *mut _ as usize;
|
||||||
|
// Manually make sure the pointer is properly aligned.
|
||||||
let base_addr_aligned = if base_addr % 2 == 0 { base_addr } else { base_addr+1 };
|
let base_addr_aligned = if base_addr % 2 == 0 { base_addr } else { base_addr+1 };
|
||||||
let u16_ptr = base_addr_aligned as *mut u16;
|
let u16_ptr = base_addr_aligned as *mut u16;
|
||||||
unsafe { *u16_ptr = 2; } //~ ERROR memory with alignment 1, but alignment 2 is required
|
unsafe { *u16_ptr = 2; } //~ERROR memory with alignment 1, but alignment 2 is required
|
||||||
println!("{:?}", x);
|
println!("{:?}", x);
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,6 @@ fn main() {
|
|||||||
y: 99,
|
y: 99,
|
||||||
};
|
};
|
||||||
let p = unsafe { &foo.x };
|
let p = unsafe { &foo.x };
|
||||||
let i = *p; //~ ERROR alignment 4 is required
|
let i = *p; //~ERROR alignment 4 is required
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,6 @@ fn main() {
|
|||||||
let x = [2u16, 3, 4]; // Make it big enough so we don't get an out-of-bounds error.
|
let x = [2u16, 3, 4]; // Make it big enough so we don't get an out-of-bounds error.
|
||||||
let x = &x[0] as *const _ as *const u32;
|
let x = &x[0] as *const _ as *const u32;
|
||||||
// This must fail because alignment is violated: the allocation's base is not sufficiently aligned.
|
// This must fail because alignment is violated: the allocation's base is not sufficiently aligned.
|
||||||
let _x = unsafe { *x }; //~ ERROR memory with alignment 2, but alignment 4 is required
|
let _x = unsafe { *x }; //~ERROR memory with alignment 2, but alignment 4 is required
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,11 +2,11 @@
|
|||||||
// compile-flags: -Zmiri-disable-validation -Zmiri-disable-stacked-borrows
|
// compile-flags: -Zmiri-disable-validation -Zmiri-disable-stacked-borrows
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
for _ in 0..10 { // Try many times as this might work by chance.
|
// No retry needed, this fails reliably.
|
||||||
let x = [2u32, 3]; // Make it big enough so we don't get an out-of-bounds error.
|
|
||||||
let x = (x.as_ptr() as *const u8).wrapping_offset(3) as *const u32;
|
let x = [2u32, 3]; // Make it big enough so we don't get an out-of-bounds error.
|
||||||
// This must fail because alignment is violated: the offset is not sufficiently aligned.
|
let x = (x.as_ptr() as *const u8).wrapping_offset(3) as *const u32;
|
||||||
// Also make the offset not a power of 2, that used to ICE.
|
// This must fail because alignment is violated: the offset is not sufficiently aligned.
|
||||||
let _x = unsafe { *x }; //~ ERROR memory with alignment 1, but alignment 4 is required
|
// Also make the offset not a power of 2, that used to ICE.
|
||||||
}
|
let _x = unsafe { *x }; //~ERROR memory with alignment 1, but alignment 4 is required
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,6 @@ fn main() {
|
|||||||
let x = &x[0] as *const _ as *const *const u8; // cast to ptr-to-ptr, so that we load a ptr
|
let x = &x[0] as *const _ as *const *const u8; // cast to ptr-to-ptr, so that we load a ptr
|
||||||
// This must fail because alignment is violated. Test specifically for loading pointers,
|
// This must fail because alignment is violated. Test specifically for loading pointers,
|
||||||
// which have special code in miri's memory.
|
// which have special code in miri's memory.
|
||||||
let _x = unsafe { *x };
|
let _x = unsafe { *x }; //~ERROR but alignment
|
||||||
//~^ ERROR but alignment
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,9 +2,10 @@
|
|||||||
// compile-flags: -Zmiri-disable-validation
|
// compile-flags: -Zmiri-disable-validation
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let x = &2u8;
|
for _ in 0..10 { // Try many times as this might work by chance.
|
||||||
let x = x as *const _ as *const [u32; 0];
|
let x = &2u8;
|
||||||
// This must fail because alignment is violated. Test specifically for loading ZST.
|
let x = x as *const _ as *const [u32; 0];
|
||||||
let _x = unsafe { *x };
|
// This must fail because alignment is violated. Test specifically for loading ZST.
|
||||||
//~^ ERROR alignment 4 is required
|
let _x = unsafe { *x }; //~ERROR alignment 4 is required
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user