-8cdc94e84040ce797fd33d0a7cfda4ec4f2f2421
+515c9fa505e18a65d7f61bc3e9eb833b79a68618
// 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.
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
}
}
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
+ }
}
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);
}
y: 99,
};
let p = unsafe { &foo.x };
- let i = *p; //~ ERROR alignment 4 is required
+ let i = *p; //~ERROR alignment 4 is required
}
}
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
}
}
// 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
}
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
}
}
// 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
+ }
}