]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: fix ICE for empty enum variant
authorlishin <lishin1008@gmail.com>
Thu, 14 Aug 2025 15:23:50 +0000 (16:23 +0100)
committerArthur Cohen <arthur.cohen@embecosm.com>
Thu, 30 Oct 2025 19:58:39 +0000 (20:58 +0100)
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 <lishin1008@gmail.com>
gcc/rust/rust-gcc.cc
gcc/testsuite/rust/compile/issue-3947.rs [new file with mode: 0644]

index 398dea17d14ccc3623cc4fe2bb3b6bbc6b7baca7..8f950d176f2958f01ffc1f9e24b4406fd54f3e6d 100644 (file)
@@ -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 (file)
index 0000000..58ccde6
--- /dev/null
@@ -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()
+}