From: Kwok Cheung Yeung <kcy@codesourcery.com>
To: Jakub Jelinek <jakub@redhat.com>, gcc-patches <gcc-patches@gcc.gnu.org>
Subject: [PATCH] openmp: Metadirective patch fixes
Date: Mon, 24 Jan 2022 21:28:57 +0000 [thread overview]
Message-ID: <1e5b98e6-d8ed-4028-f857-47b23e674082@codesourcery.com> (raw)
In-Reply-To: <b73365aa-179d-eecd-e659-b24fd669d33f@codesourcery.com>
[-- Attachment #1: Type: text/plain, Size: 1073 bytes --]
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 (<const>)' statements via constant folding.
These fixes should be merged into the original metadirective patches.
Thanks
Kwok
[-- Attachment #2: 0008-openmp-Metadirective-fixes.patch --]
[-- Type: text/plain, Size: 4511 bytes --]
From 77f419aef8a608440789b0ebb4a08f11d69f00e2 Mon Sep 17 00:00:00 2001
From: Kwok Cheung Yeung <kcy@codesourcery.com>
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 <kcy@codesourcery.com>
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;
}
--
2.25.1
prev parent reply other threads:[~2022-01-24 21:29 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-07-09 11:16 [WIP, OpenMP] OpenMP metadirectives support Kwok Cheung Yeung
2021-07-26 11:38 ` Kwok Cheung Yeung
2021-07-26 14:29 ` Jakub Jelinek
2021-07-26 19:28 ` Kwok Cheung Yeung
2021-07-26 19:56 ` Jakub Jelinek
2021-07-26 21:19 ` Kwok Cheung Yeung
2021-07-26 21:23 ` Jakub Jelinek
2021-07-26 21:27 ` Kwok Cheung Yeung
2022-01-28 16:33 ` [PATCH] openmp: Add warning when functions containing metadirectives with 'construct={target}' called directly Kwok Cheung Yeung
2021-12-10 17:27 ` [WIP, OpenMP] OpenMP metadirectives support Kwok Cheung Yeung
2021-12-10 17:29 ` [PATCH 0/7] openmp: " Kwok Cheung Yeung
2021-12-10 17:31 ` [PATCH 1/7] openmp: Add C support for parsing metadirectives Kwok Cheung Yeung
2022-02-18 21:09 ` [PATCH] openmp: Improve handling of nested OpenMP metadirectives in C and C++ (was: Re: [PATCH 1/7] openmp: Add C support for parsing metadirectives) Kwok Cheung Yeung
2022-02-18 21:26 ` [og11][committed] openmp: Improve handling of nested OpenMP metadirectives in C and C++ Kwok Cheung Yeung
2022-05-27 17:44 ` [PATCH 1/7] openmp: Add C support for parsing metadirectives Jakub Jelinek
2021-12-10 17:33 ` [PATCH 2/7] openmp: Add middle-end support for metadirectives Kwok Cheung Yeung
2022-05-30 10:54 ` Jakub Jelinek
2021-12-10 17:35 ` [PATCH 3/7] openmp: Add support for resolving metadirectives during parsing and Gimplification Kwok Cheung Yeung
2022-05-30 11:13 ` Jakub Jelinek
2021-12-10 17:36 ` [PATCH 4/7] openmp: Add support for streaming metadirectives and resolving them after LTO Kwok Cheung Yeung
2022-05-30 11:33 ` Jakub Jelinek
2021-12-10 17:37 ` [PATCH 5/7] openmp: Add C++ support for parsing metadirectives Kwok Cheung Yeung
2022-05-30 11:52 ` Jakub Jelinek
2021-12-10 17:39 ` [PATCH 6/7] openmp, fortran: Add Fortran " Kwok Cheung Yeung
2022-02-14 15:09 ` Kwok Cheung Yeung
2022-02-14 15:17 ` Kwok Cheung Yeung
2021-12-10 17:40 ` [PATCH 7/7] openmp: Add testcases for metadirectives Kwok Cheung Yeung
2022-05-27 13:42 ` Jakub Jelinek
2022-01-24 21:28 ` Kwok Cheung Yeung [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1e5b98e6-d8ed-4028-f857-47b23e674082@codesourcery.com \
--to=kcy@codesourcery.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=jakub@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).