Skip to content

Commit e7a1186

Browse files
committed
Fix ICE with #[repr(simd)] on enum
1 parent 312b894 commit e7a1186

File tree

3 files changed

+49
-0
lines changed

3 files changed

+49
-0
lines changed

compiler/rustc_middle/src/ty/layout.rs

+9
Original file line numberDiff line numberDiff line change
@@ -672,6 +672,15 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
672672

673673
// SIMD vector types.
674674
ty::Adt(def, substs) if def.repr.simd() => {
675+
if !def.is_struct() {
676+
// Should have yielded E0517 by now.
677+
tcx.sess.delay_span_bug(
678+
DUMMY_SP,
679+
"#[repr(simd)] was applied to an ADT that is not a struct",
680+
);
681+
return Err(LayoutError::Unknown(ty));
682+
}
683+
675684
// Supported SIMD vectors are homogeneous ADTs with at least one field:
676685
//
677686
// * #[repr(simd)] struct S(T, T, T, T);
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Regression test for the ICE described in #83505.
2+
3+
#![crate_type="lib"]
4+
5+
#[repr(simd)]
6+
//~^ ERROR: attribute should be applied to a struct [E0517]
7+
//~| ERROR: unsupported representation for zero-variant enum [E0084]
8+
enum Es {}
9+
static CLs: Es;
10+
//~^ ERROR: free static item without body
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
error: free static item without body
2+
--> $DIR/issue-83505-repr-simd.rs:9:1
3+
|
4+
LL | static CLs: Es;
5+
| ^^^^^^^^^^^^^^-
6+
| |
7+
| help: provide a definition for the static: `= <expr>;`
8+
9+
error[E0517]: attribute should be applied to a struct
10+
--> $DIR/issue-83505-repr-simd.rs:5:8
11+
|
12+
LL | #[repr(simd)]
13+
| ^^^^
14+
...
15+
LL | enum Es {}
16+
| ---------- not a struct
17+
18+
error[E0084]: unsupported representation for zero-variant enum
19+
--> $DIR/issue-83505-repr-simd.rs:5:1
20+
|
21+
LL | #[repr(simd)]
22+
| ^^^^^^^^^^^^^
23+
...
24+
LL | enum Es {}
25+
| ---------- zero-variant enum
26+
27+
error: aborting due to 3 previous errors
28+
29+
Some errors have detailed explanations: E0084, E0517.
30+
For more information about an error, try `rustc --explain E0084`.

0 commit comments

Comments
 (0)