[PATCH] OpenMP/Fortran: Rebind labels after metadirective body [PR122369]

Tobias Burnus tburnus@baylibre.com
Wed Oct 29 18:44:48 GMT 2025


Paul-Antoine Arras wrote:
> 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
> reference elsewhere.
> This patch fixes it by rebinding such labels to the outer region.

This does not seem to work in general:

integer :: cnt, x

cnt = 0
!$omp begin metadirective when(user={condition(cnt > 0)} : parallel)
   x = 5
!$omp end metadirective
1234 format("Hello")
write(*,1234)

!$omp begin metadirective when(user={condition(x > 0)} : parallel)
   x = 5
!$omp end metadirective
4567 print *, 'hello', cnt
cnt = cnt + 1
if (cnt < 2) goto 4567
end

* * *

Not necessarily in this patch, but I think it would be good if
the following worked as well:

implicit none
integer :: cnt
1345 format("The count is ", g0)

cnt = 0
write(*,1345) cnt

!$omp begin metadirective when(user={condition(cnt > 0)} : parallel)
   write(*,1345) cnt
!$omp end metadirective
end

which seems to be a somewhat sensible usage pattern.
But admittedly, it is not the same issue as PR122369
and could also be deferred (i.e. a new PR created for it).

Tobias



More information about the Fortran mailing list