diff options
| author | Stuart Cook <Zalathar@users.noreply.github.com> | 2025-04-02 13:10:36 +1100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-04-02 13:10:36 +1100 |
| commit | bae53a7c3cc5a070e9301da1f3586da01a52bfca (patch) | |
| tree | f715aeec0c1ffb4795521b4330cb9e1971ee2e1e | |
| parent | 9b7d5ac8180f70110e94f92ccbf8fa2263d24c73 (diff) | |
| parent | ff699ce9f55e974e9181a800203fae9d73b90e37 (diff) | |
| download | rust-bae53a7c3cc5a070e9301da1f3586da01a52bfca.tar.gz rust-bae53a7c3cc5a070e9301da1f3586da01a52bfca.zip | |
Rollup merge of #135295 - eyraudh:master, r=compiler-errors
Check empty SIMD vector in inline asm fixes [#134334](https://github.com/rust-lang/rust/issues/134334)
| -rw-r--r-- | compiler/rustc_hir_analysis/src/check/intrinsicck.rs | 8 | ||||
| -rw-r--r-- | tests/crashes/134334.rs | 9 | ||||
| -rw-r--r-- | tests/ui/simd/empty-simd-vector-in-operand.rs | 15 | ||||
| -rw-r--r-- | tests/ui/simd/empty-simd-vector-in-operand.stderr | 15 |
4 files changed, 38 insertions, 9 deletions
diff --git a/compiler/rustc_hir_analysis/src/check/intrinsicck.rs b/compiler/rustc_hir_analysis/src/check/intrinsicck.rs index d63165f0f16..32a582aadc1 100644 --- a/compiler/rustc_hir_analysis/src/check/intrinsicck.rs +++ b/compiler/rustc_hir_analysis/src/check/intrinsicck.rs @@ -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; } diff --git a/tests/crashes/134334.rs b/tests/crashes/134334.rs deleted file mode 100644 index d99df7bdc1e..00000000000 --- a/tests/crashes/134334.rs +++ /dev/null @@ -1,9 +0,0 @@ -//@ known-bug: #134334 -//@ only-x86_64 - -#[repr(simd)] -struct A(); - -fn main() { - std::arch::asm!("{}", in(xmm_reg) A()); -} diff --git a/tests/ui/simd/empty-simd-vector-in-operand.rs b/tests/ui/simd/empty-simd-vector-in-operand.rs new file mode 100644 index 00000000000..2a2a6c0737d --- /dev/null +++ b/tests/ui/simd/empty-simd-vector-in-operand.rs @@ -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` + } +} diff --git a/tests/ui/simd/empty-simd-vector-in-operand.stderr b/tests/ui/simd/empty-simd-vector-in-operand.stderr new file mode 100644 index 00000000000..7210dddd461 --- /dev/null +++ b/tests/ui/simd/empty-simd-vector-in-operand.stderr @@ -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`. |
