diff mbox series

c++: more dummy non_constant_p arg avoidance

Message ID 20230825174146.3372968-1-ppalka@redhat.com
State New
Headers show
Series c++: more dummy non_constant_p arg avoidance | expand

Commit Message

Patrick Palka Aug. 25, 2023, 5:41 p.m. UTC
Tested on x86_64-pc-linux-gnu, does this look OK for trunk?  This
reduces calls to is_rvalue_constant_expression from
cp_parser_constant_expression by 10% for stdc++.h.

-- >8 --

As a follow-up to Marek's r14-3088-ga263152643bbec, this patch makes
us avoid passing an effectively dummy non_constant_p argument in two
more spots in the parser.

gcc/cp/ChangeLog:

	* parser.cc (cp_parser_parenthesized_expression_list_elt): Pass
	nullptr as non_constant_p to cp_parser_braced_list if our
	non_constant_p is null.
	(cp_parser_initializer_list): Likewise to
	cp_parser_initializer_clause.
---
 gcc/cp/parser.cc | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

Comments

Jason Merrill Aug. 28, 2023, 10:28 p.m. UTC | #1
On 8/25/23 13:41, Patrick Palka wrote:
> Tested on x86_64-pc-linux-gnu, does this look OK for trunk?  This
> reduces calls to is_rvalue_constant_expression from
> cp_parser_constant_expression by 10% for stdc++.h.

OK.

> -- >8 --
> 
> As a follow-up to Marek's r14-3088-ga263152643bbec, this patch makes
> us avoid passing an effectively dummy non_constant_p argument in two
> more spots in the parser.
> 
> gcc/cp/ChangeLog:
> 
> 	* parser.cc (cp_parser_parenthesized_expression_list_elt): Pass
> 	nullptr as non_constant_p to cp_parser_braced_list if our
> 	non_constant_p is null.
> 	(cp_parser_initializer_list): Likewise to
> 	cp_parser_initializer_clause.
> ---
>   gcc/cp/parser.cc | 11 ++++++++---
>   1 file changed, 8 insertions(+), 3 deletions(-)
> 
> diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc
> index 774706ac607..a8cc91059c1 100644
> --- a/gcc/cp/parser.cc
> +++ b/gcc/cp/parser.cc
> @@ -8099,7 +8099,10 @@ cp_parser_parenthesized_expression_list_elt (cp_parser *parser, bool cast_p,
>         /* A braced-init-list.  */
>         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,
> +				    (non_constant_p != nullptr
> +				    ? &expr_non_constant_p
> +				    : nullptr));
>         if (non_constant_p && expr_non_constant_p)
>   	*non_constant_p = true;
>       }
> @@ -25812,9 +25815,11 @@ cp_parser_initializer_list (cp_parser* parser, bool* non_constant_p,
>   
>         /* Parse the initializer.  */
>         initializer = cp_parser_initializer_clause (parser,
> -						  &clause_non_constant_p);
> +						  (non_constant_p != nullptr
> +						   ? &clause_non_constant_p
> +						   : nullptr));
>         /* If any clause is non-constant, so is the entire initializer.  */
> -      if (clause_non_constant_p && non_constant_p)
> +      if (non_constant_p && clause_non_constant_p)
>   	*non_constant_p = true;
>   
>         /* If we have an ellipsis, this is an initializer pack
diff mbox series

Patch

diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc
index 774706ac607..a8cc91059c1 100644
--- a/gcc/cp/parser.cc
+++ b/gcc/cp/parser.cc
@@ -8099,7 +8099,10 @@  cp_parser_parenthesized_expression_list_elt (cp_parser *parser, bool cast_p,
       /* A braced-init-list.  */
       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,
+				    (non_constant_p != nullptr
+				    ? &expr_non_constant_p
+				    : nullptr));
       if (non_constant_p && expr_non_constant_p)
 	*non_constant_p = true;
     }
@@ -25812,9 +25815,11 @@  cp_parser_initializer_list (cp_parser* parser, bool* non_constant_p,
 
       /* Parse the initializer.  */
       initializer = cp_parser_initializer_clause (parser,
-						  &clause_non_constant_p);
+						  (non_constant_p != nullptr
+						   ? &clause_non_constant_p
+						   : nullptr));
       /* If any clause is non-constant, so is the entire initializer.  */
-      if (clause_non_constant_p && non_constant_p)
+      if (non_constant_p && clause_non_constant_p)
 	*non_constant_p = true;
 
       /* If we have an ellipsis, this is an initializer pack