]> git.ipfire.org Git - thirdparty/gcc.git/commit
OpenMP: Handle non-executable directives in intervening code [PR120180,PR122306]
authorPaul-Antoine Arras <parras@baylibre.com>
Thu, 16 Oct 2025 16:22:08 +0000 (17:22 +0100)
committerPaul-Antoine Arras <parras@baylibre.com>
Tue, 21 Oct 2025 14:14:57 +0000 (16:14 +0200)
commit80af807e52e4f4c480454e5a54aaeb7ce44556fd
tree94760366201a254393e26ead0aa6e6eea148f8d4
parentf4afefbbbee1414e130ca2f1552216bb702a985c
OpenMP: Handle non-executable directives in intervening code [PR120180,PR122306]

OpenMP 6 permits non-executable directives in intervening code; this commit adds
support for a sensible subset, namely metadirectives, nothing, assume, and
'error at(compilation)'.
Also handle the special case where a metadirective can be resolved at parse time
to 'omp nothing'.
This fixes a build issue that affects 10 out 12 SPECaccel benchmarks.

Co-authored by: Tobias Burnus <tburnus@baylibre.com>

PR c/120180
PR fortran/122306

gcc/c/ChangeLog:

* c-parser.cc (c_parser_pragma): Accept a subset of non-executable
OpenMP directives in intervening code.
(c_parser_omp_error): Reject 'error at(execution)' in intervening code.
(c_parser_omp_metadirective): Return early if only one selector matches
and it resolves to 'omp nothing'.

gcc/cp/ChangeLog:

* parser.cc (cp_parser_omp_metadirective): Return early if only one
selector matches and it resolves to 'omp nothing'.
(cp_parser_omp_error): Reject 'error at(execution)' in intervening code.
(cp_parser_pragma): Accept a subset of non-executable OpenMP directives
as intervening code.

gcc/fortran/ChangeLog:

* gfortran.h (enum gfc_exec_op): Add EXEC_OMP_FIRST_OPENMP_EXEC and
EXEC_OMP_LAST_OPENMP_EXEC.
* openmp.cc (gfc_match_omp_context_selector): Remove static. Remove
checks on score. Add cleanup. Remove checks on trait properties.
(gfc_match_omp_context_selector_specification): Remove static. Adjust
calls to gfc_match_omp_context_selector.
(gfc_match_omp_declare_variant): Adjust call to
gfc_match_omp_context_selector_specification.
(match_omp_metadirective): Likewise.
(icode_code_error_callback): Reject all statements except
'assume' and 'metadirective'.
(gfc_resolve_omp_context_selector): New function.
(resolve_omp_metadirective): Skip metadirectives which context selectors
can be statically resolved to false. Replace metadirective by its body
if only 'nothing' remains.
(gfc_resolve_omp_declare): Call gfc_resolve_omp_context_selector for
each variant.

gcc/testsuite/ChangeLog:

* c-c++-common/gomp/imperfect1.c: Adjust dg-error.
* c-c++-common/gomp/imperfect4.c: Likewise.
* c-c++-common/gomp/pr120180.c: Move to...
* c-c++-common/gomp/pr120180-1.c: ...here. Remove dg-error.
* g++.dg/gomp/attrs-imperfect1.C: Adjust dg-error.
* g++.dg/gomp/attrs-imperfect4.C: Likewise.
* gfortran.dg/gomp/declare-variant-2.f90: Adjust dg-error.
* gfortran.dg/gomp/declare-variant-20.f90: Likewise.
* c-c++-common/gomp/pr120180-2.c: New test.
* g++.dg/gomp/pr120180-1.C: New test.
* gfortran.dg/gomp/pr120180-1.f90: New test.
* gfortran.dg/gomp/pr120180-2.f90: New test.
* gfortran.dg/gomp/pr122306-1.f90: New file.
* gfortran.dg/gomp/pr122306-2.f90: New file.
17 files changed:
gcc/c/c-parser.cc
gcc/cp/parser.cc
gcc/fortran/gfortran.h
gcc/fortran/openmp.cc
gcc/testsuite/c-c++-common/gomp/imperfect1.c
gcc/testsuite/c-c++-common/gomp/imperfect4.c
gcc/testsuite/c-c++-common/gomp/pr120180-1.c [moved from gcc/testsuite/c-c++-common/gomp/pr120180.c with 79% similarity]
gcc/testsuite/c-c++-common/gomp/pr120180-2.c [new file with mode: 0644]
gcc/testsuite/g++.dg/gomp/attrs-imperfect1.C
gcc/testsuite/g++.dg/gomp/attrs-imperfect4.C
gcc/testsuite/g++.dg/gomp/pr120180-1.C [new file with mode: 0644]
gcc/testsuite/gfortran.dg/gomp/declare-variant-2.f90
gcc/testsuite/gfortran.dg/gomp/declare-variant-20.f90
gcc/testsuite/gfortran.dg/gomp/pr120180-1.f90 [new file with mode: 0644]
gcc/testsuite/gfortran.dg/gomp/pr120180-2.f90 [new file with mode: 0644]
gcc/testsuite/gfortran.dg/gomp/pr122306-1.f90 [new file with mode: 0644]
gcc/testsuite/gfortran.dg/gomp/pr122306-2.f90 [new file with mode: 0644]