-
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 #787 - RalfJung:pointer-checks, r=RalfJung
adjust for refactored memory pointer checks The Miri side of rust-lang/rust#62081.
- Loading branch information
Showing
20 changed files
with
107 additions
and
53 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 @@ | ||
305930cffeac1da0fd73a08d9f5680e4a49bfb9f | ||
7e08576e4276a97b523c25bfd196d419c39c7b87 |
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
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
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
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,9 @@ | ||
// This should fail even without validation | ||
// compile-flags: -Zmiri-disable-validation | ||
|
||
fn main() { | ||
let x = [2u16, 3, 4]; // Make it big enough so we don't get an out-of-bounds error. | ||
let x = &x[0] as *const _ as *const u32; | ||
// This must fail because alignment is violated: the allocation's base is not sufficiently aligned. | ||
let _x = unsafe { *x }; //~ ERROR tried to access memory with alignment 2, but alignment 4 is required | ||
} |
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,10 @@ | ||
// This should fail even without validation. | ||
// compile-flags: -Zmiri-disable-validation | ||
|
||
fn main() { | ||
let x = [2u32, 3]; // Make it big enough so we don't get an out-of-bounds error. | ||
let x = (x.as_ptr() as *const u8).wrapping_offset(3) as *const u32; | ||
// This must fail because alignment is violated: the offset is not sufficiently aligned. | ||
// Also make the offset not a power of 2, that used to ICE. | ||
let _x = unsafe { *x }; //~ ERROR tried to access memory with alignment 1, but alignment 4 is required | ||
} |
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.
3 changes: 3 additions & 0 deletions
3
tests/compile-fail/unaligned_ptr_cast_zst.rs → tests/compile-fail/unaligned_ptr_zst.rs
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
use std::mem; | ||
|
||
fn main() { | ||
let _x: &i32 = unsafe { mem::transmute(16usize) }; //~ ERROR tried to interpret some bytes as a pointer | ||
let _x: &i32 = unsafe { mem::transmute(16usize) }; //~ ERROR integer pointer in non-ZST reference | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
fn main() { | ||
// make sure ZST locals cannot be accessed | ||
let x = &() as *const () as *const i8; | ||
let _val = unsafe { *x }; //~ ERROR pointer must be in-bounds | ||
} |
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,12 @@ | ||
fn main() { | ||
// Not using the () type here, as writes of that type do not even have MIR generated. | ||
// Also not assigning directly as that's array initialization, not assignment. | ||
let zst_val = [1u8; 0]; | ||
|
||
// make sure ZST accesses are checked against being "truly" dangling pointers | ||
// (into deallocated allocations). | ||
let mut x_box = Box::new(1u8); | ||
let x = &mut *x_box as *mut _ as *mut [u8; 0]; | ||
drop(x_box); | ||
unsafe { *x = zst_val; } //~ 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,15 @@ | ||
fn main() { | ||
// Not using the () type here, as writes of that type do not even have MIR generated. | ||
// Also not assigning directly as that's array initialization, not assignment. | ||
let zst_val = [1u8; 0]; | ||
|
||
// make sure ZST accesses are checked against being "truly" dangling pointers | ||
// (that are out-of-bounds). | ||
let mut x_box = Box::new(1u8); | ||
let x = (&mut *x_box as *mut u8).wrapping_offset(1); | ||
// This one is just "at the edge", but still okay | ||
unsafe { *(x as *mut [u8; 0]) = zst_val; } | ||
// One byte further is OOB. | ||
let x = x.wrapping_offset(1); | ||
unsafe { *(x as *mut [u8; 0]) = zst_val; } //~ ERROR pointer must be in-bounds | ||
} |
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