-
Notifications
You must be signed in to change notification settings - Fork 347
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #863 - RalfJung:deref-checks, r=RalfJung
adjust tests for eager pointer checks on deref The Miri side of rust-lang/rust#63075. Fixes #447.
- Loading branch information
Showing
8 changed files
with
21 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
00ee1b47f42129a0a6e33510578fbcf07c1e5382 | ||
1cdcea920e56a5d0587307a4c9cf8fff5c77c4bc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// This should fail even without validation. | ||
// compile-flags: -Zmiri-disable-validation | ||
|
||
fn main() { | ||
let x = 2usize as *const u32; | ||
let _y = unsafe { &*x as *const u32 }; //~ ERROR dangling pointer was dereferenced | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// Deref a raw ptr to access a field of a large struct, where the field | ||
// is allocated but not the entire struct is. | ||
fn main() { | ||
let x = (1, 13); | ||
let xptr = &x as *const _ as *const (i32, i32, i32); | ||
let val = unsafe { (*xptr).1 }; //~ ERROR pointer must be in-bounds at offset 12, but is outside bounds of allocation | ||
assert_eq!(val, 13); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,12 @@ | ||
// Validation makes this fail in the wrong place | ||
// compile-flags: -Zmiri-disable-validation | ||
|
||
// Even with intptrcast and without validation, we want to be *sure* to catch bugs | ||
// 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. | ||
fn main() { | ||
let x = &mut [0u8; 3]; | ||
let base_addr = x as *mut _ as usize; | ||
let u16_ref = unsafe { if base_addr % 2 == 0 { | ||
&mut *(base_addr as *mut u16) | ||
} else { | ||
&mut *((base_addr+1) as *mut u16) | ||
} }; | ||
*u16_ref = 2; //~ ERROR tried to access memory with alignment 1, but alignment 2 is required | ||
let base_addr_aligned = if base_addr % 2 == 0 { base_addr } else { base_addr+1 }; | ||
let u16_ptr = base_addr_aligned as *mut u16; | ||
unsafe { *u16_ptr = 2; } //~ ERROR tried to access memory with alignment 1, but alignment 2 is required | ||
println!("{:?}", x); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters