Skip to content

Commit 2c4f26b

Browse files
Auto merge of #148638 - chenyukang:yukang-fix-148634-repr-simd-enum-ice, r=<try>
Fix ICE for repr simd on non struct try-job: test-various
2 parents 7a72c54 + 53cfe97 commit 2c4f26b

File tree

3 files changed

+51
-1
lines changed

3 files changed

+51
-1
lines changed

compiler/rustc_hir_typeck/src/inline_asm.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use rustc_middle::bug;
77
use rustc_middle::ty::{self, Article, FloatTy, IntTy, Ty, TyCtxt, TypeVisitableExt, UintTy};
88
use rustc_session::lint;
99
use rustc_span::def_id::LocalDefId;
10-
use rustc_span::{Span, Symbol, sym};
10+
use rustc_span::{ErrorGuaranteed, Span, Symbol, sym};
1111
use rustc_target::asm::{
1212
InlineAsmReg, InlineAsmRegClass, InlineAsmRegOrRegClass, InlineAsmType, ModifierInfo,
1313
};
@@ -27,6 +27,7 @@ enum NonAsmTypeReason<'tcx> {
2727
InvalidElement(DefId, Ty<'tcx>),
2828
NotSizedPtr(Ty<'tcx>),
2929
EmptySIMDArray(Ty<'tcx>),
30+
Tainted(ErrorGuaranteed),
3031
}
3132

3233
impl<'a, 'tcx> InlineAsmCtxt<'a, 'tcx> {
@@ -93,6 +94,14 @@ impl<'a, 'tcx> InlineAsmCtxt<'a, 'tcx> {
9394
}
9495
}
9596
ty::Adt(adt, args) if adt.repr().simd() => {
97+
if !adt.is_struct() {
98+
let guar = self.fcx.dcx().span_delayed_bug(
99+
span,
100+
format!("repr(simd) should only be used on structs, got {}", adt.descr()),
101+
);
102+
return Err(NonAsmTypeReason::Tainted(guar));
103+
}
104+
96105
let fields = &adt.non_enum_variant().fields;
97106
if fields.is_empty() {
98107
return Err(NonAsmTypeReason::EmptySIMDArray(ty));
@@ -234,6 +243,9 @@ impl<'a, 'tcx> InlineAsmCtxt<'a, 'tcx> {
234243
let msg = format!("use of empty SIMD vector `{ty}`");
235244
self.fcx.dcx().struct_span_err(expr.span, msg).emit();
236245
}
246+
NonAsmTypeReason::Tainted(_error_guard) => {
247+
// An error has already been reported.
248+
}
237249
}
238250
return None;
239251
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//@ ignore-x86_64
2+
#![feature(repr_simd)]
3+
4+
use std::arch::asm;
5+
6+
#[repr(simd)]
7+
//~^ ERROR attribute should be applied to a struct
8+
//~| ERROR unsupported representation for zero-variant enum
9+
enum Es {}
10+
11+
fn main() {
12+
unsafe {
13+
let mut x: Es;
14+
asm!("{}", out(reg) x);
15+
}
16+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
error[E0517]: attribute should be applied to a struct
2+
--> $DIR/invalid-repr-simd-on-enum-148634.rs:6:8
3+
|
4+
LL | #[repr(simd)]
5+
| ^^^^
6+
...
7+
LL | enum Es {}
8+
| ---------- not a struct
9+
10+
error[E0084]: unsupported representation for zero-variant enum
11+
--> $DIR/invalid-repr-simd-on-enum-148634.rs:6:8
12+
|
13+
LL | #[repr(simd)]
14+
| ^^^^
15+
...
16+
LL | enum Es {}
17+
| ------- zero-variant enum
18+
19+
error: aborting due to 2 previous errors
20+
21+
Some errors have detailed explanations: E0084, E0517.
22+
For more information about an error, try `rustc --explain E0084`.

0 commit comments

Comments
 (0)