Skip to content

Commit f4a1544

Browse files
committed
fix comment in alignment test
1 parent 8e73db6 commit f4a1544

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
fn main() {
2-
// miri always gives allocations the worst possible alignment, so a `u8` array is guaranteed
3-
// to be at the virtual location 1 (so one byte offset from the ultimate alignemnt location 0)
42
let mut x = [0u8; 20];
53
let x_ptr: *mut u8 = x.as_mut_ptr();
6-
let y_ptr = x_ptr as *mut u64;
4+
// At least one of these is definitely unaligned.
5+
// Currently, we guarantee to complain about the first one already (https://github.com/rust-lang/miri/issues/1074).
76
unsafe {
8-
*y_ptr = 42; //~ ERROR accessing memory with alignment 1, but alignment
7+
*(x_ptr as *mut u64) = 42; //~ ERROR accessing memory with alignment 1, but alignment
8+
*(x_ptr.add(1) as *mut u64) = 42;
99
}
1010
panic!("unreachable in miri");
1111
}

tests/compile-fail/unaligned_pointers/intptrcast_alignment_check.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// that arise from pointers being insufficiently aligned. The only way to achieve
33
// that is not not let programs exploit integer information for alignment, so here
44
// we test that this is indeed the case.
5+
//
6+
// See https://github.com/rust-lang/miri/issues/1074.
57
fn main() {
68
let x = &mut [0u8; 3];
79
let base_addr = x as *mut _ as usize;

0 commit comments

Comments
 (0)