https://gcc.gnu.org/g:3809e8f69696e52f6882a1fa56f2b506c49820c7

commit r16-4788-g3809e8f69696e52f6882a1fa56f2b506c49820c7
Author: lishin <[email protected]>
Date:   Thu Aug 14 16:23:50 2025 +0100

    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]>

Diff:
---
 gcc/rust/rust-gcc.cc                     |  2 +-
 gcc/testsuite/rust/compile/issue-3947.rs | 10 ++++++++++
 2 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/gcc/rust/rust-gcc.cc b/gcc/rust/rust-gcc.cc
index 398dea17d14c..8f950d176f29 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<constructor_elt, va_gc> *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 000000000000..58ccde6a91dc
--- /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()
+}

Reply via email to