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; } -- 2.25.1