From patchwork Fri Oct 6 12:27:39 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Carlini X-Patchwork-Id: 822387 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-463623-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="mWWIIlXO"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3y7pnX3PpXz9t4b for ; Fri, 6 Oct 2017 23:28:00 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to:cc :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=o5JxXuZ+srbq8CdkhEChsUw5Yzrr2m6BjrvvuzutjRx0c429U9 /fizWOj5VPyNnhDXndEd4MggTuholldHAg4D74/nkonLvxlJjviWbPmMoJZSFSol bFTSiOFa/nXDJJlzBRxpC4jqUO5NSfMcxJ9A4GqdpePD5xRSfTIK7aGWE= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to:cc :from:subject:message-id:date:mime-version:content-type; s= default; bh=Htmji1oqB1K82xERgC7GexdKIOY=; b=mWWIIlXOgNXAbJvVD5wE nPu+dRcaCofMWJzUVmJUgm9e8NQ3V9fsiPJ6J2wdqD1grJQ5XhV4Wk2oBmaudYyY nNLrzkBGU9crSEBCWYLbueMrt7vcw9olRVGMsOCtCv4CCtTe5z/ve6gq7fkiwETF hL8RCnP4M48Sl78hc1N87dQ= Received: (qmail 50602 invoked by alias); 6 Oct 2017 12:27:52 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 50568 invoked by uid 89); 6 Oct 2017 12:27:50 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-10.1 required=5.0 tests=BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, KAM_LAZY_DOMAIN_SECURITY, RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy=interestingly, 22577, pars X-HELO: userp1040.oracle.com Received: from userp1040.oracle.com (HELO userp1040.oracle.com) (156.151.31.81) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 06 Oct 2017 12:27:48 +0000 Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by userp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id v96CRicE008852 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 6 Oct 2017 12:27:44 GMT Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by userv0021.oracle.com (8.14.4/8.14.4) with ESMTP id v96CRiB9011106 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 6 Oct 2017 12:27:44 GMT Received: from abhmp0006.oracle.com (abhmp0006.oracle.com [141.146.116.12]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id v96CRhxS017486; Fri, 6 Oct 2017 12:27:43 GMT Received: from [192.168.1.4] (/87.11.217.181) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 06 Oct 2017 05:27:43 -0700 To: "gcc-patches@gcc.gnu.org" Cc: Nathan Sidwell , Jason Merrill From: Paolo Carlini Subject: [C++ Patch] PR 47791 Message-ID: <20f3adc3-f5bd-91f3-bcda-d2d0ec78bef6@oracle.com> Date: Fri, 6 Oct 2017 14:27:39 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.1.0 MIME-Version: 1.0 X-IsSubscribed: yes 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 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. 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 *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); }