public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc/devel/rust/master] parser: Move outer attrs properly intoto AssignmentExpr
@ 2022-06-08 12:24 Thomas Schwinge
  0 siblings, 0 replies; only message in thread
From: Thomas Schwinge @ 2022-06-08 12:24 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:6c99a5a8f1a62976ff58d89034642f28128a2033

commit 6c99a5a8f1a62976ff58d89034642f28128a2033
Author: Arthur Cohen <arthur.cohen@embecosm.com>
Date:   Fri Mar 25 09:50:48 2022 +0100

    parser: Move outer attrs properly intoto AssignmentExpr
    
    AssignmentExpressions could not access their outer attributes properly,
    since they were being eagerly moved into the `IdentifierExpr` type they
    are based on. The base `OperatorExpr` class would thus end up with an
    empty vector of outer attributes

Diff:
---
 gcc/rust/ast/rust-expr.h                   |  5 +++--
 gcc/rust/parse/rust-parse-impl.h           | 17 +++++++++--------
 gcc/testsuite/rust/execute/torture/cfg5.rs | 13 +++++++++++++
 3 files changed, 25 insertions(+), 10 deletions(-)

diff --git a/gcc/rust/ast/rust-expr.h b/gcc/rust/ast/rust-expr.h
index 7336db225d4..1966a590c94 100644
--- a/gcc/rust/ast/rust-expr.h
+++ b/gcc/rust/ast/rust-expr.h
@@ -704,8 +704,9 @@ public:
 
   // Call OperatorExpr constructor to initialise left_expr
   AssignmentExpr (std::unique_ptr<Expr> value_to_assign_to,
-		  std::unique_ptr<Expr> value_to_assign, Location locus)
-    : OperatorExpr (std::move (value_to_assign_to), std::vector<Attribute> (),
+		  std::unique_ptr<Expr> value_to_assign,
+		  std::vector<Attribute> outer_attribs, Location locus)
+    : OperatorExpr (std::move (value_to_assign_to), std::move (outer_attribs),
 		    locus),
       right_expr (std::move (value_to_assign))
   {}
diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h
index 7e6ab9b0287..189074580aa 100644
--- a/gcc/rust/parse/rust-parse-impl.h
+++ b/gcc/rust/parse/rust-parse-impl.h
@@ -11694,7 +11694,7 @@ Parser<ManagedTokenSource>::parse_stmt_or_expr_without_block ()
 	  {
 	    // should be expr without block
 	    std::unique_ptr<AST::ExprWithoutBlock> expr
-	      = parse_expr_without_block ();
+	      = parse_expr_without_block (std::move (outer_attrs));
 
 	    if (lexer.peek_token ()->get_id () == SEMICOLON)
 	      {
@@ -11739,7 +11739,7 @@ Parser<ManagedTokenSource>::parse_stmt_or_expr_without_block ()
 	  // FIXME: old code was good until composability was required
 	  // return parse_path_based_stmt_or_expr(std::move(outer_attrs));
 	  std::unique_ptr<AST::ExprWithoutBlock> expr
-	    = parse_expr_without_block ();
+	    = parse_expr_without_block (std::move (outer_attrs));
 
 	  if (lexer.peek_token ()->get_id () == SEMICOLON)
 	    {
@@ -11762,7 +11762,7 @@ Parser<ManagedTokenSource>::parse_stmt_or_expr_without_block ()
 	 * expression then make it statement if semi afterwards */
 
 	std::unique_ptr<AST::ExprWithoutBlock> expr
-	  = parse_expr_without_block ();
+	  = parse_expr_without_block (std::move (outer_attrs));
 
 	if (lexer.peek_token ()->get_id () == SEMICOLON)
 	  {
@@ -12437,7 +12437,7 @@ Parser<ManagedTokenSource>::parse_expr (int right_binding_power,
 
   // parse null denotation (unary part of expression)
   std::unique_ptr<AST::Expr> expr
-    = null_denotation (current_token, std::move (outer_attrs), restrictions);
+    = null_denotation (current_token, {}, restrictions);
 
   if (expr == nullptr)
     {
@@ -12452,8 +12452,8 @@ Parser<ManagedTokenSource>::parse_expr (int right_binding_power,
       current_token = lexer.peek_token ();
       lexer.skip_token ();
 
-      expr = left_denotation (current_token, std::move (expr), AST::AttrVec (),
-			      restrictions);
+      expr = left_denotation (current_token, std::move (expr),
+			      std::move (outer_attrs), restrictions);
 
       if (expr == nullptr)
 	{
@@ -13786,7 +13786,7 @@ template <typename ManagedTokenSource>
 std::unique_ptr<AST::AssignmentExpr>
 Parser<ManagedTokenSource>::parse_assig_expr (
   const_TokenPtr tok ATTRIBUTE_UNUSED, std::unique_ptr<AST::Expr> left,
-  AST::AttrVec outer_attrs ATTRIBUTE_UNUSED, ParseRestrictions restrictions)
+  AST::AttrVec outer_attrs, ParseRestrictions restrictions)
 {
   // parse RHS (as tok has already been consumed in parse_expression)
   std::unique_ptr<AST::Expr> right
@@ -13799,7 +13799,8 @@ Parser<ManagedTokenSource>::parse_assig_expr (
   Location locus = left->get_locus ();
 
   return std::unique_ptr<AST::AssignmentExpr> (
-    new AST::AssignmentExpr (std::move (left), std::move (right), locus));
+    new AST::AssignmentExpr (std::move (left), std::move (right),
+			     std::move (outer_attrs), locus));
 }
 
 /* Returns the left binding power for the given CompoundAssignmentExpr type.
diff --git a/gcc/testsuite/rust/execute/torture/cfg5.rs b/gcc/testsuite/rust/execute/torture/cfg5.rs
new file mode 100644
index 00000000000..581a29bb89d
--- /dev/null
+++ b/gcc/testsuite/rust/execute/torture/cfg5.rs
@@ -0,0 +1,13 @@
+// { dg-additional-options "-w -frust-cfg=A" }
+
+fn main() -> i32 {
+    let mut a = 0;
+
+    #[cfg(A)]
+    a = 3;
+
+    #[cfg(B)]
+    a = 40;
+
+    a - 3
+}


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-06-08 12:24 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-08 12:24 [gcc/devel/rust/master] parser: Move outer attrs properly intoto AssignmentExpr Thomas Schwinge

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).