Paul-Antoine Arras wrote:
Here is a revamped patch as well as some inline replies.
Thanks,
On 31/10/2025 17:41, Tobias Burnus wrote:
Error: Label 4567 referenced at (1) is never defined

Added testcase. Fixed in the attached patch.

Can you also add a test case like
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=122508#c1

Namely, testing that a label of an outer scope
that get redefined in an inner scope will print
an error? Like the one in comment 1 - or a bit
refined:

Like:

1234 ...
!$omp metadirective ...
   5678 ...
   !$omp metadirective ...
      1234 ... ! re-used outerside one
      5678 ... ! re-used outer one

* * *

The attached patch should now incorporate your draft and handle PR122508 as well.

Thanks :-)


Subject: [PATCH] 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.


The patch LGTM – but please add an dg-error test case on top, as suggested above. (Could also be a separate follow-up commit.)

Thanks,

Tobias

Reply via email to