From aca691160dbeae0c18049d1c23091e644261b528 Mon Sep 17 00:00:00 2001 From: Oliver Schneider Date: Wed, 6 Jul 2016 11:19:24 +0200 Subject: [PATCH] add a test --- tests/compile-fail/alignment.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 tests/compile-fail/alignment.rs diff --git a/tests/compile-fail/alignment.rs b/tests/compile-fail/alignment.rs new file mode 100644 index 000000000000..4faaa359df62 --- /dev/null +++ b/tests/compile-fail/alignment.rs @@ -0,0 +1,11 @@ +fn main() { + // miri always gives allocations the worst possible alignment, so a `u8` array is guaranteed + // to be at the virtual location 1 (so one byte offset from the ultimate alignemnt location 0) + let mut x = [0u8; 20]; + let x_ptr: *mut u8 = &mut x[0]; + let y_ptr = x_ptr as *mut u64; + unsafe { + *y_ptr = 42; //~ ERROR tried to access memory with alignment 1, but alignment + } + panic!("unreachable in miri"); +}