From f4a15444cf90452876733549731ab94517656e8b Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Tue, 14 Apr 2020 09:50:20 +0200 Subject: [PATCH] fix comment in alignment test --- tests/compile-fail/unaligned_pointers/alignment.rs | 8 ++++---- .../unaligned_pointers/intptrcast_alignment_check.rs | 2 ++ 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/tests/compile-fail/unaligned_pointers/alignment.rs b/tests/compile-fail/unaligned_pointers/alignment.rs index b732a949af..8532f91a5c 100644 --- a/tests/compile-fail/unaligned_pointers/alignment.rs +++ b/tests/compile-fail/unaligned_pointers/alignment.rs @@ -1,11 +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 = x.as_mut_ptr(); - let y_ptr = x_ptr as *mut u64; + // At least one of these is definitely unaligned. + // Currently, we guarantee to complain about the first one already (https://github.com/rust-lang/miri/issues/1074). unsafe { - *y_ptr = 42; //~ ERROR accessing memory with alignment 1, but alignment + *(x_ptr as *mut u64) = 42; //~ ERROR accessing memory with alignment 1, but alignment + *(x_ptr.add(1) as *mut u64) = 42; } panic!("unreachable in miri"); } diff --git a/tests/compile-fail/unaligned_pointers/intptrcast_alignment_check.rs b/tests/compile-fail/unaligned_pointers/intptrcast_alignment_check.rs index 1a8df5eace..0a3b48dab5 100644 --- a/tests/compile-fail/unaligned_pointers/intptrcast_alignment_check.rs +++ b/tests/compile-fail/unaligned_pointers/intptrcast_alignment_check.rs @@ -2,6 +2,8 @@ // that arise from pointers being insufficiently aligned. The only way to achieve // that is not not let programs exploit integer information for alignment, so here // we test that this is indeed the case. +// +// See https://github.com/rust-lang/miri/issues/1074. fn main() { let x = &mut [0u8; 3]; let base_addr = x as *mut _ as usize;