From: Pierre-Emmanuel Patry Date: Tue, 24 Oct 2023 14:01:52 +0000 (+0200) Subject: gccrs: Add more checks for expr value in early visitors X-Git-Tag: basepoints/gcc-15~2025 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=d430d0bac3e447b323c3ff70bdfb83555e5cadd1;p=thirdparty%2Fgcc.git gccrs: Add more checks for expr value in early visitors Early passes visitors may encounter constant item without a value, this is expected as the pass rejecting a constant without an expression is done later during the ast validation. gcc/rust/ChangeLog: * expand/rust-cfg-strip.cc (CfgStrip::visit): Add expr value check. * expand/rust-expand-visitor.cc (ExpandVisitor::visit): Likewise. * resolve/rust-early-name-resolver.cc (EarlyNameResolver::visit): Likewise. Signed-off-by: Pierre-Emmanuel Patry --- diff --git a/gcc/rust/expand/rust-cfg-strip.cc b/gcc/rust/expand/rust-cfg-strip.cc index 70df4460f689..9c5b92c4460c 100644 --- a/gcc/rust/expand/rust-cfg-strip.cc +++ b/gcc/rust/expand/rust-cfg-strip.cc @@ -2293,12 +2293,15 @@ CfgStrip::visit (AST::ConstantItem &const_item) /* strip any internal sub-expressions - expression itself isn't * allowed to have external attributes in this position so can't be * stripped. */ - auto &expr = const_item.get_expr (); - expr->accept_vis (*this); - if (expr->is_marked_for_strip ()) - rust_error_at (expr->get_locus (), - "cannot strip expression in this position - outer " - "attributes not allowed"); + if (const_item.has_expr ()) + { + auto &expr = const_item.get_expr (); + expr->accept_vis (*this); + if (expr->is_marked_for_strip ()) + rust_error_at (expr->get_locus (), + "cannot strip expression in this position - outer " + "attributes not allowed"); + } } void CfgStrip::visit (AST::StaticItem &static_item) diff --git a/gcc/rust/expand/rust-expand-visitor.cc b/gcc/rust/expand/rust-expand-visitor.cc index 55d5de0a04ec..b0fa004fdc34 100644 --- a/gcc/rust/expand/rust-expand-visitor.cc +++ b/gcc/rust/expand/rust-expand-visitor.cc @@ -1127,7 +1127,8 @@ ExpandVisitor::visit (AST::ConstantItem &const_item) { maybe_expand_type (const_item.get_type ()); - maybe_expand_expr (const_item.get_expr ()); + if (const_item.has_expr ()) + maybe_expand_expr (const_item.get_expr ()); } void diff --git a/gcc/rust/resolve/rust-early-name-resolver.cc b/gcc/rust/resolve/rust-early-name-resolver.cc index 63d3ccfb74ff..b9307c8612f2 100644 --- a/gcc/rust/resolve/rust-early-name-resolver.cc +++ b/gcc/rust/resolve/rust-early-name-resolver.cc @@ -752,7 +752,8 @@ void EarlyNameResolver::visit (AST::ConstantItem &const_item) { const_item.get_type ()->accept_vis (*this); - const_item.get_expr ()->accept_vis (*this); + if (const_item.has_expr ()) + const_item.get_expr ()->accept_vis (*this); } void