]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Add more checks for expr value in early visitors
authorPierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Tue, 24 Oct 2023 14:01:52 +0000 (16:01 +0200)
committerCohenArthur <arthur.cohen@embecosm.com>
Mon, 6 Nov 2023 17:13:22 +0000 (17:13 +0000)
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>
gcc/rust/expand/rust-cfg-strip.cc
gcc/rust/expand/rust-expand-visitor.cc
gcc/rust/resolve/rust-early-name-resolver.cc

index 21fb2f539518f4daa7e8066b46bf7b40489d1df8..50c4a1c07239b0092baf1ca6970c85c015ceedca 100644 (file)
@@ -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)
index 55d5de0a04ecfee472bceec93d8638c4c6b2e859..b0fa004fdc34d98eafc12cfc1ad1e1ac5e6c51e4 100644 (file)
@@ -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
index 32522d52cac04775ee4c09a2df1582fa913f4b8e..d19c384afd3c32b21e3770fc14f8889625f19730 100644 (file)
@@ -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