diff options
| author | Ralf Jung <post@ralfj.de> | 2024-09-14 10:00:02 +0200 |
|---|---|---|
| committer | Ralf Jung <post@ralfj.de> | 2024-09-14 10:00:07 +0200 |
| commit | 3b806d337c0cb83bde42a7d4898ff183f888c488 (patch) | |
| tree | c0f4d89a65096d19a212769f3706b82694b24403 /tests | |
| parent | 0307e401c26699656ae08e3809e7d272f5c103f4 (diff) | |
| download | rust-3b806d337c0cb83bde42a7d4898ff183f888c488.tar.gz rust-3b806d337c0cb83bde42a7d4898ff183f888c488.zip | |
interpret: fix dealing with overflow during slice indexing
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/ui/consts/slice-index-overflow-issue-130284.rs | 13 | ||||
| -rw-r--r-- | tests/ui/consts/slice-index-overflow-issue-130284.stderr | 9 |
2 files changed, 22 insertions, 0 deletions
diff --git a/tests/ui/consts/slice-index-overflow-issue-130284.rs b/tests/ui/consts/slice-index-overflow-issue-130284.rs new file mode 100644 index 00000000000..29900908256 --- /dev/null +++ b/tests/ui/consts/slice-index-overflow-issue-130284.rs @@ -0,0 +1,13 @@ +const C: () = { + let value = [1, 2]; + let ptr = value.as_ptr().wrapping_add(2); + let fat = std::ptr::slice_from_raw_parts(ptr, usize::MAX); + unsafe { + // This used to ICE, but it should just report UB. + let _ice = (*fat)[usize::MAX - 1]; + //~^ERROR: constant value failed + //~| overflow + } +}; + +fn main() {} diff --git a/tests/ui/consts/slice-index-overflow-issue-130284.stderr b/tests/ui/consts/slice-index-overflow-issue-130284.stderr new file mode 100644 index 00000000000..e3e676c8949 --- /dev/null +++ b/tests/ui/consts/slice-index-overflow-issue-130284.stderr @@ -0,0 +1,9 @@ +error[E0080]: evaluation of constant value failed + --> $DIR/slice-index-overflow-issue-130284.rs:7:20 + | +LL | let _ice = (*fat)[usize::MAX - 1]; + | ^^^^^^^^^^^^^^^^^^^^^^ overflowing pointer arithmetic: the total offset in bytes does not fit in an `isize` + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0080`. |
