diff options
author | Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com> | 2023-10-24 16:01:52 +0200 |
---|---|---|
committer | CohenArthur <arthur.cohen@embecosm.com> | 2023-11-06 17:13:22 +0000 |
commit | 2c5d1113e3352992a3e497dc092e14741aaca334 (patch) | |
tree | 0775291121a47b860b117f515a7574c4fbe30cd5 | |
parent | 1f8a1bbff69b3a3e9feea8084291baad0d4a28eb (diff) | |
download | gcc-2c5d1113e3352992a3e497dc092e14741aaca334.zip gcc-2c5d1113e3352992a3e497dc092e14741aaca334.tar.gz gcc-2c5d1113e3352992a3e497dc092e14741aaca334.tar.bz2 |
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 21fb2f5..50c4a1c 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 32522d5..d19c384 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 |