1
Fork 0

fix: Check empty SIMD vector in inline asm

This commit is contained in:
Hadrien Eyraud 2025-01-09 18:39:40 +01:00 committed by eyraudh
parent aa8f0fd716
commit 6948343b9f
4 changed files with 37 additions and 9 deletions

View file

@ -29,6 +29,7 @@ enum NonAsmTypeReason<'tcx> {
Invalid(Ty<'tcx>),
InvalidElement(DefId, Ty<'tcx>),
NotSizedPtr(Ty<'tcx>),
EmptySIMDArray(Ty<'tcx>),
}
impl<'a, 'tcx> InlineAsmCtxt<'a, 'tcx> {
@ -102,6 +103,9 @@ impl<'a, 'tcx> InlineAsmCtxt<'a, 'tcx> {
}
ty::Adt(adt, args) if adt.repr().simd() => {
let fields = &adt.non_enum_variant().fields;
if fields.is_empty() {
return Err(NonAsmTypeReason::EmptySIMDArray(ty));
}
let field = &fields[FieldIdx::ZERO];
let elem_ty = field.ty(self.tcx(), args);
@ -226,6 +230,10 @@ impl<'a, 'tcx> InlineAsmCtxt<'a, 'tcx> {
can be used as arguments for inline assembly",
).emit();
}
NonAsmTypeReason::EmptySIMDArray(ty) => {
let msg = format!("use of empty SIMD vector `{ty}`");
self.infcx.dcx().struct_span_err(expr.span, msg).emit();
}
}
return None;
}