public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Kwok Yeung <kcy@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc/devel/omp/gcc-11] openmp: Metadirective fixes
Date: Tue, 25 Jan 2022 20:36:52 +0000 (GMT)	[thread overview]
Message-ID: <20220125203652.7CA75385DC35@sourceware.org> (raw)

https://gcc.gnu.org/g:b597c0835ede0067d1b009e0d7381515b44d8753

commit b597c0835ede0067d1b009e0d7381515b44d8753
Author: Kwok Cheung Yeung <kcy@codesourcery.com>
Date:   Tue Jan 25 11:40:58 2022 -0800

    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-25  Kwok Cheung Yeung  <kcy@codesourcery.com>
    
            gcc/c/
            * c-parser.c (c_parser_skip_to_end_of_block_or_statement): Track
            bracket depth separately from nesting depth.
    
            gcc/cp/
            * parser.c (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.c (omp_dynamic_cond): Do not return user condition if
            constant.

Diff:
---
 gcc/ChangeLog.omp    |  5 +++++
 gcc/c/ChangeLog.omp  |  5 +++++
 gcc/c/c-parser.c     |  9 ++++++---
 gcc/cp/ChangeLog.omp |  6 ++++++
 gcc/cp/parser.c      | 20 ++++++--------------
 gcc/omp-general.c    |  8 ++++++--
 6 files changed, 34 insertions(+), 19 deletions(-)

diff --git a/gcc/ChangeLog.omp b/gcc/ChangeLog.omp
index 47b8831e596..4c02ea1bb89 100644
--- a/gcc/ChangeLog.omp
+++ b/gcc/ChangeLog.omp
@@ -1,3 +1,8 @@
+2022-01-25  Kwok Cheung Yeung  <kcy@codesourcery.com>
+
+	* omp-general.c (omp_dynamic_cond): Do not return user condition if
+	constant.
+
 2022-01-25  Kwok Cheung Yeung  <kcy@codesourcery.com>
 
 	* omp-general.c (omp_check_context_selector): Revert string length
diff --git a/gcc/c/ChangeLog.omp b/gcc/c/ChangeLog.omp
index f691813801f..90b123fc0e6 100644
--- a/gcc/c/ChangeLog.omp
+++ b/gcc/c/ChangeLog.omp
@@ -1,3 +1,8 @@
+2022-01-25  Kwok Cheung Yeung  <kcy@codesourcery.com>
+
+	* c-parser.c (c_parser_skip_to_end_of_block_or_statement): Track
+	bracket depth separately from nesting depth.
+
 2022-01-25  Kwok Cheung Yeung  <kcy@codesourcery.com>
 
 	* c-parser.c (c_parser_skip_to_end_of_block_or_statement): Handle
diff --git a/gcc/c/c-parser.c b/gcc/c/c-parser.c
index 747a4193c77..212c066cad3 100644
--- a/gcc/c/c-parser.c
+++ b/gcc/c/c-parser.c
@@ -1345,6 +1345,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)
@@ -1367,7 +1368,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);
@@ -1395,11 +1396,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/ChangeLog.omp b/gcc/cp/ChangeLog.omp
index 5b44f265e8a..c226f07f9ae 100644
--- a/gcc/cp/ChangeLog.omp
+++ b/gcc/cp/ChangeLog.omp
@@ -1,3 +1,9 @@
+2022-01-25  Kwok Cheung Yeung  <kcy@codesourcery.com>
+
+	* parser.c (cp_parser_skip_to_end_of_statement): Revert.
+	(cp_parser_skip_to_end_of_block_or_statement): Track bracket depth
+	separately from nesting depth.
+
 2022-01-25  Kwok Cheung Yeung  <kcy@codesourcery.com>
 
 	* parser.c (cp_parser_skip_to_end_of_statement): Handle parentheses.
diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index 50f4ab2c2b6..c0950e06311 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -3897,17 +3897,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
@@ -3957,6 +3946,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)
@@ -3978,7 +3968,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;
 
@@ -4001,11 +3991,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.c b/gcc/omp-general.c
index 6ad03e5b02f..36e1b1d21c3 100644
--- a/gcc/omp-general.c
+++ b/gcc/omp-general.c
@@ -1999,7 +1999,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)
@@ -2010,8 +2010,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;
 }


                 reply	other threads:[~2022-01-25 20:36 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20220125203652.7CA75385DC35@sourceware.org \
    --to=kcy@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /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).