Skip to content

Commit 8733aba

Browse files
Rollup merge of #122249 - RalfJung:machine-read-hook, r=oli-obk
interpret: do not call machine read hooks during validation Fixes #3347 r? ``@oli-obk``
2 parents b770e3a + ab392a8 commit 8733aba

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
lines changed

tests/pass/alloc-access-tracking.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#![feature(start)]
2+
#![no_std]
3+
//@compile-flags: -Zmiri-track-alloc-id=17 -Zmiri-track-alloc-accesses -Cpanic=abort
4+
//@only-target-linux: alloc IDs differ between OSes for some reason
5+
6+
extern "Rust" {
7+
fn miri_alloc(size: usize, align: usize) -> *mut u8;
8+
fn miri_dealloc(ptr: *mut u8, size: usize, align: usize);
9+
}
10+
11+
#[start]
12+
fn start(_: isize, _: *const *const u8) -> isize {
13+
unsafe {
14+
let ptr = miri_alloc(123, 1);
15+
*ptr = 42; // Crucially, only a write is printed here, no read!
16+
assert_eq!(*ptr, 42);
17+
miri_dealloc(ptr, 123, 1);
18+
}
19+
0
20+
}
21+
22+
#[panic_handler]
23+
fn panic_handler(_: &core::panic::PanicInfo) -> ! {
24+
loop {}
25+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
note: tracking was triggered
2+
--> $DIR/alloc-access-tracking.rs:LL:CC
3+
|
4+
LL | let ptr = miri_alloc(123, 1);
5+
| ^^^^^^^^^^^^^^^^^^ created Miri bare-metal heap allocation of 123 bytes (alignment ALIGN bytes) with id 17
6+
|
7+
= note: BACKTRACE:
8+
= note: inside `start` at $DIR/alloc-access-tracking.rs:LL:CC
9+
10+
note: tracking was triggered
11+
--> $DIR/alloc-access-tracking.rs:LL:CC
12+
|
13+
LL | *ptr = 42; // Crucially, only a write is printed here, no read!
14+
| ^^^^^^^^^ write access to allocation with id 17
15+
|
16+
= note: BACKTRACE:
17+
= note: inside `start` at $DIR/alloc-access-tracking.rs:LL:CC
18+
19+
note: tracking was triggered
20+
--> $DIR/alloc-access-tracking.rs:LL:CC
21+
|
22+
LL | assert_eq!(*ptr, 42);
23+
| ^^^^^^^^^^^^^^^^^^^^ read access to allocation with id 17
24+
|
25+
= note: BACKTRACE:
26+
= note: inside `start` at RUSTLIB/core/src/macros/mod.rs:LL:CC
27+
= note: this note originates in the macro `assert_eq` (in Nightly builds, run with -Z macro-backtrace for more info)
28+
29+
note: tracking was triggered
30+
--> $DIR/alloc-access-tracking.rs:LL:CC
31+
|
32+
LL | miri_dealloc(ptr, 123, 1);
33+
| ^^^^^^^^^^^^^^^^^^^^^^^^^ freed allocation with id 17
34+
|
35+
= note: BACKTRACE:
36+
= note: inside `start` at $DIR/alloc-access-tracking.rs:LL:CC
37+

0 commit comments

Comments
 (0)