Skip to content

Commit 92706cc

Browse files
Lishin1215philberty
authored andcommitted
gccrs: fix ICE for empty enum variant
gcc/rust/ChangeLog: * rust-gcc.cc (constructor_expression): Ensure vec_alloc reserves at least one element. gcc/testsuite/ChangeLog: * rust/compile/issue-3947.rs: New test. Signed-off-by: lishin <[email protected]>
1 parent e4a7b46 commit 92706cc

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

gcc/rust/rust-gcc.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1258,7 +1258,7 @@ constructor_expression (tree type_tree, bool is_variant,
12581258
return error_mark_node;
12591259

12601260
vec<constructor_elt, va_gc> *init;
1261-
vec_alloc (init, vals.size ());
1261+
vec_alloc (init, union_index != -1 ? 1 : vals.size ());
12621262

12631263
tree sink = NULL_TREE;
12641264
bool is_constant = true;
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
enum _Enum {
2+
A(),
3+
}
4+
5+
type _E = _Enum;
6+
7+
// { dg-warning "function is never used: '_a'" "" { target *-*-* } .+1 }
8+
const fn _a() -> _Enum {
9+
_E::A()
10+
}

0 commit comments

Comments
 (0)