diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2024-09-15 16:01:38 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-09-15 16:01:38 +0200 |
| commit | 96195a5e240bac2061a828c8016ad73a3b9f2d37 (patch) | |
| tree | 3c3c1a494707c103924d81deee7cf9e400901093 /tests | |
| parent | 18a93ca65ef4fc97e0455c52c460826b50594ea1 (diff) | |
| parent | 268f6cf558fd689459648d702e67395908e7a6c5 (diff) | |
| download | rust-96195a5e240bac2061a828c8016ad73a3b9f2d37.tar.gz rust-96195a5e240bac2061a828c8016ad73a3b9f2d37.zip | |
Rollup merge of #130342 - RalfJung:slice-idx-overflow, r=saethlin
interpret, miri: fix dealing with overflow during slice indexing and allocation This is mostly to fix https://github.com/rust-lang/rust/issues/130284. I then realized we're using somewhat sketchy arguments for a similar multiplication in `copy`/`copy_nonoverlapping`/`write_bytes`, so I made them all share the same function that checks exactly the right thing. (The intrinsics would previously fail on allocations larger than `1 << 47` bytes... which are theoretically possible maybe? Anyway it seems conceptually wrong to use any other bound than `isize::MAX` here.)
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`. |
