forgot to add alignment test loop in one test

This commit is contained in:
Ralf Jung 2020-08-18 10:11:54 +02:00
parent 066fa629f2
commit d5b15297ac
10 changed files with 34 additions and 29 deletions

View File

@ -1 +1 @@
8cdc94e84040ce797fd33d0a7cfda4ec4f2f2421
515c9fa505e18a65d7f61bc3e9eb833b79a68618

View File

@ -1,6 +1,8 @@
// error-pattern: but alignment 4 is required
fn main() {
// No retry needed, this fails reliably.
let mut x = [0u8; 20];
let x_ptr: *mut u8 = x.as_mut_ptr();
// At least one of these is definitely unaligned.

View File

@ -8,6 +8,6 @@ fn main() {
let zptr = &z as *const _ as *const u64;
unsafe {
::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
}
}

View File

@ -6,14 +6,16 @@
struct MuchAlign;
fn main() {
let buf = [0u32; 256];
// `buf` is sufficiently aligned for `layout.align` on a `dyn Debug`, but not
// for the actual alignment required by `MuchAlign`.
// We craft a wide reference `&dyn Debug` with the vtable for `MuchAlign`. That should be UB,
// as the reference is not aligned to its dynamic alignment requirements.
let mut ptr = &MuchAlign as &dyn std::fmt::Debug;
// Overwrite the data part of `ptr` so it points to `buf`.
unsafe { (&mut ptr as *mut _ as *mut *const u8).write(&buf as *const _ as *const u8); }
// Re-borrow that. This should be UB.
let _ptr = &*ptr; //~ ERROR alignment 256 is required
for _ in 0..10 { // Try many times as this might work by chance.
let buf = [0u32; 256];
// `buf` is sufficiently aligned for `layout.align` on a `dyn Debug`, but not
// for the actual alignment required by `MuchAlign`.
// We craft a wide reference `&dyn Debug` with the vtable for `MuchAlign`. That should be UB,
// as the reference is not aligned to its dynamic alignment requirements.
let mut ptr = &MuchAlign as &dyn std::fmt::Debug;
// Overwrite the data part of `ptr` so it points to `buf`.
unsafe { (&mut ptr as *mut _ as *mut *const u8).write(&buf as *const _ as *const u8); }
// Re-borrow that. This should be UB.
let _ptr = &*ptr; //~ERROR alignment 256 is required
}
}

View File

@ -9,8 +9,9 @@
fn main() {
let x = &mut [0u8; 3];
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 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);
}

View File

@ -16,6 +16,6 @@ fn main() {
y: 99,
};
let p = unsafe { &foo.x };
let i = *p; //~ ERROR alignment 4 is required
let i = *p; //~ERROR alignment 4 is required
}
}

View File

@ -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 = &x[0] as *const _ as *const u32;
// 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
}
}

View File

@ -2,11 +2,11 @@
// compile-flags: -Zmiri-disable-validation -Zmiri-disable-stacked-borrows
fn main() {
for _ in 0..10 { // Try many times as this might work by chance.
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;
// This must fail because alignment is violated: the offset is not sufficiently aligned.
// 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
}
// 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;
// This must fail because alignment is violated: the offset is not sufficiently aligned.
// 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
}

View File

@ -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
// This must fail because alignment is violated. Test specifically for loading pointers,
// which have special code in miri's memory.
let _x = unsafe { *x };
//~^ ERROR but alignment
let _x = unsafe { *x }; //~ERROR but alignment
}
}

View File

@ -2,9 +2,10 @@
// compile-flags: -Zmiri-disable-validation
fn main() {
let x = &2u8;
let x = x as *const _ as *const [u32; 0];
// This must fail because alignment is violated. Test specifically for loading ZST.
let _x = unsafe { *x };
//~^ ERROR alignment 4 is required
for _ in 0..10 { // Try many times as this might work by chance.
let x = &2u8;
let x = x as *const _ as *const [u32; 0];
// This must fail because alignment is violated. Test specifically for loading ZST.
let _x = unsafe { *x }; //~ERROR alignment 4 is required
}
}