]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
openmp: Metadirective fixes
authorKwok Cheung Yeung <kcy@codesourcery.com>
Tue, 25 Jan 2022 19:40:58 +0000 (11:40 -0800)
committerKwok Cheung Yeung <kcy@codesourcery.com>
Tue, 28 Jun 2022 20:55:18 +0000 (13:55 -0700)
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.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/ChangeLog.omp
gcc/c/ChangeLog.omp
gcc/c/c-parser.cc
gcc/cp/ChangeLog.omp
gcc/cp/parser.cc
gcc/omp-general.cc

index 369e8c9e5005c26d6c8876574198638b122092c5..5a7891f02ecd7cf1edb1de0599e639a95c4ed22a 100644 (file)
@@ -1,3 +1,8 @@
+2022-01-25  Kwok Cheung Yeung  <kcy@codesourcery.com>
+
+       * omp-general.cc (omp_dynamic_cond): Do not return user condition if
+       constant.
+
 2022-01-25  Kwok Cheung Yeung  <kcy@codesourcery.com>
 
        * omp-general.cc (omp_check_context_selector): Revert string length
index 39f82752f9ee60e986b0305f293687005557301e..103bf15852700d713f066c3994d0349165814cf4 100644 (file)
@@ -1,3 +1,8 @@
+2022-01-25  Kwok Cheung Yeung  <kcy@codesourcery.com>
+
+       * c-parser.cc (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.cc (c_parser_skip_to_end_of_block_or_statement): Handle
index dd7338de51f76914acb9e601eeb5d0bce1a40091..d215ad62103fdf303a5510cda12fe00e3dae12d1 100644 (file)
@@ -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:
index c1ef9a1651ed28fade73572e48e47140b611585b..31b9888474922dbda4bf243235a99f547edcf565 100644 (file)
@@ -1,3 +1,9 @@
+2022-01-25  Kwok Cheung Yeung  <kcy@codesourcery.com>
+
+       * 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.
+
 2022-01-25  Kwok Cheung Yeung  <kcy@codesourcery.com>
 
        * parser.cc (cp_parser_skip_to_end_of_statement): Handle parentheses.
index 57df1e2fa80914708afe04a21ffb04957f237fe0..ee838ea28f494198917056ef0342a2a60b211d69 100644 (file)
@@ -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:
index 19f67f817ae08431e61eef2f3cdcb6579f782e90..1e66cd7bce6a024078c83f9c88e812ee2079125c 100644 (file)
@@ -2007,7 +2007,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)
@@ -2018,8 +2018,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;
 }