]> git.ipfire.org Git - thirdparty/gcc.git/commit
openmp: Improve handling of nested OpenMP metadirectives in C and C++
authorKwok Cheung Yeung <kcy@codesourcery.com>
Fri, 18 Feb 2022 19:00:57 +0000 (19:00 +0000)
committerKwok Cheung Yeung <kcy@codesourcery.com>
Fri, 18 Feb 2022 21:17:06 +0000 (21:17 +0000)
commit249df772b70f7b9f50f68030d4ea9c25624cc578
tree90f874cc3e378f21e74101153b9376fa87d26fdf
parent8cb0121af50eacb63098a79ff8c6deae05883c6f
openmp: Improve handling of nested OpenMP metadirectives in C and C++

This patch fixes a misparsing issue when encountering code like:

  #pragma omp metadirective when {<selector_set>={...}: A)
    #pragma omp metadirective when (<selector_set>={...}: B)

When called for the first metadirective, analyze_metadirective_body would
stop just before the colon in the second metadirective because it naively
assumes that the '}' marks the end of a code block.

The assertion for clauses to end parsing at the same point is now disabled
if a parse error has occurred during the parsing of the clause, since some
tokens may not be consumed if a parse error cuts parsing short.

2022-02-18  Kwok Cheung Yeung  <kcy@codesourcery.com>

gcc/c/
* c-parser.c (c_parser_omp_construct): Move handling of
PRAGMA_OMP_METADIRECTIVE from here...
(c_parser_pragma): ...to here.
(analyze_metadirective_body): Check that the bracket nesting level
is also zero before stopping the adding of tokens on encountering a
close brace.
(c_parser_omp_metadirective): Modify function signature and update.
Do not assert on remaining tokens if there has been a parse error.

gcc/cp/
* parser.c (cp_parser_omp_construct): Move handling of
PRAGMA_OMP_METADIRECTIVE from here...
(cp_parser_pragma): ...to here.
(analyze_metadirective_body): Check that the bracket
nesting level is also zero before stopping the adding of tokens on
encountering a close brace.
(cp_parser_omp_metadirective): Modify function signature and update.
Do not assert on remaining tokens if there has been a parse error.

gcc/testsuite/
* c-c++-common/gomp/metadirective-1.c (f): Add test for
improperly nested metadirectives.
gcc/c/ChangeLog.omp
gcc/c/c-parser.c
gcc/cp/ChangeLog.omp
gcc/cp/parser.c
gcc/testsuite/ChangeLog.omp
gcc/testsuite/c-c++-common/gomp/metadirective-1.c