Skip to content

Commit 3cce05f

Browse files
committed
consts: remove dead runtime-array const bitcast fallback
The generic unsized constant reader already handles `RuntimeArray` constants, including the trailing-bytes error case covered by the new compile-fail test. Keep `const_bitcast` on the direct `try_read_from_const_alloc` path instead of carrying a second fallback that no longer changes behavior.
1 parent e0d2e20 commit 3cce05f

File tree

1 file changed

+7
-41
lines changed

1 file changed

+7
-41
lines changed

crates/rustc_codegen_spirv/src/codegen_cx/constant.rs

Lines changed: 7 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -346,48 +346,14 @@ impl<'tcx> CodegenCx<'tcx> {
346346
&& let Some(SpirvConst::ConstDataFromAlloc(alloc)) =
347347
self.builder.lookup_const_by_id(pointee)
348348
&& let SpirvType::Pointer { pointee } = self.lookup_type(ty)
349+
&& let Some(init) = self.try_read_from_const_alloc(alloc, pointee)
349350
{
350-
let mut runtime_array_bitcast_error = None;
351-
let init = self.try_read_from_const_alloc(alloc, pointee).or_else(|| {
352-
match self.lookup_type(pointee) {
353-
// Reify unsized constants through a sized backing array,
354-
// then keep the requested pointer type in `SpirvConst::PtrTo`.
355-
SpirvType::RuntimeArray { element } => {
356-
let elem_size = self.lookup_type(element).sizeof(self)?;
357-
if elem_size.bytes() == 0 {
358-
return None;
359-
}
360-
361-
let alloc_size = alloc.inner().size();
362-
if alloc_size.bytes() % elem_size.bytes() != 0 {
363-
runtime_array_bitcast_error = Some(
364-
"const runtime array backing allocation size is not a multiple of the element size",
365-
);
366-
return None;
367-
}
368-
369-
let count = alloc_size.bytes() / elem_size.bytes();
370-
let sized_ty = self.type_array(element, count);
371-
self.try_read_from_const_alloc(alloc, sized_ty)
372-
}
373-
_ => None,
374-
}
375-
});
376-
377-
if let Some(init) = init {
378-
return self.def_constant(
379-
ty,
380-
SpirvConst::PtrTo {
381-
pointee: init.def_cx(self),
382-
},
383-
);
384-
}
385-
386-
if let Some(reason) = runtime_array_bitcast_error {
387-
let result = val.def_cx(self).with_type(ty);
388-
self.zombie_no_span(result.def_cx(self), reason);
389-
return result;
390-
}
351+
return self.def_constant(
352+
ty,
353+
SpirvConst::PtrTo {
354+
pointee: init.def_cx(self),
355+
},
356+
);
391357
}
392358

393359
if val.ty == ty {

0 commit comments

Comments
 (0)