]> git.ipfire.org Git - thirdparty/gcc.git/commit
OpenMP/Fortran: Revamp handling of labels in metadirectives [PR122369,PR122508]
authorPaul-Antoine Arras <parras@baylibre.com>
Tue, 28 Oct 2025 16:27:47 +0000 (17:27 +0100)
committerPaul-Antoine Arras <parras@baylibre.com>
Tue, 4 Nov 2025 15:14:01 +0000 (16:14 +0100)
commit7fa8420170b7a8ca40d7414ddcddaed425442cee
tree2214a7d19267a9f175a99fb2e0a4438ea4e0e023
parent0834dc3a80ebffdd28e27739c0d5c0c5b1f681f9
OpenMP/Fortran: Revamp handling of labels in metadirectives [PR122369,PR122508]

When a label is matched in the first statement after the end of a metadirective
body, it is bound to the associated region. However this prevents it from being
referenced elsewhere.
This patch fixes it by rebinding such labels to the outer region. It also
ensures that labels defined in an outer region can be referenced in a
metadirective body.

PR fortran/122369
PR fortran/122508

gcc/fortran/ChangeLog:
* gfortran.h (gfc_rebind_label): Declare new function.
* parse.cc (parse_omp_metadirective_body): Rebind labels to the outer
region. Maintain a vector of metadirective regions.
(gfc_parse_file): Initialise it.
* parse.h (GFC_PARSE_H): Declare it.
* symbol.cc (gfc_get_st_label): Look for existing labels in outer
metadirective regions.
(gfc_rebind_label): Define new function.
(gfc_define_st_label): Accept duplicate labels in metadirective body.
(gfc_reference_st_label): Accept shared DO termination labels in
metadirective body.

gcc/testsuite/ChangeLog:

* gfortran.dg/gomp/pr122369-1.f90: New test.
* gfortran.dg/gomp/pr122369-2.f90: New test.
* gfortran.dg/gomp/pr122369-3.f90: New test.
* gfortran.dg/gomp/pr122369-4.f90: New test.
* gfortran.dg/gomp/pr122508-1.f90: New test.
* gfortran.dg/gomp/pr122508-2.f90: New test.
gcc/fortran/gfortran.h
gcc/fortran/parse.cc
gcc/fortran/parse.h
gcc/fortran/symbol.cc
gcc/testsuite/gfortran.dg/gomp/pr122369-1.f90 [new file with mode: 0644]
gcc/testsuite/gfortran.dg/gomp/pr122369-2.f90 [new file with mode: 0644]
gcc/testsuite/gfortran.dg/gomp/pr122369-3.f90 [new file with mode: 0644]
gcc/testsuite/gfortran.dg/gomp/pr122369-4.f90 [new file with mode: 0644]
gcc/testsuite/gfortran.dg/gomp/pr122508-1.f90 [new file with mode: 0644]
gcc/testsuite/gfortran.dg/gomp/pr122508-2.f90 [new file with mode: 0644]