From 857dd4da7187c9d345d0913b73601e65ed5f06da Mon Sep 17 00:00:00 2001 From: Krzysztof Parzyszek Date: Sat, 22 Nov 2025 14:51:04 -0600 Subject: [PATCH] [flang][OpenMP] Canonicalize loops with intervening OpenMP constructs Example based on the gfortran test a.6.1.f90 ``` do 100 i = 1,10 !$omp do do 100 j = 1,10 call work(i,j) 100 continue ``` During canonicalization of label-DO loops, if the body of an OpenMP construct ends with a label, treat the label as ending the construct itself. This will also allow handling of cases like ``` do 100 i = 1, 10 !$omp atomic write 100 x = i ``` which we were unable to before. --- flang/include/flang/Parser/openmp-utils.h | 1 + flang/lib/Parser/openmp-utils.cpp | 39 ++++++++++++++++ flang/lib/Semantics/canonicalize-do.cpp | 17 +++++-- flang/test/Parser/OpenMP/atomic-label-do.f90 | 39 ++++++++++++++++ flang/test/Parser/OpenMP/cross-label-do.f90 | 48 ++++++++++++++++++++ 5 files changed, 141 insertions(+), 3 deletions(-) create mode 100644 flang/test/Parser/OpenMP/atomic-label-do.f90 create mode 100644 flang/test/Parser/OpenMP/cross-label-do.f90 diff --git a/flang/include/flang/Parser/openmp-utils.h b/flang/include/flang/Parser/openmp-utils.h index d4b739f4c9529..b72164e6cef4b 100644 --- a/flang/include/flang/Parser/openmp-utils.h +++ b/flang/include/flang/Parser/openmp-utils.h @@ -135,6 +135,7 @@ template struct IsStatement> { }; std::optional