From: lishin Date: Thu, 14 Aug 2025 15:23:50 +0000 (+0100) Subject: gccrs: fix ICE for empty enum variant X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3809e8f69696e52f6882a1fa56f2b506c49820c7;p=thirdparty%2Fgcc.git 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 --- diff --git a/gcc/rust/rust-gcc.cc b/gcc/rust/rust-gcc.cc index 398dea17d14..8f950d176f2 100644 --- a/gcc/rust/rust-gcc.cc +++ b/gcc/rust/rust-gcc.cc @@ -1258,7 +1258,7 @@ constructor_expression (tree type_tree, bool is_variant, return error_mark_node; vec *init; - vec_alloc (init, vals.size ()); + vec_alloc (init, union_index != -1 ? 1 : vals.size ()); tree sink = NULL_TREE; bool is_constant = true; diff --git a/gcc/testsuite/rust/compile/issue-3947.rs b/gcc/testsuite/rust/compile/issue-3947.rs new file mode 100644 index 00000000000..58ccde6a91d --- /dev/null +++ b/gcc/testsuite/rust/compile/issue-3947.rs @@ -0,0 +1,10 @@ +enum _Enum { + A(), +} + +type _E = _Enum; + +// { dg-warning "function is never used: '_a'" "" { target *-*-* } .+1 } +const fn _a() -> _Enum { + _E::A() +}