diff mbox series

[C++] PR 47791

Message ID 20f3adc3-f5bd-91f3-bcda-d2d0ec78bef6@oracle.com
State New
Headers show
Series [C++] PR 47791 | expand

Commit Message

Paolo Carlini Oct. 6, 2017, 12:27 p.m. UTC
Hi,

this is a very old issue, with no impact on the functionality, which I 
already analyzed a bit a while ago: submitter noticed that 
finish_function & co could be cleaned up a bit wrt the constants passed 
in the flags parameter. When I had again a look today cleaning up the 
code appeared very straightforward:  just change the finish_function 
parameter to bool type and adjust the callers. Interestingly, as a 
consequence, cp_parser_function_definition_after_declarator can be also 
simplified, because ctor_initializer_p was only used for the 
finish_function call. Likewise the helper functions called by 
cp_parser_function_definition_after_declarator itself, which were just 
preparing ctor_initializer_p.

Tested x86_64-linux.

Thanks, Paolo.

////////////////////////
2017-10-06  Paolo Carlini  <paolo.carlini@oracle>

	PR c++/47791
	* decl.c (finish_function): Take a bool intead of an int; adjust.
	* cp-tree.h (finish_function): Adjust declaration.
	* decl2.c (generate_tls_wrapper, finish_objects,
	finish_static_storage_duration_function): Adjust calls.
	* lambda.c (maybe_add_lambda_conv_op, finish_lambda_function):
	Likewise.
	* method.c (synthesize_method): Likewise.
	* optimize.c (maybe_thunk_body, maybe_clone_body): Likewise.
	* pt.c (instantiate_decl): Likewise.
	* parser.c (cp_parser_function_definition_after_declarator,
	cp_parser_late_parsing_for_member, cp_parser_omp_declare_reduction):
	Likewise.
	(cp_parser_ctor_initializer_opt,
	cp_parser_ctor_initializer_opt_and_function_body,
	cp_parser_function_try_block,
	cp_parser_function_definition_after_declarator,
	cp_parser_function_transaction): Return void; adjust declarations.

Comments

Nathan Sidwell Oct. 6, 2017, 1:53 p.m. UTC | #1
On 10/06/2017 08:27 AM, Paolo Carlini wrote:
> Hi,
> 
> this is a very old issue, with no impact on the functionality, which I 
> already analyzed a bit a while ago: submitter noticed that 
> finish_function & co could be cleaned up a bit wrt the constants passed 
> in the flags parameter. When I had again a look today cleaning up the 
> code appeared very straightforward:  just change the finish_function 
> parameter to bool type and adjust the callers. Interestingly, as a 
> consequence, cp_parser_function_definition_after_declarator can be also 
> simplified, because ctor_initializer_p was only used for the 
> finish_function call. Likewise the helper functions called by 
> cp_parser_function_definition_after_declarator itself, which were just 
> preparing ctor_initializer_p.


ok, thanks
diff mbox series

Patch

