From: Philip Herron <[email protected]>
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 <[email protected]>
---
gcc/rust/backend/rust-compile-expr.cc | 2 ++
gcc/testsuite/rust/compile/issue-3960.rs | 7 +++++++
2 files changed, 9 insertions(+)
create mode 100644 gcc/testsuite/rust/compile/issue-3960.rs
diff --git a/gcc/rust/backend/rust-compile-expr.cc
b/gcc/rust/backend/rust-compile-expr.cc
index 547bb7c27a8..8deb55ab77d 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 00000000000..57329f0d48a
--- /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 }
+}
--
2.49.0