Skip to content

Commit fd0bcfb

Browse files
committed
Auto merge of #130253 - workingjubilee:rollup-npqpnaf, r=workingjubilee
Rollup of 10 pull requests Successful merges: - #129103 (Don't warn empty branches unreachable for now) - #129696 (update stdarch) - #129835 (enable const-float-classify test, and test_next_up/down on 32bit x86) - #130077 (Fix linking error when compiling for 32-bit watchOS) - #130114 (Remove needless returns detected by clippy in the compiler) - #130168 (maint: update docs for change_time ext and doc links) - #130228 (notify Miri when intrinsics are changed) - #130239 (miri: fix overflow detection for unsigned pointer offset) - #130244 (Use the same span for attributes and Try expansion of ?) - #130248 (Limit `libc::link` usage to `nto70` target only, not NTO OS) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 1afc45c + 81dda27 commit fd0bcfb

File tree

5 files changed

+36
-9
lines changed

5 files changed

+36
-9
lines changed

src/intrinsics/simd.rs

+6-9
Original file line numberDiff line numberDiff line change
@@ -666,22 +666,19 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
666666
let (right, right_len) = this.operand_to_simd(right)?;
667667
let (dest, dest_len) = this.mplace_to_simd(dest)?;
668668

669-
// `index` is an array, not a SIMD type
670-
let ty::Array(_, index_len) = index.layout.ty.kind() else {
671-
span_bug!(
672-
this.cur_span(),
673-
"simd_shuffle index argument has non-array type {}",
674-
index.layout.ty
675-
)
669+
// `index` is an array or a SIMD type
670+
let (index, index_len) = match index.layout.ty.kind() {
671+
// FIXME: remove this once `index` must always be a SIMD vector.
672+
ty::Array(..) => (index.assert_mem_place(), index.len(this)?),
673+
_ => this.operand_to_simd(index)?,
676674
};
677-
let index_len = index_len.eval_target_usize(*this.tcx, this.param_env());
678675

679676
assert_eq!(left_len, right_len);
680677
assert_eq!(index_len, dest_len);
681678

682679
for i in 0..dest_len {
683680
let src_index: u64 = this
684-
.read_immediate(&this.project_index(index, i)?)?
681+
.read_immediate(&this.project_index(&index, i)?)?
685682
.to_scalar()
686683
.to_u32()?
687684
.into();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
fn main() {
2+
let x = &[0i32; 2];
3+
let x = x.as_ptr().wrapping_add(1);
4+
// If the `!0` is interpreted as `isize`, it is just `-1` and hence harmless.
5+
// However, this is unsigned arithmetic, so really this is `usize::MAX` and hence UB.
6+
unsafe { x.byte_add(!0).read() }; //~ERROR: does not fit in an `isize`
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
error: Undefined Behavior: overflowing pointer arithmetic: the total offset in bytes does not fit in an `isize`
2+
--> $DIR/ptr_offset_unsigned_overflow.rs:LL:CC
3+
|
4+
LL | unsafe { x.byte_add(!0).read() };
5+
| ^^^^^^^^^^^^^^ overflowing pointer arithmetic: the total offset in bytes does not fit in an `isize`
6+
|
7+
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
8+
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
9+
= note: BACKTRACE:
10+
= note: inside `main` at $DIR/ptr_offset_unsigned_overflow.rs:LL:CC
11+
12+
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
13+
14+
error: aborting due to 1 previous error
15+

tests/pass/intrinsics/portable-simd.rs

+8
Original file line numberDiff line numberDiff line change
@@ -620,6 +620,10 @@ fn simd_intrinsics() {
620620
);
621621
assert_eq!(simd_shuffle_generic::<_, i32x4, { &[3, 1, 0, 2] }>(a, b), a,);
622622
assert_eq!(simd_shuffle::<_, _, i32x4>(a, b, const { [3u32, 1, 0, 2] }), a,);
623+
assert_eq!(
624+
simd_shuffle::<_, _, i32x4>(a, b, const { u32x4::from_array([3u32, 1, 0, 2]) }),
625+
a,
626+
);
623627
assert_eq!(
624628
simd_shuffle_generic::<_, i32x4, { &[7, 5, 4, 6] }>(a, b),
625629
i32x4::from_array([4, 2, 1, 10]),
@@ -628,6 +632,10 @@ fn simd_intrinsics() {
628632
simd_shuffle::<_, _, i32x4>(a, b, const { [7u32, 5, 4, 6] }),
629633
i32x4::from_array([4, 2, 1, 10]),
630634
);
635+
assert_eq!(
636+
simd_shuffle::<_, _, i32x4>(a, b, const { u32x4::from_array([7u32, 5, 4, 6]) }),
637+
i32x4::from_array([4, 2, 1, 10]),
638+
);
631639
}
632640
}
633641

0 commit comments

Comments
 (0)