Index: cp-tree.h
===================================================================
--- cp-tree.h	(revision 253483)
+++ cp-tree.h	(working copy)
@@ -6106,7 +6106,7 @@  extern bool start_function			(cp_decl_specifier_se
 extern tree begin_function_body			(void);
 extern void finish_function_body		(tree);
 extern tree outer_curly_brace_block		(tree);
-extern tree finish_function			(int);
+extern tree finish_function			(bool);
 extern tree grokmethod				(cp_decl_specifier_seq *, const cp_declarator *, tree);
 extern void maybe_register_incomplete_var	(tree);
 extern void maybe_commonize_var			(tree);
Index: decl.c
===================================================================
--- decl.c	(revision 253483)
+++ decl.c	(working copy)
@@ -7824,7 +7824,7 @@  start_cleanup_fn (void)
 static void
 end_cleanup_fn (void)
 {
-  expand_or_defer_fn (finish_function (0));
+  expand_or_defer_fn (finish_function (/*inline_p=*/false));
 
   pop_from_top_level ();
 }
@@ -15456,20 +15456,16 @@  maybe_save_function_definition (tree fun)
 
 /* Finish up a function declaration and compile that function
    all the way to assembler language output.  The free the storage
-   for the function definition.
+   for the function definition. INLINE_P is TRUE if we just
+   finished processing the body of an in-class inline function
+   definition.  (This processing will have taken place after the
+   class definition is complete.)  */
 
-   FLAGS is a bitwise or of the following values:
-     2 - INCLASS_INLINE
-       We just finished processing the body of an in-class inline
-       function definition.  (This processing will have taken place
-       after the class definition is complete.)  */
-
 tree
-finish_function (int flags)
+finish_function (bool inline_p)
 {
   tree fndecl = current_function_decl;
   tree fntype, ctype = NULL_TREE;
-  int inclass_inline = (flags & 2) != 0;
 
   /* When we get some parse errors, we can end up without a
      current_function_decl, so cope.  */
@@ -15729,7 +15725,7 @@  tree
      bindings for the template parameters that we added in
      maybe_begin_member_template_processing when start_function was
      called.  */
-  if (inclass_inline)
+  if (inline_p)
     maybe_end_member_template_processing ();
 
   /* Leave the scope of the class.  */
Index: decl2.c
===================================================================
--- decl2.c	(revision 253483)
+++ decl2.c	(working copy)
@@ -3328,7 +3328,7 @@  generate_tls_wrapper (tree fn)
     TREE_READONLY (fn) = true;
   finish_return_stmt (convert_from_reference (var));
   finish_function_body (body);
-  expand_or_defer_fn (finish_function (0));
+  expand_or_defer_fn (finish_function (/*inline_p=*/false));
 }
 
 /* Start the process of running a particular set of global constructors
@@ -3395,7 +3395,7 @@  finish_objects (int method_type, int initp, tree b
 
   /* Finish up.  */
   finish_compound_stmt (body);
-  fn = finish_function (0);
+  fn = finish_function (/*inline_p=*/false);
 
   if (method_type == 'I')
     {
@@ -3535,7 +3535,7 @@  finish_static_storage_duration_function (tree body
 {
   /* Close out the function.  */
   finish_compound_stmt (body);
-  expand_or_defer_fn (finish_function (0));
+  expand_or_defer_fn (finish_function (/*inline_p=*/false));
 }
 
 /* Return the information about the indicated PRIORITY level.  If no
@@ -4284,7 +4284,7 @@  handle_tls_init (void)
   finish_then_clause (if_stmt);
   finish_if_stmt (if_stmt);
   finish_function_body (body);
-  expand_or_defer_fn (finish_function (0));
+  expand_or_defer_fn (finish_function (/*inline_p=*/false));
 }
 
 /* We're at the end of compilation, so generate any mangling aliases that
@@ -5249,7 +5249,7 @@  vtv_finish_verification_constructor_init_function
   tree fn;
 
   finish_compound_stmt (function_body);
-  fn = finish_function (0);
+  fn = finish_function (/*inline_p=*/false);
   DECL_STATIC_CONSTRUCTOR (fn) = 1;
   decl_init_priority_insert (fn, MAX_RESERVED_INIT_PRIORITY - 1);
 
Index: lambda.c
===================================================================
--- lambda.c	(revision 253483)
+++ lambda.c	(working copy)
@@ -1223,7 +1223,7 @@  maybe_add_lambda_conv_op (tree type)
   finish_compound_stmt (compound_stmt);
   finish_function_body (body);
 
-  fn = finish_function (/*inline*/2);
+  fn = finish_function (/*inline_p=*/true);
   if (!generic_lambda_p)
     expand_or_defer_fn (fn);
 
@@ -1241,7 +1241,7 @@  maybe_add_lambda_conv_op (tree type)
   finish_compound_stmt (compound_stmt);
   finish_function_body (body);
 
-  fn = finish_function (/*inline*/2);
+  fn = finish_function (/*inline_p=*/true);
   if (!generic_lambda_p)
     expand_or_defer_fn (fn);
 
