]> 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, 25 Jan 2022 20:05:03 +0000 (12:05 -0800)
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.

gcc/ChangeLog.omp
gcc/c/ChangeLog.omp
gcc/c/c-parser.c
gcc/cp/ChangeLog.omp
gcc/cp/parser.c
gcc/omp-general.c

index 47b8831e596f5b58558d678491af2a5417820cea..4c02ea1bb89ce8affabf14bad00d88400756445e 100644 (file)
@@ -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
index f691813801feacd96f56beba538fb96511b8092c..90b123fc0e6566af3ca267e2582fbdb848130509 100644 (file)
@@ -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
index 747a4193c77e836418d174fb334851cdb9de4b7d..212c066cad33f434e85c11323fcc6bf35592b045 100644 (file)
@@ -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:
index 5b44f265e8a47d3963ef01f7b85b49e3971fd635..c226f07f9ae12866b84cb53bb084e6a17328d3b4 100644 (file)
@@ -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.
index 50f4ab2c2b670047a8955460d6ad1d25bfd40b90..c0950e0631187f6935d3709c052f5e07444911b2 100644 (file)
@@ -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:
index 6ad03e5b02f6898b10cf2799a907ddc1a82ef675..36e1b1d21c33794743e91eda8233459216b59a88 100644 (file)
@@ -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;
 }