Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk?

-- >8 --

Now that cp_parser_constant_expression accepts a null non_constant_p,
we can transitively remove dummy arguments in the call chain.

Running dg.exp and counting the # of is_rvalue_constant_expression calls
from cp_parser_constant_expression:
pre-r14-2800: 2,459,145
this patch  : 1,719,454

gcc/cp/ChangeLog:

        * parser.cc (cp_parser_postfix_expression): Adjust the call to
        cp_parser_braced_list.
        (cp_parser_postfix_open_square_expression): Likewise.
        (cp_parser_new_initializer): Likewise.
        (cp_parser_assignment_expression): Adjust the call to
        cp_parser_initializer_clause.
        (cp_parser_lambda_introducer): Adjust the call to cp_parser_initializer.
        (cp_parser_range_for): Adjust the call to cp_parser_braced_list.
        (cp_parser_jump_statement): Likewise.
        (cp_parser_mem_initializer): Likewise.
        (cp_parser_template_argument): Likewise.
        (cp_parser_default_argument): Adjust the call to cp_parser_initializer.
        (cp_parser_initializer): Handle null is_direct_init and non_constant_p
        arguments.
        (cp_parser_initializer_clause): Handle null non_constant_p argument.
        (cp_parser_braced_list): Likewise.
        (cp_parser_initializer_list): Likewise.
        (cp_parser_member_declaration): Adjust the call to
        cp_parser_initializer_clause and cp_parser_initializer.
        (cp_parser_yield_expression): Adjust the call to cp_parser_braced_list.
        (cp_parser_functional_cast): Likewise.
        (cp_parser_late_parse_one_default_arg): Adjust the call to
        cp_parser_initializer.
        (cp_parser_omp_for_loop_init): Likewise.
        (cp_parser_omp_declare_reduction_exprs): Likewise.
---
 gcc/cp/parser.cc | 102 +++++++++++++++++++----------------------------
 1 file changed, 41 insertions(+), 61 deletions(-)

diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc
index b1d2e141e35..957eb705b2a 100644
--- a/gcc/cp/parser.cc
+++ b/gcc/cp/parser.cc
@@ -2483,11 +2483,11 @@ static tree cp_parser_default_argument
 static void cp_parser_function_body
   (cp_parser *, bool);
 static tree cp_parser_initializer
-  (cp_parser *, bool *, bool *, bool = false);
+  (cp_parser *, bool * = nullptr, bool * = nullptr, bool = false);
 static cp_expr cp_parser_initializer_clause
-  (cp_parser *, bool *);
+  (cp_parser *, bool * = nullptr);
 static cp_expr cp_parser_braced_list
-  (cp_parser*, bool*);
+  (cp_parser*, bool * = nullptr);
 static vec<constructor_elt, va_gc> *cp_parser_initializer_list
   (cp_parser *, bool *, bool *);
 
