Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit e5b3cb5

Browse files
committedJan 10, 2025
Check empty SIMD vector in inline asm
1 parent 251206c commit e5b3cb5

File tree

4 files changed

+37
-9
lines changed

4 files changed

+37
-9
lines changed
 

‎compiler/rustc_hir_analysis/src/check/intrinsicck.rs

+8
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ enum NonAsmTypeReason<'tcx> {
2626
UnevaluatedSIMDArrayLength(DefId, ty::Const<'tcx>),
2727
Invalid(Ty<'tcx>),
2828
InvalidElement(DefId, Ty<'tcx>),
29+
EmptySIMDArray(Ty<'tcx>),
2930
}
3031

3132
impl<'a, 'tcx> InlineAsmCtxt<'a, 'tcx> {
@@ -86,6 +87,9 @@ impl<'a, 'tcx> InlineAsmCtxt<'a, 'tcx> {
8687
ty::RawPtr(ty, _) if self.is_thin_ptr_ty(ty) => Ok(asm_ty_isize),
8788
ty::Adt(adt, args) if adt.repr().simd() => {
8889
let fields = &adt.non_enum_variant().fields;
90+
if fields.is_empty() {
91+
return Err(NonAsmTypeReason::EmptySIMDArray(ty));
92+
}
8993
let field = &fields[FieldIdx::ZERO];
9094
let elem_ty = field.ty(self.tcx, args);
9195

@@ -201,6 +205,10 @@ impl<'a, 'tcx> InlineAsmCtxt<'a, 'tcx> {
201205
can be used as arguments for inline assembly",
202206
).emit();
203207
}
208+
NonAsmTypeReason::EmptySIMDArray(ty) => {
209+
let msg = format!("use of empty SIMD vector `{ty}`");
210+
self.tcx.dcx().struct_span_err(expr.span, msg).emit();
211+
}
204212
}
205213
return None;
206214
}

‎tests/crashes/134334.rs

-9
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Regression test for issue #134224.
2+
3+
#![feature(repr_simd)]
4+
5+
#[repr(simd)]
6+
struct A();
7+
//~^ ERROR SIMD vector cannot be empty
8+
9+
fn main() {
10+
unsafe {
11+
std::arch::asm!("{}", in(xmm_reg) A());
12+
//~^ use of empty SIMD vector `A`
13+
}
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
error[E0075]: SIMD vector cannot be empty
2+
--> $DIR/empty-simd-vector-in-operand.rs:6:1
3+
|
4+
LL | struct A();
5+
| ^^^^^^^^
6+
7+
error: use of empty SIMD vector `A`
8+
--> $DIR/empty-simd-vector-in-operand.rs:11:43
9+
|
10+
LL | std::arch::asm!("{}", in(xmm_reg) A());
11+
| ^^^
12+
13+
error: aborting due to 2 previous errors
14+
15+
For more information about this error, try `rustc --explain E0075`.

0 commit comments

Comments
 (0)
Failed to load comments.