]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: 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)
committerArthur Cohen <arthur.cohen@embecosm.com>
Tue, 16 Jan 2024 18:13:10 +0000 (19:13 +0100)
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 70df4460f68982be45d7ab298add01de87f7d18a..9c5b92c4460c5cbae9ed03379150564aa2177c5f 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 63d3ccfb74ffd6e63a1184ed98197c30414214ef..b9307c8612f26046f7f9d72ebf2853b592b4f046 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