[gcc r14-8114] gccrs: Add more checks for expr value in early visitors

Arthur Cohen cohenarthur@gcc.gnu.org
Tue Jan 16 18:14:48 GMT 2024


https://gcc.gnu.org/g:d430d0bac3e447b323c3ff70bdfb83555e5cadd1

commit r14-8114-gd430d0bac3e447b323c3ff70bdfb83555e5cadd1
Author: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Date:   Tue Oct 24 16:01:52 2023 +0200

    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>

Diff:
---
 gcc/rust/expand/rust-cfg-strip.cc            | 15 +++++++++------
 gcc/rust/expand/rust-expand-visitor.cc       |  3 ++-
 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 70df4460f68..9c5b92c4460 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 55d5de0a04e..b0fa004fdc3 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 63d3ccfb74f..b9307c8612f 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


More information about the Gcc-cvs mailing list