@@ -1362,7 +1362,7 @@  finish_lambda_function (tree body)
   finish_function_body (body);
 
   /* Finish the function and generate code for it if necessary.  */
-  tree fn = finish_function (/*inline*/2);
+  tree fn = finish_function (/*inline_p=*/true);
 
   /* Only expand if the call op is not a template.  */
   if (!DECL_TEMPLATE_INFO (fn))
Index: method.c
===================================================================
--- method.c	(revision 253483)
+++ method.c	(working copy)
@@ -953,7 +953,7 @@  synthesize_method (tree fndecl)
     }
 
   finish_function_body (stmt);
-  expand_or_defer_fn (finish_function (0));
+  expand_or_defer_fn (finish_function (/*inline_p=*/false));
 
   input_location = save_input_location;
 
Index: optimize.c
===================================================================
--- optimize.c	(revision 253483)
+++ optimize.c	(working copy)
@@ -416,7 +416,7 @@  maybe_thunk_body (tree fn, bool force)
 	}
 
       DECL_ABSTRACT_ORIGIN (clone) = NULL;
-      expand_or_defer_fn (finish_function (0));
+      expand_or_defer_fn (finish_function (/*inline_p=*/false));
     }
   return 1;
 }
@@ -657,7 +657,7 @@  maybe_clone_body (tree fn)
       cp_function_chain->can_throw = !TREE_NOTHROW (fn);
 
       /* Now, expand this function into RTL, if appropriate.  */
