diff --git a/rust-version b/rust-version index 4fbaee9dcb..c2850a9f9f 100644 --- a/rust-version +++ b/rust-version @@ -1 +1 @@ -a9fb00bfa4b3038c855b2097b54e05e8c198c183 +6c65d4f47f82836f303026ec70f752e30d586bd4 diff --git a/src/intrinsics/simd.rs b/src/intrinsics/simd.rs index a5afd029b6..85d7459bb4 100644 --- a/src/intrinsics/simd.rs +++ b/src/intrinsics/simd.rs @@ -666,22 +666,19 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { let (right, right_len) = this.operand_to_simd(right)?; let (dest, dest_len) = this.mplace_to_simd(dest)?; - // `index` is an array, not a SIMD type - let ty::Array(_, index_len) = index.layout.ty.kind() else { - span_bug!( - this.cur_span(), - "simd_shuffle index argument has non-array type {}", - index.layout.ty - ) + // `index` is an array or a SIMD type + let (index, index_len) = match index.layout.ty.kind() { + // FIXME: remove this once `index` must always be a SIMD vector. + ty::Array(..) => (index.assert_mem_place(), index.len(this)?), + _ => this.operand_to_simd(index)?, }; - let index_len = index_len.eval_target_usize(*this.tcx, this.param_env()); assert_eq!(left_len, right_len); assert_eq!(index_len, dest_len); for i in 0..dest_len { let src_index: u64 = this - .read_immediate(&this.project_index(index, i)?)? + .read_immediate(&this.project_index(&index, i)?)? .to_scalar() .to_u32()? .into(); diff --git a/tests/fail/intrinsics/ptr_offset_unsigned_overflow.rs b/tests/fail/intrinsics/ptr_offset_unsigned_overflow.rs new file mode 100644 index 0000000000..a2739842bc --- /dev/null +++ b/tests/fail/intrinsics/ptr_offset_unsigned_overflow.rs @@ -0,0 +1,7 @@ +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` +} diff --git a/tests/fail/intrinsics/ptr_offset_unsigned_overflow.stderr b/tests/fail/intrinsics/ptr_offset_unsigned_overflow.stderr new file mode 100644 index 0000000000..43cd80a6d3 --- /dev/null +++ b/tests/fail/intrinsics/ptr_offset_unsigned_overflow.stderr @@ -0,0 +1,15 @@ +error: Undefined Behavior: overflowing pointer arithmetic: the total offset in bytes does not fit in an `isize` + --> $DIR/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` + | + = 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_unsigned_overflow.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 + diff --git a/tests/pass/intrinsics/portable-simd.rs b/tests/pass/intrinsics/portable-simd.rs index c4ba11d0a4..daf75fee8f 100644 --- a/tests/pass/intrinsics/portable-simd.rs +++ b/tests/pass/intrinsics/portable-simd.rs @@ -620,6 +620,10 @@ fn simd_intrinsics() { ); assert_eq!(simd_shuffle_generic::<_, i32x4, { &[3, 1, 0, 2] }>(a, b), a,); assert_eq!(simd_shuffle::<_, _, i32x4>(a, b, const { [3u32, 1, 0, 2] }), a,); + assert_eq!( + simd_shuffle::<_, _, i32x4>(a, b, const { u32x4::from_array([3u32, 1, 0, 2]) }), + a, + ); assert_eq!( simd_shuffle_generic::<_, i32x4, { &[7, 5, 4, 6] }>(a, b), i32x4::from_array([4, 2, 1, 10]), @@ -628,6 +632,10 @@ fn simd_intrinsics() { simd_shuffle::<_, _, i32x4>(a, b, const { [7u32, 5, 4, 6] }), i32x4::from_array([4, 2, 1, 10]), ); + assert_eq!( + simd_shuffle::<_, _, i32x4>(a, b, const { u32x4::from_array([7u32, 5, 4, 6]) }), + i32x4::from_array([4, 2, 1, 10]), + ); } } diff --git a/tests/pass/simd-intrinsic-generic-elements.rs b/tests/pass/intrinsics/simd-intrinsic-generic-elements.rs similarity index 100% rename from tests/pass/simd-intrinsic-generic-elements.rs rename to tests/pass/intrinsics/simd-intrinsic-generic-elements.rs