@@ -7734,12 +7734,8 @@ cp_parser_postfix_expression (cp_parser *parser, bool 
address_p, bool cast_p,
            /* If things aren't going well, there's no need to
               keep going.  */
            if (!cp_parser_error_occurred (parser))
-             {
-               bool non_constant_p;
-               /* Parse the brace-enclosed initializer list.  */
-               initializer = cp_parser_braced_list (parser,
-                                                    &non_constant_p);
-             }
+             /* Parse the brace-enclosed initializer list.  */
+             initializer = cp_parser_braced_list (parser);
            /* If that worked, we're definitely looking at a
               compound-literal expression.  */
            if (cp_parser_parse_definitely (parser))
@@ -8203,10 +8199,9 @@ cp_parser_postfix_open_square_expression (cp_parser 
*parser,
        }
       else if (cp_lexer_next_token_is (parser->lexer, CPP_OPEN_BRACE))
        {
-         bool expr_nonconst_p;
          cp_lexer_set_source_position (parser->lexer);
          maybe_warn_cpp0x (CPP0X_INITIALIZER_LISTS);
-         index = cp_parser_braced_list (parser, &expr_nonconst_p);
+         index = cp_parser_braced_list (parser);
        }
       else
        index = cp_parser_expression (parser, NULL, /*cast_p=*/false,
@@ -9640,12 +9635,10 @@ cp_parser_new_initializer (cp_parser* parser)
 
   if (cp_lexer_next_token_is (parser->lexer, CPP_OPEN_BRACE))
     {
-      tree t;
-      bool expr_non_constant_p;
       cp_lexer_set_source_position (parser->lexer);
       maybe_warn_cpp0x (CPP0X_INITIALIZER_LISTS);
-      t = cp_parser_braced_list (parser, &expr_non_constant_p);
-      CONSTRUCTOR_IS_DIRECT_INIT (t) = 1;
+      tree t = cp_parser_braced_list (parser);
+      CONSTRUCTOR_IS_DIRECT_INIT (t) = true;
       expression_list = make_tree_vector_single (t);
     }
   else
@@ -10505,11 +10498,8 @@ cp_parser_assignment_expression (cp_parser* parser, 
cp_id_kind * pidk,
            = cp_parser_assignment_operator_opt (parser);
          if (assignment_operator != ERROR_MARK)
            {
-             bool non_constant_p;
-
              /* Parse the right-hand side of the assignment.  */
-             cp_expr rhs = cp_parser_initializer_clause (parser,
-                                                         &non_constant_p);
+             cp_expr rhs = cp_parser_initializer_clause (parser);
 
              if (BRACE_ENCLOSED_INITIALIZER_P (rhs))
                maybe_warn_cpp0x (CPP0X_INITIALIZER_LISTS);
@@ -11413,14 +11403,15 @@ cp_parser_lambda_introducer (cp_parser* parser, tree 
lambda_expr)
          || cp_lexer_next_token_is (parser->lexer, CPP_OPEN_PAREN)
          || cp_lexer_next_token_is (parser->lexer, CPP_OPEN_BRACE))
        {
-         bool direct, non_constant;
          /* An explicit initializer exists.  */
          if (cxx_dialect < cxx14)
            pedwarn (input_location, OPT_Wc__14_extensions,
                     "lambda capture initializers "
                     "only available with %<-std=c++14%> or %<-std=gnu++14%>");
-         capture_init_expr = cp_parser_initializer (parser, &direct,
-                                                    &non_constant, true);
+         capture_init_expr = cp_parser_initializer (parser,
+                                                    /*direct_init=*/nullptr,
+                                                    /*non_constant=*/nullptr,
+                                                    /*subexpression_p=*/true);
          explicit_init_p = true;
          if (capture_init_expr == NULL_TREE)
            {
@@ -13726,10 +13717,7 @@ cp_parser_range_for (cp_parser *parser, tree scope, 
tree init, tree range_decl,
     }
 
   if (cp_lexer_next_token_is (parser->lexer, CPP_OPEN_BRACE))
-    {
-      bool expr_non_constant_p;
-      range_expr = cp_parser_braced_list (parser, &expr_non_constant_p);
-    }
+    range_expr = cp_parser_braced_list (parser);
   else
     range_expr = cp_parser_expression (parser);
 
@@ -14437,13 +14425,12 @@ cp_parser_jump_statement (cp_parser* parser)
     case RID_RETURN:
       {
        tree expr;
-       bool expr_non_constant_p;
 
        if (cp_lexer_next_token_is (parser->lexer, CPP_OPEN_BRACE))
          {
            cp_lexer_set_source_position (parser->lexer);
            maybe_warn_cpp0x (CPP0X_INITIALIZER_LISTS);
-           expr = cp_parser_braced_list (parser, &expr_non_constant_p);
+           expr = cp_parser_braced_list (parser);
          }
        else if (cp_lexer_next_token_is_not (parser->lexer, CPP_SEMICOLON))
          expr = cp_parser_expression (parser);
@@ -17056,10 +17043,9 @@ cp_parser_mem_initializer (cp_parser* parser)
 
   if (cp_lexer_next_token_is (parser->lexer, CPP_OPEN_BRACE))
     {
-      bool expr_non_constant_p;
       cp_lexer_set_source_position (parser->lexer);
       maybe_warn_cpp0x (CPP0X_INITIALIZER_LISTS);
-      expression_list = cp_parser_braced_list (parser, &expr_non_constant_p);
+      expression_list = cp_parser_braced_list (parser);
       CONSTRUCTOR_IS_DIRECT_INIT (expression_list) = 1;
       expression_list = build_tree_list (NULL_TREE, expression_list);
     }
@@ -19197,10 +19183,7 @@ cp_parser_template_argument (cp_parser* parser)
       /* In C++20, we can encounter a braced-init-list.  */
       if (cxx_dialect >= cxx20
          && cp_lexer_next_token_is (parser->lexer, CPP_OPEN_BRACE))
-       {
-         bool expr_non_constant_p;
-         return cp_parser_braced_list (parser, &expr_non_constant_p);
-       }
+       return cp_parser_braced_list (parser);
 
       /* With C++17 generalized non-type template arguments we need to handle
         lvalue constant expressions, too.  */
@@ -25314,7 +25297,6 @@ cp_parser_default_argument (cp_parser *parser, bool 
template_parm_p)
   tree default_argument = NULL_TREE;
   bool saved_greater_than_is_operator_p;
   unsigned char saved_local_variables_forbidden_p;
-  bool non_constant_p, is_direct_init;
 
   /* Make sure that PARSER->GREATER_THAN_IS_OPERATOR_P is
      set correctly.  */
@@ -25341,8 +25323,7 @@ cp_parser_default_argument (cp_parser *parser, bool 
template_parm_p)
       saved_class_ref = current_class_ref;
       cp_function_chain->x_current_class_ref = NULL_TREE;
     }
-  default_argument
-    = cp_parser_initializer (parser, &is_direct_init, &non_constant_p);
+  default_argument = cp_parser_initializer (parser);
   /* Restore the "this" pointer.  */
   if (cfun)
     {
@@ -25441,8 +25422,8 @@ cp_parser_ctor_initializer_opt_and_function_body 
(cp_parser *parser,
    is set to true; otherwise it is set to false.  */
 
 static tree
-cp_parser_initializer (cp_parser* parser, bool* is_direct_init,
-                      bool* non_constant_p, bool subexpression_p)
+cp_parser_initializer (cp_parser *parser, bool *is_direct_init /*=nullptr*/,
+                      bool *non_constant_p /*=nullptr*/, bool subexpression_p)
 {
   cp_token *token;
   tree init;
@@ -25452,9 +25433,11 @@ cp_parser_initializer (cp_parser* parser, bool* 
is_direct_init,
 
   /* Let our caller know whether or not this initializer was
      parenthesized.  */
-  *is_direct_init = (token->type != CPP_EQ);
+  if (is_direct_init)
+    *is_direct_init = (token->type != CPP_EQ);
   /* Assume that the initializer is constant.  */
-  *non_constant_p = false;
+  if (non_constant_p)
+    *non_constant_p = false;
 
   if (token->type == CPP_EQ)
     {
@@ -25514,7 +25497,8 @@ cp_parser_initializer_clause (cp_parser* parser, bool* 
non_constant_p)
   cp_expr initializer;
 
   /* Assume the expression is constant.  */
-  *non_constant_p = false;
+  if (non_constant_p)
+    *non_constant_p = false;
 
   /* If it is not a `{', then we are looking at an
      assignment-expression.  */
@@ -25546,7 +25530,7 @@ cp_parser_initializer_clause (cp_parser* parser, bool* 
non_constant_p)
    cp_parser_initializer.  */
 
 static cp_expr
-cp_parser_braced_list (cp_parser* parser, bool* non_constant_p)
+cp_parser_braced_list (cp_parser *parser, bool *non_constant_p /*=nullptr*/)
 {
   tree initializer;
   location_t start_loc = cp_lexer_peek_token (parser->lexer)->location;
@@ -25568,7 +25552,7 @@ cp_parser_braced_list (cp_parser* parser, bool* 
non_constant_p)
       if (cp_lexer_next_token_is (parser->lexer, CPP_COMMA))
        cp_lexer_consume_token (parser->lexer);
     }
-  else
+  else if (non_constant_p)
     *non_constant_p = false;
   /* Now, there should be a trailing `}'.  */
   location_t finish_loc = cp_lexer_peek_token (parser->lexer)->location;
@@ -25706,7 +25690,8 @@ cp_parser_initializer_list (cp_parser* parser, bool* 
non_constant_p,
   tree first_designator = NULL_TREE;
 
   /* Assume all of the expressions are constant.  */
-  *non_constant_p = false;
+  if (non_constant_p)
+    *non_constant_p = false;
 
   unsigned nelts = 0;
   int suppress = suppress_location_wrappers;
@@ -25814,7 +25799,7 @@ cp_parser_initializer_list (cp_parser* parser, bool* 
non_constant_p,
       initializer = cp_parser_initializer_clause (parser,
                                                  &clause_non_constant_p);
       /* If any clause is non-constant, so is the entire initializer.  */
-      if (clause_non_constant_p)
+      if (clause_non_constant_p && non_constant_p)
        *non_constant_p = true;
 
       /* If we have an ellipsis, this is an initializer pack
@@ -27689,14 +27674,12 @@ cp_parser_member_declaration (cp_parser* parser)
                    initializer = cp_parser_save_nsdmi (parser);
                  else if (cxx_dialect >= cxx11)
                    {
-                     bool nonconst;
                      /* Don't require a constant rvalue in C++11, since we
                         might want a reference constant.  We'll enforce
                         constancy later.  */
                      cp_lexer_consume_token (parser->lexer);
                      /* Parse the initializer.  */
-                     initializer = cp_parser_initializer_clause (parser,
-                                                                 &nonconst);
+                     initializer = cp_parser_initializer_clause (parser);
                    }
                  else
                    /* Parse the initializer.  */
@@ -27705,13 +27688,12 @@ cp_parser_member_declaration (cp_parser* parser)
              else if (cp_lexer_next_token_is (parser->lexer, CPP_OPEN_BRACE)
                       && !function_declarator_p (declarator))
                {
-                 bool x;
                  declarator->init_loc
                    = cp_lexer_peek_token (parser->lexer)->location;
                  if (decl_specifiers.storage_class != sc_static)
                    initializer = cp_parser_save_nsdmi (parser);
                  else
-                   initializer = cp_parser_initializer (parser, &x, &x);
+                   initializer = cp_parser_initializer (parser);
                }
              /* Detect invalid bit-field cases such as
 
@@ -28721,11 +28703,10 @@ cp_parser_yield_expression (cp_parser* parser)
 
   if (cp_lexer_next_token_is (parser->lexer, CPP_OPEN_BRACE))
     {
-      bool expr_non_constant_p;
       cp_lexer_set_source_position (parser->lexer);
       /* ??? : probably a moot point?  */
       maybe_warn_cpp0x (CPP0X_INITIALIZER_LISTS);
-      expr = cp_parser_braced_list (parser, &expr_non_constant_p);
+      expr = cp_parser_braced_list (parser);
     }
   else
     expr = cp_parser_assignment_expression (parser);
@@ -32641,7 +32622,6 @@ cp_parser_functional_cast (cp_parser* parser, tree type)
   vec<tree, va_gc> *vec;
   tree expression_list;
   cp_expr cast;
-  bool nonconst_p;
 
   location_t start_loc = input_location;
 
@@ -32652,7 +32632,7 @@ cp_parser_functional_cast (cp_parser* parser, tree type)
     {
       cp_lexer_set_source_position (parser->lexer);
       maybe_warn_cpp0x (CPP0X_INITIALIZER_LISTS);
-      expression_list = cp_parser_braced_list (parser, &nonconst_p);
+      expression_list = cp_parser_braced_list (parser);
       CONSTRUCTOR_IS_DIRECT_INIT (expression_list) = 1;
       if (TREE_CODE (type) == TYPE_DECL)
        type = TREE_TYPE (type);
@@ -33087,7 +33067,6 @@ cp_parser_late_parse_one_default_arg (cp_parser 
*parser, tree decl,
 {
   cp_token_cache *tokens;
   tree parsed_arg;
-  bool dummy;
 
   if (default_arg == error_mark_node)
     return error_mark_node;
@@ -33100,7 +33079,7 @@ cp_parser_late_parse_one_default_arg (cp_parser 
*parser, tree decl,
   start_lambda_scope (decl);
 
   /* Parse the default argument.  */
-  parsed_arg = cp_parser_initializer (parser, &dummy, &dummy);
+  parsed_arg = cp_parser_initializer (parser);
   if (BRACE_ENCLOSED_INITIALIZER_P (parsed_arg))
     maybe_warn_cpp0x (CPP0X_INITIALIZER_LISTS);
 
@@ -43142,10 +43121,10 @@ cp_parser_omp_for_loop_init (cp_parser *parser,
                   || type_dependent_expression_p (decl)
                   || auto_node)
            {
-             bool is_direct_init, is_non_constant_init;
+             bool is_non_constant_init;
 
              init = cp_parser_initializer (parser,
-                                           &is_direct_init,
+                                           /*is_direct_init=*/nullptr,
                                            &is_non_constant_init);
 
              if (auto_node)
@@ -47739,7 +47718,7 @@ cp_parser_omp_declare_reduction_exprs (tree fndecl, 
cp_parser *parser)
       bool ctor = false;
       if (strcmp (p, "omp_priv") == 0)
        {
-         bool is_direct_init, is_non_constant_init;
+         bool is_non_constant_init;
          ctor = true;
          cp_lexer_consume_token (parser->lexer);
          /* Reject initializer (omp_priv) and initializer (omp_priv ()).  */
@@ -47754,7 +47733,8 @@ cp_parser_omp_declare_reduction_exprs (tree fndecl, 
cp_parser *parser)
              error ("invalid initializer clause");
              return false;
            }
-         initializer = cp_parser_initializer (parser, &is_direct_init,
+         initializer = cp_parser_initializer (parser,
+                                              /*is_direct_init=*/nullptr,
                                               &is_non_constant_init);
          cp_finish_decl (omp_priv, initializer, !is_non_constant_init,
                          NULL_TREE, LOOKUP_ONLYCONVERTING);

base-commit: ffc74822468a39324722eef4c4412ea3224ca976
-- 
2.41.0

Reply via email to