Skip to content

Commit f8a331a

Browse files
committed
fix handling of alignment for dyn-sized places
1 parent b6df7e9 commit f8a331a

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

tests/fail/unaligned_pointers/dyn_alignment.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
// should find the bug even without validation and stacked borrows, but gets masked by optimizations
2-
//@compile-flags: -Zmiri-disable-validation -Zmiri-disable-stacked-borrows -Zmir-opt-level=0 -Cdebug-assertions=no
1+
// should find the bug even without, but gets masked by optimizations
2+
//@compile-flags: -Zmiri-disable-stacked-borrows -Zmir-opt-level=0 -Cdebug-assertions=no
3+
//@normalize-stderr-test: "but found [0-9]+" -> "but found $$ALIGN"
34

45
#[repr(align(256))]
56
#[derive(Debug)]
@@ -19,6 +20,6 @@ fn main() {
1920
(&mut ptr as *mut _ as *mut *const u8).write(&buf as *const _ as *const u8);
2021
}
2122
// Re-borrow that. This should be UB.
22-
let _ptr = &*ptr; //~ERROR: alignment 256 is required
23+
let _ptr = &*ptr; //~ERROR: required 256 byte alignment
2324
}
2425
}

tests/fail/unaligned_pointers/dyn_alignment.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
error: Undefined Behavior: accessing memory with alignment ALIGN, but alignment ALIGN is required
1+
error: Undefined Behavior: constructing invalid value: encountered an unaligned reference (required 256 byte alignment but found $ALIGN)
22
--> $DIR/dyn_alignment.rs:LL:CC
33
|
44
LL | let _ptr = &*ptr;
5-
| ^^^^^ accessing memory with alignment ALIGN, but alignment ALIGN is required
5+
| ^^^^^ constructing invalid value: encountered an unaligned reference (required 256 byte alignment but found $ALIGN)
66
|
77
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
88
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information

0 commit comments

Comments
 (0)