Skip to content

Commit 6948343

Browse files
committed
fix: Check empty SIMD vector in inline asm
1 parent aa8f0fd commit 6948343

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
@@ -29,6 +29,7 @@ enum NonAsmTypeReason<'tcx> {
2929
Invalid(Ty<'tcx>),
3030
InvalidElement(DefId, Ty<'tcx>),
3131
NotSizedPtr(Ty<'tcx>),
32+
EmptySIMDArray(Ty<'tcx>),
3233
}
3334

3435
impl<'a, 'tcx> InlineAsmCtxt<'a, 'tcx> {
@@ -102,6 +103,9 @@ impl<'a, 'tcx> InlineAsmCtxt<'a, 'tcx> {
102103
}
103104
ty::Adt(adt, args) if adt.repr().simd() => {
104105
let fields = &adt.non_enum_variant().fields;
106+
if fields.is_empty() {
107+
return Err(NonAsmTypeReason::EmptySIMDArray(ty));
108+
}
105109
let field = &fields[FieldIdx::ZERO];
106110
let elem_ty = field.ty(self.tcx(), args);
107111

@@ -226,6 +230,10 @@ impl<'a, 'tcx> InlineAsmCtxt<'a, 'tcx> {
226230
can be used as arguments for inline assembly",
227231
).emit();
228232
}
233+
NonAsmTypeReason::EmptySIMDArray(ty) => {
234+
let msg = format!("use of empty SIMD vector `{ty}`");
235+
self.infcx.dcx().struct_span_err(expr.span, msg).emit();
236+
}
229237
}
230238
return None;
231239
}

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)