diff options
author | Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com> | 2023-10-24 16:01:52 +0200 |
---|---|---|
committer | Arthur Cohen <arthur.cohen@embecosm.com> | 2024-01-16 19:13:10 +0100 |
commit | d430d0bac3e447b323c3ff70bdfb83555e5cadd1 (patch) | |
tree | 74707783b31d2b4313a840648a64adb31d2fd561 | |
parent | 55bfecc95a577c58edd93061852e40b93b47d19c (diff) | |
download | gcc-d430d0bac3e447b323c3ff70bdfb83555e5cadd1.zip gcc-d430d0bac3e447b323c3ff70bdfb83555e5cadd1.tar.gz gcc-d430d0bac3e447b323c3ff70bdfb83555e5cadd1.tar.bz2 |
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 <pierre-emmanuel.patry@embecosm.com>
-rw-r--r-- | gcc/rust/expand/rust-cfg-strip.cc | 15 | ||||
-rw-r--r-- | gcc/rust/expand/rust-expand-visitor.cc | 3 | ||||
-rw-r--r-- | gcc/rust/resolve/rust-early-name-resolver.cc | 3 |
3 files changed, 13 insertions, 8 deletions
diff --git a/gcc/rust/expand/rust-cfg-strip.cc b/gcc/rust/expand/rust-cfg-strip.cc index 70df446..9c5b92c 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 55d5de0..b0fa004 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 63d3ccf..b9307c8 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 |