Skip to content

Commit ed24d8a

Browse files
authored
Unrolled build for #151628
Rollup merge of #151628 - enthropy7:fix-simd-const-eval-ice, r=RalfJung Fix ICE in const eval of packed SIMD types with non-power-of-two element counts fixes #151537 const evaluation of packed SIMD types with non-power-of-two element counts (like `Simd<_, 3>`) was hitting an ICE. the issue was in `check_simd_ptr_alignment` - it asserted that `backend_repr` must be `BackendRepr::SimdVector`, but for packed SIMD types with non-power-of-two counts the compiler uses `BackendRepr::Memory` instead (as mentioned in `rustc_abi/src/layout.rs:1511`). was fixed by making `check_simd_ptr_alignment` accept both `BackendRepr::SimdVector` and `BackendRepr::Memory` for SIMD types. added a check to ensure we're dealing with a SIMD type, and the alignment logic works the same for both representations. also i added a test that reproduces the original ICE.
2 parents d8b2222 + c45a513 commit ed24d8a

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

‎compiler/rustc_const_eval/src/interpret/intrinsics/simd.rs‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use either::Either;
22
use rustc_abi::{BackendRepr, Endian};
33
use rustc_apfloat::ieee::{Double, Half, Quad, Single};
44
use rustc_apfloat::{Float, Round};
5-
use rustc_data_structures::assert_matches;
65
use rustc_middle::mir::interpret::{InterpErrorKind, Pointer, UndefinedBehaviorInfo};
76
use rustc_middle::ty::{FloatTy, ScalarInt, SimdAlign};
87
use rustc_middle::{bug, err_ub_format, mir, span_bug, throw_unsup_format, ty};
@@ -838,7 +837,20 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
838837
vector_layout: TyAndLayout<'tcx>,
839838
alignment: SimdAlign,
840839
) -> InterpResult<'tcx> {
841-
assert_matches!(vector_layout.backend_repr, BackendRepr::SimdVector { .. });
840+
// Packed SIMD types with non-power-of-two element counts use BackendRepr::Memory
841+
// instead of BackendRepr::SimdVector. We need to handle both cases.
842+
// FIXME: remove the BackendRepr::Memory case when SIMD vectors are always passed as BackendRepr::SimdVector.
843+
assert!(vector_layout.ty.is_simd(), "check_simd_ptr_alignment called on non-SIMD type");
844+
match vector_layout.backend_repr {
845+
BackendRepr::SimdVector { .. } | BackendRepr::Memory { .. } => {}
846+
_ => {
847+
span_bug!(
848+
self.cur_span(),
849+
"SIMD type has unexpected backend_repr: {:?}",
850+
vector_layout.backend_repr
851+
);
852+
}
853+
}
842854

843855
let align = match alignment {
844856
ty::SimdAlign::Unaligned => {
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//@ check-pass
2+
// Fixes #151537
3+
#![feature(portable_simd, core_intrinsics)]
4+
use std::intrinsics::simd::SimdAlign;
5+
use std::{ptr::null, simd::prelude::*};
6+
7+
const _: () = {
8+
let c = Simd::from_array([0; 3]);
9+
unsafe {
10+
core::intrinsics::simd::simd_masked_store::<_, _, _, { SimdAlign::Element }>(
11+
c,
12+
null::<i32>(),
13+
c,
14+
)
15+
};
16+
};
17+
18+
fn main() {}

0 commit comments

Comments
 (0)