simd_shuffle: require index argument to be a vector
This commit is contained in:
parent
fe5183e627
commit
15848f3f08
@ -180,34 +180,20 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>(
|
||||
return;
|
||||
}
|
||||
|
||||
// Make sure this is actually an array, since typeck only checks the length-suffixed
|
||||
// version of this intrinsic.
|
||||
// Make sure this is actually a SIMD vector.
|
||||
let idx_ty = fx.monomorphize(idx.node.ty(fx.mir, fx.tcx));
|
||||
let n: u16 = match idx_ty.kind() {
|
||||
ty::Array(ty, len) if matches!(ty.kind(), ty::Uint(ty::UintTy::U32)) => len
|
||||
.try_eval_target_usize(fx.tcx, ty::ParamEnv::reveal_all())
|
||||
.unwrap_or_else(|| {
|
||||
span_bug!(span, "could not evaluate shuffle index array length")
|
||||
})
|
||||
.try_into()
|
||||
.unwrap(),
|
||||
_ if idx_ty.is_simd()
|
||||
&& matches!(
|
||||
idx_ty.simd_size_and_type(fx.tcx).1.kind(),
|
||||
ty::Uint(ty::UintTy::U32)
|
||||
) =>
|
||||
{
|
||||
idx_ty.simd_size_and_type(fx.tcx).0.try_into().unwrap()
|
||||
}
|
||||
_ => {
|
||||
fx.tcx.dcx().span_err(
|
||||
span,
|
||||
format!("simd_shuffle index must be an array of `u32`, got `{}`", idx_ty),
|
||||
);
|
||||
// Prevent verifier error
|
||||
fx.bcx.ins().trap(TrapCode::UnreachableCodeReached);
|
||||
return;
|
||||
}
|
||||
let n: u16 = if idx_ty.is_simd()
|
||||
&& matches!(idx_ty.simd_size_and_type(fx.tcx).1.kind(), ty::Uint(ty::UintTy::U32))
|
||||
{
|
||||
idx_ty.simd_size_and_type(fx.tcx).0.try_into().unwrap()
|
||||
} else {
|
||||
fx.tcx.dcx().span_err(
|
||||
span,
|
||||
format!("simd_shuffle index must be a SIMD vector of `u32`, got `{}`", idx_ty),
|
||||
);
|
||||
// Prevent verifier error
|
||||
fx.bcx.ins().trap(TrapCode::UnreachableCodeReached);
|
||||
return;
|
||||
};
|
||||
|
||||
assert_eq!(x.layout(), y.layout());
|
||||
|
Loading…
Reference in New Issue
Block a user