]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: Fix ICE during const eval of const capacity
authorPhilip Herron <herron.philip@googlemail.com>
Thu, 31 Jul 2025 20:46:42 +0000 (21:46 +0100)
committerArthur Cohen <arthur.cohen@embecosm.com>
Tue, 5 Aug 2025 14:37:00 +0000 (16:37 +0200)
We assert that struct expressions during code-gen must be of TyTy::ADTType
but we can simply just check for this and return error_mark_node to make
this safe.

Fixes Rust-GCC#3960

gcc/rust/ChangeLog:

* backend/rust-compile-expr.cc (CompileExpr::visit): check for ADTType instead of assert

gcc/testsuite/ChangeLog:

* rust/compile/issue-3960.rs: New test.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
gcc/rust/backend/rust-compile-expr.cc
gcc/testsuite/rust/compile/issue-3960.rs [new file with mode: 0644]

index 547bb7c27a8eb3557ebaeb455dadf2309e23a70c..8deb55ab77d6efcf06632d94dd52bf2be52bca86 100644 (file)
@@ -490,6 +490,8 @@ CompileExpr::visit (HIR::StructExprStructFields &struct_expr)
       rust_error_at (struct_expr.get_locus (), "unknown type");
       return;
     }
+  if (!tyty->is<TyTy::ADTType> ())
+    return;
 
   // it must be an ADT
   rust_assert (tyty->get_kind () == TyTy::TypeKind::ADT);
diff --git a/gcc/testsuite/rust/compile/issue-3960.rs b/gcc/testsuite/rust/compile/issue-3960.rs
new file mode 100644 (file)
index 0000000..57329f0
--- /dev/null
@@ -0,0 +1,7 @@
+fn main() {
+    struct G {
+        g: (),
+    }
+    let g = [0; G { g: () }];
+    // { dg-error "mismatched types, expected .usize. but got .G. .E0308." "" { target *-*-* } .-1 }
+}