aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorPhilip Herron <herron.philip@googlemail.com>2025-03-26 17:11:36 +0000
committerArthur Cohen <arthur.cohen@embecosm.com>2025-03-31 21:07:16 +0200
commite60632a2797cb40d301a7421011d2d974a3612df (patch)
tree577c18982413b3533942ef41f64dc9cb275653b6 /gcc
parente545727c840b7359fa27543c598cfa6e4a32e0ff (diff)
downloadgcc-e60632a2797cb40d301a7421011d2d974a3612df.zip
gcc-e60632a2797cb40d301a7421011d2d974a3612df.tar.gz
gcc-e60632a2797cb40d301a7421011d2d974a3612df.tar.bz2
gccrs: Fix ICE when array elements are not a value
We need to check for error_mark_node when doing adjustments from coercion sites otherwise we hit assetions as part of the coercion. That fixes the ICE but the reason for the error_mark_node is because the array element value. Fixes Rust-GCC#3567 gcc/rust/ChangeLog: * backend/rust-compile-expr.cc (CompileExpr::array_value_expr): add value chk for array expr gcc/testsuite/ChangeLog: * rust/compile/issue-3567.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.cc11
-rw-r--r--gcc/testsuite/rust/compile/issue-3567.rs4
2 files changed, 15 insertions, 0 deletions
diff --git a/gcc/rust/backend/rust-compile-expr.cc b/gcc/rust/backend/rust-compile-expr.cc
index 21f4ca1..e4ab9f0 100644
--- a/gcc/rust/backend/rust-compile-expr.cc
+++ b/gcc/rust/backend/rust-compile-expr.cc
@@ -1902,6 +1902,14 @@ CompileExpr::array_value_expr (location_t expr_locus,
for (auto &elem : elems.get_values ())
{
tree translated_expr = CompileExpr::Compile (*elem, ctx);
+ if (translated_expr == error_mark_node)
+ {
+ rich_location r (line_table, expr_locus);
+ r.add_fixit_replace (elem->get_locus (), "not a value");
+ rust_error_at (r, ErrorCode::E0423, "expected value");
+ return error_mark_node;
+ }
+
constructor.push_back (translated_expr);
indexes.push_back (i++);
}
@@ -2003,6 +2011,9 @@ HIRCompileBase::resolve_adjustements (
tree e = expression;
for (auto &adjustment : adjustments)
{
+ if (e == error_mark_node)
+ return error_mark_node;
+
switch (adjustment.get_type ())
{
case Resolver::Adjustment::AdjustmentType::ERROR:
diff --git a/gcc/testsuite/rust/compile/issue-3567.rs b/gcc/testsuite/rust/compile/issue-3567.rs
new file mode 100644
index 0000000..021d9c2
--- /dev/null
+++ b/gcc/testsuite/rust/compile/issue-3567.rs
@@ -0,0 +1,4 @@
+fn main() {
+ let _: &[i8] = &[i8];
+ // { dg-error "expected value .E0423." "" { target *-*-* } .-1 }
+}