From 3809e8f69696e52f6882a1fa56f2b506c49820c7 Mon Sep 17 00:00:00 2001 From: lishin Date: Thu, 14 Aug 2025 16:23:50 +0100 Subject: [PATCH] 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 --- gcc/rust/rust-gcc.cc | 2 +- gcc/testsuite/rust/compile/issue-3947.rs | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/rust/compile/issue-3947.rs 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() +} -- 2.47.3