aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorPhilip Herron <herron.philip@googlemail.com>2025-07-31 21:46:42 +0100
committerArthur Cohen <arthur.cohen@embecosm.com>2025-08-05 16:37:00 +0200
commit948e4a63455c090afd491c7b669896d47ae08559 (patch)
treea86fce84935c26b2479fbd1b89616beb7198f5d0 /gcc
parent2dcfb123df07301593581e01b4adcdf6b8197f60 (diff)
downloadgcc-948e4a63455c090afd491c7b669896d47ae08559.zip
gcc-948e4a63455c090afd491c7b669896d47ae08559.tar.gz
gcc-948e4a63455c090afd491c7b669896d47ae08559.tar.bz2
gccrs: Fix ICE during const eval of const capacity
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>
Diffstat (limited to 'gcc')
-rw-r--r--gcc/rust/backend/rust-compile-expr.cc2
-rw-r--r--gcc/testsuite/rust/compile/issue-3960.rs7
2 files changed, 9 insertions, 0 deletions
diff --git a/gcc/rust/backend/rust-compile-expr.cc b/gcc/rust/backend/rust-compile-expr.cc
index 547bb7c..8deb55a 100644
--- a/gcc/rust/backend/rust-compile-expr.cc
+++ b/gcc/rust/backend/rust-compile-expr.cc
@@ -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
index 0000000..57329f0
--- /dev/null
+++ b/gcc/testsuite/rust/compile/issue-3960.rs
@@ -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 }
+}