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

Paul-Antoine Arras parras@baylibre.com
Fri Oct 31 15:45:40 GMT 2025


On 29/10/2025 18:44, Tobias Burnus wrote:
> 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

Here is a revamped version of the patch that should handle properly more 
cases.

> * * *
> 
> 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).

I have now created a new PR for that: https://gcc.gnu.org/PR122508.

Thanks,
-- 
PA
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-OpenMP-Fortran-Rebind-labels-after-metadirective-bod.patch
Type: text/x-patch
Size: 7961 bytes
Desc: not available
URL: <https://gcc.gnu.org/pipermail/fortran/attachments/20251031/65ff4b9e/attachment.bin>


More information about the Fortran mailing list