-      finish_function (0);
+      finish_function (/*inline_p=*/false);
       BLOCK_ABSTRACT_ORIGIN (DECL_INITIAL (clone)) = DECL_INITIAL (fn);
       if (alias)
 	{
Index: parser.c
===================================================================
--- parser.c	(revision 253483)
+++ parser.c	(working copy)
@@ -2257,7 +2257,7 @@  static cp_expr cp_parser_braced_list
 static vec<constructor_elt, va_gc> *cp_parser_initializer_list
   (cp_parser *, bool *);
 
-static bool cp_parser_ctor_initializer_opt_and_function_body
+static void cp_parser_ctor_initializer_opt_and_function_body
   (cp_parser *, bool);
 
 static tree cp_parser_late_parsing_omp_declare_simd
@@ -2310,7 +2310,7 @@  static tree cp_parser_conversion_type_id
   (cp_parser *);
 static cp_declarator *cp_parser_conversion_declarator_opt
   (cp_parser *);
-static bool cp_parser_ctor_initializer_opt
+static void cp_parser_ctor_initializer_opt
   (cp_parser *);
 static void cp_parser_mem_initializer_list
   (cp_parser *);
@@ -2353,7 +2353,7 @@  static void cp_parser_explicit_specialization
 
 static tree cp_parser_try_block
   (cp_parser *);
-static bool cp_parser_function_try_block
+static void cp_parser_function_try_block
   (cp_parser *);
 static void cp_parser_handler_seq
   (cp_parser *);
@@ -2438,7 +2438,7 @@  static tree cp_parser_transaction
   (cp_parser *, cp_token *);
 static tree cp_parser_transaction_expression
   (cp_parser *, enum rid);
-static bool cp_parser_function_transaction
+static void cp_parser_function_transaction
   (cp_parser *, enum rid);
 static tree cp_parser_transaction_cancel
   (cp_parser *);
@@ -14253,11 +14253,9 @@  cp_parser_conversion_declarator_opt (cp_parser* pa
 /* Parse an (optional) ctor-initializer.
 
    ctor-initializer:
-     : mem-initializer-list
+     : mem-initializer-list  */
 
-   Returns TRUE iff the ctor-initializer was actually present.  */
-
-static bool
+static void
 cp_parser_ctor_initializer_opt (cp_parser* parser)
 {
   /* If the next token is not a `:', then there is no
@@ -14267,8 +14265,7 @@  cp_parser_ctor_initializer_opt (cp_parser* parser)
       /* Do default initialization of any bases and members.  */
       if (DECL_CONSTRUCTOR_P (current_function_decl))
 	finish_mem_initializers (NULL_TREE);
-
-      return false;
+      return;
     }
 
   /* Consume the `:' token.  */
@@ -14275,8 +14272,6 @@  cp_parser_ctor_initializer_opt (cp_parser* parser)
   cp_lexer_consume_token (parser->lexer);
   /* And the mem-initializer-list.  */
   cp_parser_mem_initializer_list (parser);
-
-  return true;
 }
 
 /* Parse a mem-initializer-list.
@@ -21701,12 +21696,11 @@  cp_parser_function_body (cp_parser *parser, bool i
    true if a ctor-initializer was present.  When IN_FUNCTION_TRY_BLOCK
    is true we are parsing a function-try-block.  */
 
-static bool
+static void
 cp_parser_ctor_initializer_opt_and_function_body (cp_parser *parser,
 						  bool in_function_try_block)
 {
   tree body, list;
-  bool ctor_initializer_p;
   const bool check_body_p =
      DECL_CONSTRUCTOR_P (current_function_decl)
      && DECL_DECLARED_CONSTEXPR_P (current_function_decl);
@@ -21715,7 +21709,7 @@  cp_parser_ctor_initializer_opt_and_function_body (
   /* Begin the function body.  */
   body = begin_function_body ();
   /* Parse the optional ctor-initializer.  */
-  ctor_initializer_p = cp_parser_ctor_initializer_opt (parser);
+  cp_parser_ctor_initializer_opt (parser);
 
   /* If we're parsing a constexpr constructor definition, we need
      to check that the constructor body is indeed empty.  However,
@@ -21735,8 +21729,6 @@  cp_parser_ctor_initializer_opt_and_function_body (
     check_constexpr_ctor_body (last, list, /*complain=*/true);
   /* Finish the function body.  */
   finish_function_body (body);
-
-  return ctor_initializer_p;
 }
 
 /* Parse an initializer.
@@ -24364,20 +24356,19 @@  cp_parser_try_block (cp_parser* parser)
    function-try-block:
      try ctor-initializer [opt] function-body handler-seq  */
 
-static bool
+static void
 cp_parser_function_try_block (cp_parser* parser)
 {
   tree compound_stmt;
   tree try_block;
-  bool ctor_initializer_p;
 
   /* Look for the `try' keyword.  */
   if (!cp_parser_require_keyword (parser, RID_TRY, RT_TRY))
-    return false;
+    return;
   /* Let the rest of the front end know where we are.  */
   try_block = begin_function_try_block (&compound_stmt);
   /* Parse the function-body.  */
-  ctor_initializer_p = cp_parser_ctor_initializer_opt_and_function_body
+  cp_parser_ctor_initializer_opt_and_function_body
     (parser, /*in_function_try_block=*/true);
   /* We're done with the `try' part.  */
   finish_function_try_block (try_block);
@@ -24385,8 +24376,6 @@  cp_parser_function_try_block (cp_parser* parser)
   cp_parser_handler_seq (parser);
   /* We're done with the handlers.  */
   finish_function_handler_sequence (try_block, compound_stmt);
-
-  return ctor_initializer_p;
 }
 
 /* Parse a handler-seq.
@@ -26561,7 +26550,6 @@  cp_parser_function_definition_after_declarator (cp
 						bool inline_p)
 {
   tree fn;
-  bool ctor_initializer_p = false;
   bool saved_in_unbraced_linkage_specification_p;
   bool saved_in_function_body;
   unsigned saved_num_template_parameter_lists;
@@ -26619,21 +26607,18 @@  cp_parser_function_definition_after_declarator (cp
      or function-transaction-block.  Note that all of these include the
      function-body.  */
   if (cp_lexer_next_token_is_keyword (parser->lexer, RID_TRANSACTION_ATOMIC))
-    ctor_initializer_p = cp_parser_function_transaction (parser,
-	RID_TRANSACTION_ATOMIC);
+    cp_parser_function_transaction (parser, RID_TRANSACTION_ATOMIC);
   else if (cp_lexer_next_token_is_keyword (parser->lexer,
       RID_TRANSACTION_RELAXED))
-    ctor_initializer_p = cp_parser_function_transaction (parser,
-	RID_TRANSACTION_RELAXED);
+    cp_parser_function_transaction (parser, RID_TRANSACTION_RELAXED);
   else if (cp_lexer_next_token_is_keyword (parser->lexer, RID_TRY))
-    ctor_initializer_p = cp_parser_function_try_block (parser);
+    cp_parser_function_try_block (parser);
   else
-    ctor_initializer_p = cp_parser_ctor_initializer_opt_and_function_body
+    cp_parser_ctor_initializer_opt_and_function_body
       (parser, /*in_function_try_block=*/false);
 
   /* Finish the function.  */
-  fn = finish_function ((ctor_initializer_p ? 1 : 0) |
-			(inline_p ? 2 : 0));
+  fn = finish_function (inline_p);
   /* Generate code for it, if necessary.  */
   expand_or_defer_fn (fn);
   /* Restore the saved values.  */
@@ -27504,7 +27489,7 @@  cp_parser_late_parsing_for_member (cp_parser* pars
 	{
 	  parser->lexer->in_pragma = true;
 	  cp_parser_omp_declare_reduction_exprs (member_function, parser);
-	  finish_function (/*inline*/2);
+	  finish_function (/*inline_p=*/true);
 	  cp_check_omp_declare_reduction (member_function);
 	}
       else
@@ -37692,7 +37677,7 @@  cp_parser_omp_declare_reduction (cp_parser *parser
       if (!cp_parser_omp_declare_reduction_exprs (fndecl, parser))
 	{
 	  if (!block_scope)
-	    finish_function (0);
+	    finish_function (/*inline_p=*/false);
 	  else
 	    DECL_CONTEXT (fndecl) = current_function_decl;
 	  if (cp)
@@ -37702,7 +37687,7 @@  cp_parser_omp_declare_reduction (cp_parser *parser
       if (cp)
 	cp_parser_pop_lexer (parser);
       if (!block_scope)
-	finish_function (0);
+	finish_function (/*inline_p=*/false);
       else
 	{
 	  DECL_CONTEXT (fndecl) = current_function_decl;
@@ -38397,13 +38382,12 @@  cp_parser_transaction_expression (cp_parser *parse
      __transaction_relaxed function-try-block
 */
 
-static bool
+static void
 cp_parser_function_transaction (cp_parser *parser, enum rid keyword)
 {
   unsigned char old_in = parser->in_transaction;
   unsigned char new_in = 1;
   tree compound_stmt, stmt, attrs;
-  bool ctor_initializer_p;
   cp_token *token;
 
   gcc_assert (keyword == RID_TRANSACTION_ATOMIC
@@ -38427,16 +38411,14 @@  cp_parser_function_transaction (cp_parser *parser,
   parser->in_transaction = new_in;
 
   if (cp_lexer_next_token_is_keyword (parser->lexer, RID_TRY))
-    ctor_initializer_p = cp_parser_function_try_block (parser);
+    cp_parser_function_try_block (parser);
   else
-    ctor_initializer_p = cp_parser_ctor_initializer_opt_and_function_body
+    cp_parser_ctor_initializer_opt_and_function_body
       (parser, /*in_function_try_block=*/false);
 
   parser->in_transaction = old_in;
 
   finish_transaction_stmt (stmt, compound_stmt, new_in, NULL_TREE);
-
-  return ctor_initializer_p;
 }
 
 /* Parse a __transaction_cancel statement.
Index: pt.c
===================================================================
--- pt.c	(revision 253483)
+++ pt.c	(working copy)
@@ -23281,7 +23281,7 @@  instantiate_decl (tree d, bool defer_ok, bool expl
 	DECL_SAVED_TREE (d) = pop_stmt_list (block);
       else
 	{
-	  d = finish_function (0);
+	  d = finish_function (/*inline_p=*/false);
 	  expand_or_defer_fn (d);
 	}