Skip to content

Check empty SIMD vector in inline asm #135295

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions compiler/rustc_hir_analysis/src/check/intrinsicck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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;
}
Expand Down
9 changes: 0 additions & 9 deletions tests/crashes/134334.rs

This file was deleted.

15 changes: 15 additions & 0 deletions tests/ui/simd/empty-simd-vector-in-operand.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Regression test for issue #134224.
//@ only-x86_64

#![feature(repr_simd)]

#[repr(simd)]
struct A();
//~^ ERROR SIMD vector cannot be empty

fn main() {
unsafe {
std::arch::asm!("{}", in(xmm_reg) A());
//~^ use of empty SIMD vector `A`
}
}
15 changes: 15 additions & 0 deletions tests/ui/simd/empty-simd-vector-in-operand.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
error[E0075]: SIMD vector cannot be empty
--> $DIR/empty-simd-vector-in-operand.rs:7:1
|
LL | struct A();
| ^^^^^^^^

error: use of empty SIMD vector `A`
--> $DIR/empty-simd-vector-in-operand.rs:12:43
|
LL | std::arch::asm!("{}", in(xmm_reg) A());
| ^^^

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0075`.
Loading