Skip to content

Commit 99ec9c1

Browse files
committed
Auto merge of #1854 - RalfJung:partial-ptr-overwrite, r=RalfJung
adjust for ERR_ON_PARTIAL_PTR_OVERWRITE The Miri side of rust-lang/rust#87248
2 parents 1f969da + 3a92228 commit 99ec9c1

File tree

4 files changed

+11
-2
lines changed

4 files changed

+11
-2
lines changed

rust-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3bc9dd0dd293ab82945e35888ed6d7ab802761ef
1+
3227e35765bab6d02c581928e26ad1d34bacf394

src/machine.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,13 +123,17 @@ impl fmt::Display for MiriMemoryKind {
123123
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
124124
pub struct Tag {
125125
pub alloc_id: AllocId,
126-
// Stacked Borrows tag.
126+
/// Stacked Borrows tag.
127127
pub sb: SbTag,
128128
}
129129

130130
impl Provenance for Tag {
131+
/// We use absolute addresses in the `offset` of a `Pointer<Tag>`.
131132
const OFFSET_IS_ADDR: bool = true;
132133

134+
/// We cannot err on partial overwrites, it happens too often in practice (due to unions).
135+
const ERR_ON_PARTIAL_PTR_OVERWRITE: bool = false;
136+
133137
fn fmt(ptr: &Pointer<Self>, f: &mut fmt::Formatter<'_>) -> fmt::Result {
134138
let (tag, addr) = ptr.into_parts(); // address is absolute
135139
write!(f, "0x{:x}", addr.bytes())?;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
// Make sure we find these even with many checks disabled.
22
// compile-flags: -Zmiri-disable-alignment-check -Zmiri-disable-stacked-borrows -Zmiri-disable-validation
33

4+
// Test what happens when we overwrite parts of a pointer.
5+
// Also see <https://github.com/rust-lang/rust/issues/87184>.
6+
47
fn main() {
58
let mut p = &42;
69
unsafe {

tests/compile-fail/pointer_byte_read.rs renamed to tests/compile-fail/pointer_partial_read.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// Test what happens when we read parts of a pointer.
2+
// Related to <https://github.com/rust-lang/rust/issues/69488>.
13
fn main() {
24
let x = 13;
35
let y = &x;

0 commit comments

Comments
 (0)