forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of rust-lang#3896 - RalfJung:ptr_offset_unsigned_overflow,…
… r=RalfJung ptr_offset_unsigned_overflow: extend test Test that indeed, the signed version works before the unsigned version is UB.
- Loading branch information
Showing
2 changed files
with
6 additions
and
5 deletions.
There are no files selected for viewing
7 changes: 4 additions & 3 deletions
7
src/tools/miri/tests/fail/intrinsics/ptr_offset_unsigned_overflow.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 |
---|---|---|
@@ -1,7 +1,8 @@ | ||
fn main() { | ||
let x = &[0i32; 2]; | ||
let x = x.as_ptr().wrapping_add(1); | ||
// If the `!0` is interpreted as `isize`, it is just `-1` and hence harmless. | ||
// However, this is unsigned arithmetic, so really this is `usize::MAX` and hence UB. | ||
unsafe { x.byte_add(!0).read() }; //~ERROR: does not fit in an `isize` | ||
// If `usize::MAX` is interpreted as `isize`, it is just `-1` and hence harmless. | ||
let _ = unsafe { x.byte_offset(usize::MAX as isize) }; | ||
// However, `byte_add` uses unsigned arithmetic, so really this is `usize::MAX` and hence UB. | ||
let _ = unsafe { x.byte_add(usize::MAX) }; //~ERROR: does not fit in an `isize` | ||
} |
4 changes: 2 additions & 2 deletions
4
src/tools/miri/tests/fail/intrinsics/ptr_offset_unsigned_overflow.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