Skip to content

Commit

Permalink
Make the intention of the miri test more clear
Browse files Browse the repository at this point in the history
  • Loading branch information
adwinwhite committed Sep 19, 2024
1 parent c4574cb commit 937b09b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/tools/miri/tests/fail/uninit/padding-enum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ fn main() {

// Turns out the discriminant is (currently) stored
// in the 1st pointer, so the second half is padding.
let c = (&p as *const mem::MaybeUninit<E>).byte_add(mem::size_of::<&'static ()>()) as *const u8;
let c = &p as *const _ as *const u8;
let padding_offset = mem::size_of::<&'static ()>();
// Read a padding byte.
let _val = *c.add(0);
let _val = *c.add(padding_offset);
//~^ERROR: uninitialized
}
}
4 changes: 2 additions & 2 deletions src/tools/miri/tests/fail/uninit/padding-enum.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
error: Undefined Behavior: using uninitialized data, but this operation requires initialized memory
--> tests/fail/uninit/padding-enum.rs:LL:CC
|
LL | let _val = *c.add(0);
| ^^^^^^^^^ using uninitialized data, but this operation requires initialized memory
LL | let _val = *c.add(padding_offset);
| ^^^^^^^^^^^^^^^^^^^^^^ using uninitialized data, but this operation requires initialized memory
|
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
Expand Down

0 comments on commit 937b09b

Please sign in to comment.