Forbid old-style simd_shuffleN intrinsics

This commit is contained in:
Oli Scherer 2023-07-10 13:03:48 +00:00
parent e8168ce8a3
commit 2876bb8481

View File

@ -117,8 +117,8 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>(
}); });
} }
// simd_shuffle32<T, U>(x: T, y: T, idx: [u32; 32]) -> U // simd_shuffle<T, I, U>(x: T, y: T, idx: I) -> U
_ if intrinsic.as_str().starts_with("simd_shuffle") => { sym::simd_shuffle => {
let (x, y, idx) = match args { let (x, y, idx) = match args {
[x, y, idx] => (x, y, idx), [x, y, idx] => (x, y, idx),
_ => { _ => {
@ -133,13 +133,10 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>(
return; return;
} }
// If this intrinsic is the older "simd_shuffleN" form, simply parse the integer.
// If there is no suffix, use the index array length.
let n: u16 = if intrinsic == sym::simd_shuffle {
// Make sure this is actually an array, since typeck only checks the length-suffixed // Make sure this is actually an array, since typeck only checks the length-suffixed
// version of this intrinsic. // version of this intrinsic.
let idx_ty = fx.monomorphize(idx.ty(fx.mir, fx.tcx)); let idx_ty = fx.monomorphize(idx.ty(fx.mir, fx.tcx));
match idx_ty.kind() { let n: u16 = match idx_ty.kind() {
ty::Array(ty, len) if matches!(ty.kind(), ty::Uint(ty::UintTy::U32)) => len ty::Array(ty, len) if matches!(ty.kind(), ty::Uint(ty::UintTy::U32)) => len
.try_eval_target_usize(fx.tcx, ty::ParamEnv::reveal_all()) .try_eval_target_usize(fx.tcx, ty::ParamEnv::reveal_all())
.unwrap_or_else(|| { .unwrap_or_else(|| {
@ -150,19 +147,12 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>(
_ => { _ => {
fx.tcx.sess.span_err( fx.tcx.sess.span_err(
span, span,
format!( format!("simd_shuffle index must be an array of `u32`, got `{}`", idx_ty),
"simd_shuffle index must be an array of `u32`, got `{}`",
idx_ty,
),
); );
// Prevent verifier error // Prevent verifier error
fx.bcx.ins().trap(TrapCode::UnreachableCodeReached); fx.bcx.ins().trap(TrapCode::UnreachableCodeReached);
return; return;
} }
}
} else {
// FIXME remove this case
intrinsic.as_str()["simd_shuffle".len()..].parse().unwrap()
}; };
assert_eq!(x.layout(), y.layout()); assert_eq!(x.layout(), y.layout());
@ -179,7 +169,7 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>(
let indexes = { let indexes = {
use rustc_middle::mir::interpret::*; use rustc_middle::mir::interpret::*;
let idx_const = crate::constant::mir_operand_get_const_val(fx, idx) let idx_const = crate::constant::mir_operand_get_const_val(fx, idx)
.expect("simd_shuffle* idx not const"); .expect("simd_shuffle idx not const");
let idx_bytes = match idx_const { let idx_bytes = match idx_const {
ConstValue::ByRef { alloc, offset } => { ConstValue::ByRef { alloc, offset } => {