diff options
| author | bors <bors@rust-lang.org> | 2024-09-17 17:25:43 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2024-09-17 17:25:43 +0000 |
| commit | 62ccf6a4343b0055fd7273a1d0954ecc5b74ace2 (patch) | |
| tree | 12a79a60952cbc6b668b8824da6ed94e40e8f71f | |
| parent | ba86cf8686399953e97e82177b201354d808241d (diff) | |
| parent | 4854ca74112cfcdffc2d41a876a9870a89f6f2b4 (diff) | |
| download | rust-62ccf6a4343b0055fd7273a1d0954ecc5b74ace2.tar.gz rust-62ccf6a4343b0055fd7273a1d0954ecc5b74ace2.zip | |
Auto merge of #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.
| -rw-r--r-- | src/tools/miri/tests/fail/intrinsics/ptr_offset_unsigned_overflow.rs | 7 | ||||
| -rw-r--r-- | src/tools/miri/tests/fail/intrinsics/ptr_offset_unsigned_overflow.stderr | 4 |
2 files changed, 6 insertions, 5 deletions
diff --git a/src/tools/miri/tests/fail/intrinsics/ptr_offset_unsigned_overflow.rs b/src/tools/miri/tests/fail/intrinsics/ptr_offset_unsigned_overflow.rs index a2739842bc1..a0fa49d3d6f 100644 --- a/src/tools/miri/tests/fail/intrinsics/ptr_offset_unsigned_overflow.rs +++ b/src/tools/miri/tests/fail/intrinsics/ptr_offset_unsigned_overflow.rs @@ -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` } diff --git a/src/tools/miri/tests/fail/intrinsics/ptr_offset_unsigned_overflow.stderr b/src/tools/miri/tests/fail/intrinsics/ptr_offset_unsigned_overflow.stderr index a5f046ec403..e03bdfdb85d 100644 --- a/src/tools/miri/tests/fail/intrinsics/ptr_offset_unsigned_overflow.stderr +++ b/src/tools/miri/tests/fail/intrinsics/ptr_offset_unsigned_overflow.stderr @@ -1,8 +1,8 @@ error: Undefined Behavior: overflowing pointer arithmetic: the total offset in bytes does not fit in an `isize` --> tests/fail/intrinsics/ptr_offset_unsigned_overflow.rs:LL:CC | -LL | unsafe { x.byte_add(!0).read() }; - | ^^^^^^^^^^^^^^ overflowing pointer arithmetic: the total offset in bytes does not fit in an `isize` +LL | let _ = unsafe { x.byte_add(usize::MAX) }; + | ^^^^^^^^^^^^^^^^^^^^^^ overflowing pointer arithmetic: the total offset in bytes does not fit in an `isize` | = 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 |
