Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions compiler/rustc_const_eval/src/interpret/intrinsics/simd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use either::Either;
use rustc_abi::{BackendRepr, Endian};
use rustc_apfloat::ieee::{Double, Half, Quad, Single};
use rustc_apfloat::{Float, Round};
use rustc_data_structures::assert_matches;
use rustc_middle::mir::interpret::{InterpErrorKind, Pointer, UndefinedBehaviorInfo};
use rustc_middle::ty::{FloatTy, ScalarInt, SimdAlign};
use rustc_middle::{bug, err_ub_format, mir, span_bug, throw_unsup_format, ty};
Expand Down Expand Up @@ -829,7 +828,20 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
vector_layout: TyAndLayout<'tcx>,
alignment: SimdAlign,
) -> InterpResult<'tcx> {
assert_matches!(vector_layout.backend_repr, BackendRepr::SimdVector { .. });
// Packed SIMD types with non-power-of-two element counts use BackendRepr::Memory
// instead of BackendRepr::SimdVector. We need to handle both cases.
// FIXME: remove the BackendRepr::Memory case when SIMD vectors are always passed as BackendRepr::SimdVector.
assert!(vector_layout.ty.is_simd(), "check_simd_ptr_alignment called on non-SIMD type");
match vector_layout.backend_repr {
BackendRepr::SimdVector { .. } | BackendRepr::Memory { .. } => {}
_ => {
span_bug!(
self.cur_span(),
"SIMD type has unexpected backend_repr: {:?}",
vector_layout.backend_repr
);
}
}

let align = match alignment {
ty::SimdAlign::Unaligned => {
Expand Down
18 changes: 18 additions & 0 deletions tests/ui/consts/const-eval/simd/simd-packed-non-pow2.rs
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a link to the issue that is fixed by this PR as a comment inside this test.

Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//@ check-pass
// Fixes #151537
#![feature(portable_simd, core_intrinsics)]
use std::intrinsics::simd::SimdAlign;
use std::{ptr::null, simd::prelude::*};

const _: () = {
let c = Simd::from_array([0; 3]);
unsafe {
core::intrinsics::simd::simd_masked_store::<_, _, _, { SimdAlign::Element }>(
c,
null::<i32>(),
c,
)
};
};

fn main() {}
Loading