const-eval: do not call immediate_const_vector on vector of pointers

This commit is contained in:
Folkert de Vries 2026-01-19 15:53:12 +01:00
parent 120388c063
commit 71f34429ac
No known key found for this signature in database
GPG key ID: 1F17F6FFD112B97C
3 changed files with 10 additions and 7 deletions

View file

@ -1074,8 +1074,14 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
if constant_ty.is_simd() {
// However, some SIMD types do not actually use the vector ABI
// (in particular, packed SIMD types do not). Ensure we exclude those.
//
// We also have to exclude vectors of pointers because `immediate_const_vector`
// does not work for those.
let layout = bx.layout_of(constant_ty);
if let BackendRepr::SimdVector { .. } = layout.backend_repr {
let (_, element_ty) = constant_ty.simd_size_and_type(bx.tcx());
if let BackendRepr::SimdVector { .. } = layout.backend_repr
&& element_ty.is_numeric()
{
let (llval, ty) = self.immediate_const_vector(bx, constant);
return OperandRef {
val: OperandValue::Immediate(llval),

View file

@ -1,3 +1,4 @@
//@ compile-flags: -Copt-level=3
#![crate_type = "lib"]
#![no_std]
#![feature(repr_simd, core_intrinsics)]

View file

@ -41,12 +41,8 @@ fn main() {
static ZERO: u8 = 0u8;
let x: Simd<*const u8, 2> = simd_splat(&raw const ZERO);
let y: Simd<*const u8, 2> = const { simd_splat(&raw const ZERO) };
assert_eq!(x.into_array(), [&raw const ZERO; 2]);
// FIXME: this hits "could not evaluate shuffle_indices at compile time",
// emitted in `immediate_const_vector`. const-eval should be able to handle
// this though I think? `const { [&raw const ZERO; 2] }` appears to work.
// let y: Simd<*const u8, 2> = const { simd_splat(&raw const ZERO) };
// assert_eq!(x.into_array(), y.into_array());
assert_eq!(x.into_array(), y.into_array());
}
}