forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#124923 - RalfJung:offset-from-errors, r=compiler-errors interpret/miri: better errors on failing offset_from Fixes rust-lang/miri#3104
- Loading branch information
Showing
6 changed files
with
67 additions
and
27 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
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
21 changes: 21 additions & 0 deletions
21
src/tools/miri/tests/fail/intrinsics/ptr_offset_from_different_ints.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#![feature(strict_provenance)] | ||
use core::ptr; | ||
|
||
fn main() { | ||
unsafe { | ||
let base = ptr::without_provenance::<()>(10); | ||
let unit = &*base; | ||
let p1 = unit as *const (); | ||
|
||
let base = ptr::without_provenance::<()>(11); | ||
let unit = &*base; | ||
let p2 = unit as *const (); | ||
|
||
// Seems to work because they are same pointer | ||
// even though it's dangling. | ||
let _ = p1.byte_offset_from(p1); | ||
|
||
// UB because different pointers. | ||
let _ = p1.byte_offset_from(p2); //~ERROR: different pointers without provenance | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/tools/miri/tests/fail/intrinsics/ptr_offset_from_different_ints.stderr
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 @@ | ||
error: Undefined Behavior: `ptr_offset_from` called on different pointers without provenance (i.e., without an associated allocation) | ||
--> $DIR/ptr_offset_from_different_ints.rs:LL:CC | ||
| | ||
LL | let _ = p1.byte_offset_from(p2); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^ `ptr_offset_from` called on different pointers without provenance (i.e., without an associated 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 $DIR/ptr_offset_from_different_ints.rs:LL:CC | ||
|
||
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace | ||
|
||
error: aborting due to 1 previous error | ||
|
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