-
Notifications
You must be signed in to change notification settings - Fork 391
Closed
rust-lang/rust
#136438Labels
A-diagnosticserrors and warnings emitted by mirierrors and warnings emitted by miriA-intrinsicsArea: Affects out implementation of Rust intrinsicsArea: Affects out implementation of Rust intrinsicsC-enhancementCategory: a PR with an enhancement or an issue tracking an accepted enhancementCategory: a PR with an enhancement or an issue tracking an accepted enhancement
Description
I ran the following code with Miri:
fn main() {
unsafe {
(&1_u8 as *const u8).offset_from(&2_u8);
}
}
I expected Miri to sensibly report some UB, but instead I got the following:
error: Undefined Behavior: out-of-bounds `offset_from` origin: expected a pointer to the end of 4 bytes of memory, but got alloc4 which is at the beginning of the allocation
--> src/main.rs:3:9
|
3 | (&1_u8 as *const u8).offset_from(&2_u8);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ out-of-bounds `offset_from` origin: expected a pointer to the end of 4 bytes of memory, but got alloc4 which is at the beginning of the allocation
|
= 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
= note: BACKTRACE:
= note: inside `main` at src/main.rs:3:9: 3:48
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
The error message doesn't make any sense. I don't know where Miri got the "4 bytes of memory" expectation from. So I think the error is incorrect.
Reproducible on the playground with rust version 1.86.0-nightly (2025-01-20 f3d1d47fd84dfcf7f513)
Metadata
Metadata
Assignees
Labels
A-diagnosticserrors and warnings emitted by mirierrors and warnings emitted by miriA-intrinsicsArea: Affects out implementation of Rust intrinsicsArea: Affects out implementation of Rust intrinsicsC-enhancementCategory: a PR with an enhancement or an issue tracking an accepted enhancementCategory: a PR with an enhancement or an issue tracking an accepted enhancement