Skip to content

Commit 23097f8

Browse files
committed
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 #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 <[email protected]>
1 parent b322656 commit 23097f8

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

gcc/rust/backend/rust-compile-expr.cc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1902,6 +1902,14 @@ CompileExpr::array_value_expr (location_t expr_locus,
19021902
for (auto &elem : elems.get_values ())
19031903
{
19041904
tree translated_expr = CompileExpr::Compile (*elem, ctx);
1905+
if (translated_expr == error_mark_node)
1906+
{
1907+
rich_location r (line_table, expr_locus);
1908+
r.add_fixit_replace (elem->get_locus (), "not a value");
1909+
rust_error_at (r, ErrorCode::E0423, "expected value");
1910+
return error_mark_node;
1911+
}
1912+
19051913
constructor.push_back (translated_expr);
19061914
indexes.push_back (i++);
19071915
}
@@ -2003,6 +2011,9 @@ HIRCompileBase::resolve_adjustements (
20032011
tree e = expression;
20042012
for (auto &adjustment : adjustments)
20052013
{
2014+
if (e == error_mark_node)
2015+
return error_mark_node;
2016+
20062017
switch (adjustment.get_type ())
20072018
{
20082019
case Resolver::Adjustment::AdjustmentType::ERROR:
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
fn main() {
2+
let _: &[i8] = &[i8];
3+
// { dg-error "expected value .E0423." "" { target *-*-* } .-1 }
4+
}

0 commit comments

Comments
 (0)