From patchwork Mon Jan 24 21:28:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kwok Cheung Yeung X-Patchwork-Id: 50417 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2404F3857C43 for ; Mon, 24 Jan 2022 21:29:24 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from esa4.mentor.iphmx.com (esa4.mentor.iphmx.com [68.232.137.252]) by sourceware.org (Postfix) with ESMTPS id 8662F3858412 for ; Mon, 24 Jan 2022 21:29:07 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 8662F3858412 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=codesourcery.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=mentor.com IronPort-SDR: WTUn7/Jx2boylgMelOZ7CxVcpp6NOCetoEeoIeSlwzvJU+TIZ/ojQnHSvlAjtELsT9Q6fdJoV6 sJIdelsGPTg9b7ZUiQY6CcylrONzGlNaRiLb6WtJs0F7jrfVokvJZWUyrrlCiRvcNKq0KQrE09 RlCpB2xUrPmb49KHm934x1SqbS54k/vFsNvCfJF9hAAh6fs183Qj68lcJs9naX91Jl10oCYfEw AOPdB5VaasvB+pgGOxvphClpBjKdPTaoanhT9/9ya76hONhmDc0ooBuR6lDu9NlBTkbRWaMiSg VHIYTBiWZEw/Lt8kUtPW8w+I X-IronPort-AV: E=Sophos;i="5.88,313,1635235200"; d="scan'208,223";a="71126678" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa4.mentor.iphmx.com with ESMTP; 24 Jan 2022 13:29:06 -0800 IronPort-SDR: ne8Mp8pprnYtkTaPOGC2ikGUVaIw1D1v8Vv+BEtnHeIOrze248zoU//7RCXDBW2gRVIP1NOElZ cySEPJoIZXvtWfrJalFGt3DapPR+Ks24r4DRI4PNCqDF7BwhaDMWmh/dLFvAFAb6D2BhYAn55J ir0jqAchwXDOUq5UGyKZwhAxjzZU3p9E6D6300AxR/3wbquNrroaqao5TElp/jV1Tdl8mu27Uo UmoLgKUYq/zEusaySH8EUQh2hRvCULoo6RuXM5agsECpH172AIjvKgx7aKoSOWChyCKHzxn5k9 c7M= Message-ID: <1e5b98e6-d8ed-4028-f857-47b23e674082@codesourcery.com> Date: Mon, 24 Jan 2022 21:28:57 +0000 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.5.0 From: Kwok Cheung Yeung Subject: [PATCH] openmp: Metadirective patch fixes References: To: Jakub Jelinek , gcc-patches In-Reply-To: X-Originating-IP: [137.202.0.90] X-ClientProxiedBy: SVR-IES-MBX-08.mgc.mentorg.com (139.181.222.8) To SVR-IES-MBX-04.mgc.mentorg.com (139.181.222.4) X-Spam-Status: No, score=-12.0 required=5.0 tests=BAYES_00, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" Hello This patch fixes a couple of issues with the latest patch series for metadirectives. Firstly, the changes to c_parser_skip_to_end_of_block_or_statement and its C++ equivalent cause a couple of tests (e.g. gcc.dg/attr-malloc.c) to regress. This is because these tests cause the parser to skip code starting from within a pair of brackets - this causes the unsigned nesting_depth to wrap around to UINT_MAX when a ')' is encountered and so semicolons no longer stop the skipping, causing too much code to be skipped and resulting in the test regressions. This is fixed by tracking the bracket nesting level separately from the brace nesting level in a signed int, and to allow skipping to end with negative values. Secondly, user condition selectors containing only compile-time constants should be treated as static rather than dynamic. In practice though it doesn't matter much, as GCC readily eliminates the resulting 'if ()' statements via constant folding. These fixes should be merged into the original metadirective patches. Thanks Kwok From 77f419aef8a608440789b0ebb4a08f11d69f00e2 Mon Sep 17 00:00:00 2001 From: Kwok Cheung Yeung Date: Fri, 21 Jan 2022 18:23:57 +0000 Subject: [PATCH 8/9] openmp: Metadirective fixes Fix regressions introduced by block/statement skipping. If user condition selector is constant, do not return it as a dynamic selector. 2022-01-21 Kwok Cheung Yeung gcc/c/ * c-parser.cc (c_parser_skip_to_end_of_block_or_statement): Track bracket depth separately from nesting depth. gcc/cp/ * parser.cc (cp_parser_skip_to_end_of_statement): Revert. (cp_parser_skip_to_end_of_block_or_statement): Track bracket depth separately from nesting depth. gcc/ * omp-general.cc (omp_dynamic_cond): Do not return user condition if constant. --- gcc/c/c-parser.cc | 9 ++++++--- gcc/cp/parser.cc | 20 ++++++-------------- gcc/omp-general.cc | 8 ++++++-- 3 files changed, 18 insertions(+), 19 deletions(-) diff --git a/gcc/c/c-parser.cc b/gcc/c/c-parser.cc index 47075973bfe..f3afc38eb65 100644 --- a/gcc/c/c-parser.cc +++ b/gcc/c/c-parser.cc @@ -1344,6 +1344,7 @@ static void c_parser_skip_to_end_of_block_or_statement (c_parser *parser) { unsigned nesting_depth = 0; + int bracket_depth = 0; bool save_error = parser->error; while (true) @@ -1366,7 +1367,7 @@ c_parser_skip_to_end_of_block_or_statement (c_parser *parser) case CPP_SEMICOLON: /* If the next token is a ';', we have reached the end of the statement. */ - if (!nesting_depth) + if (!nesting_depth && bracket_depth <= 0) { /* Consume the ';'. */ c_parser_consume_token (parser); @@ -1394,11 +1395,13 @@ c_parser_skip_to_end_of_block_or_statement (c_parser *parser) /* Track parentheses in case the statement is a standalone 'for' statement - we want to skip over the semicolons separating the operands. */ - nesting_depth++; + if (nesting_depth == 0) + ++bracket_depth; break; case CPP_CLOSE_PAREN: - nesting_depth--; + if (nesting_depth == 0) + --bracket_depth; break; case CPP_PRAGMA: diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc index de35f42d7c4..7cfaff9d65b 100644 --- a/gcc/cp/parser.cc +++ b/gcc/cp/parser.cc @@ -3931,17 +3931,6 @@ cp_parser_skip_to_end_of_statement (cp_parser* parser) ++nesting_depth; break; - case CPP_OPEN_PAREN: - /* Track parentheses in case the statement is a standalone 'for' - statement - we want to skip over the semicolons separating the - operands. */ - ++nesting_depth; - break; - - case CPP_CLOSE_PAREN: - --nesting_depth; - break; - case CPP_KEYWORD: if (token->keyword != RID__EXPORT && token->keyword != RID__MODULE @@ -3991,6 +3980,7 @@ static void cp_parser_skip_to_end_of_block_or_statement (cp_parser* parser) { int nesting_depth = 0; + int bracket_depth = 0; /* Unwind generic function template scope if necessary. */ if (parser->fully_implicit_function_template_p) @@ -4012,7 +4002,7 @@ cp_parser_skip_to_end_of_block_or_statement (cp_parser* parser) case CPP_SEMICOLON: /* Stop if this is an unnested ';'. */ - if (!nesting_depth) + if (!nesting_depth && bracket_depth <= 0) nesting_depth = -1; break; @@ -4035,11 +4025,13 @@ cp_parser_skip_to_end_of_block_or_statement (cp_parser* parser) /* Track parentheses in case the statement is a standalone 'for' statement - we want to skip over the semicolons separating the operands. */ - nesting_depth++; + if (nesting_depth == 0) + bracket_depth++; break; case CPP_CLOSE_PAREN: - nesting_depth--; + if (nesting_depth == 0) + bracket_depth--; break; case CPP_KEYWORD: diff --git a/gcc/omp-general.cc b/gcc/omp-general.cc index 9db729e6d59..bab4a932f5d 100644 --- a/gcc/omp-general.cc +++ b/gcc/omp-general.cc @@ -1990,7 +1990,7 @@ omp_get_context_selector (tree ctx, const char *set, const char *sel) } /* Return a tree expression representing the dynamic part of the context - * selector CTX. */ + selector CTX. */ static tree omp_dynamic_cond (tree ctx) @@ -2001,8 +2001,12 @@ omp_dynamic_cond (tree ctx) tree expr_list = TREE_VALUE (user); gcc_assert (TREE_PURPOSE (expr_list) == NULL_TREE); - return TREE_VALUE (expr_list); + + /* The user condition is not dynamic if it is constant. */ + if (!tree_fits_shwi_p (TREE_VALUE (expr_list))) + return TREE_VALUE (expr_list); } + return NULL_TREE; }