File tree Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Original file line number Diff line number Diff line change
1
+ // Validation makes this fail in the wrong place
2
+ // compile-flags: -Zmiri-disable-validation -Zmiri-seed=0000000000000000
3
+
4
+ // Even with intptrcast and without validation, we want to be *sure* to catch bugs
5
+ // that arise from pointers being insufficiently aligned. The only way to achieve
6
+ // that is not not let programs exploit integer information for alignment, so here
7
+ // we test that this is indeed the case.
8
+ fn main ( ) {
9
+ let x = & mut [ 0u8 ; 3 ] ;
10
+ let base_addr = x as * mut _ as usize ;
11
+ let u16_ref = unsafe { if base_addr % 2 == 0 {
12
+ & mut * ( base_addr as * mut u16 )
13
+ } else {
14
+ & mut * ( ( base_addr+1 ) as * mut u16 )
15
+ } } ;
16
+ * u16_ref = 2 ; //~ ERROR tried to access memory with alignment 1, but alignment 2 is required
17
+ println ! ( "{:?}" , x) ;
18
+ }
You can’t perform that action at this time.
0 commit comments