[flang-commits] [flang] b2b3a52 - Skip compiler directives between OMP PARALLEL DO and the loop (#81021)

via flang-commits flang-commits at lists.llvm.org
Fri Feb 9 10:05:56 PST 2024


Author: Mats Petersson
Date: 2024-02-09T18:05:51Z
New Revision: b2b3a5248540320e74347fcdaffbd148d1e9d494

URL: https://github.com/llvm/llvm-project/commit/b2b3a5248540320e74347fcdaffbd148d1e9d494
DIFF: https://github.com/llvm/llvm-project/commit/b2b3a5248540320e74347fcdaffbd148d1e9d494.diff

LOG: Skip compiler directives between OMP PARALLEL DO and the loop (#81021)

This fixes a compilation error when code like this is presented to the
compiler:

  !$OMP PARALLEL DO
  !DIR$ VECTOR ALIGNED
  DO 20 i=1,N
     a = a + 0.5
20   CONTINUE

The directive itself is later ignored (with a warning that this is
happening), but because the compiler already errored out before that
point, it completely fails to compile this code. Other compilers accept
the code without complaints.

Added: 
    

Modified: 
    flang/lib/Semantics/canonicalize-omp.cpp
    flang/test/Semantics/OpenMP/loop-association.f90

Removed: 
    


################################################################################
diff  --git a/flang/lib/Semantics/canonicalize-omp.cpp b/flang/lib/Semantics/canonicalize-omp.cpp
index 013fb408214eef..01adcf53728424 100644
--- a/flang/lib/Semantics/canonicalize-omp.cpp
+++ b/flang/lib/Semantics/canonicalize-omp.cpp
@@ -90,7 +90,11 @@ class CanonicalizationOfOmp {
     auto &dir{std::get<parser::OmpLoopDirective>(beginDir.t)};
 
     nextIt = it;
-    if (++nextIt != block.end()) {
+    while (++nextIt != block.end()) {
+      // Ignore compiler directives.
+      if (auto *directive{GetConstructIf<parser::CompilerDirective>(*nextIt)})
+        continue;
+
       if (auto *doCons{GetConstructIf<parser::DoConstruct>(*nextIt)}) {
         if (doCons->GetLoopControl()) {
           // move DoConstruct
@@ -111,12 +115,14 @@ class CanonicalizationOfOmp {
               "DO loop after the %s directive must have loop control"_err_en_US,
               parser::ToUpperCaseLetters(dir.source.ToString()));
         }
-        return; // found do-loop
+      } else {
+        messages_.Say(dir.source,
+            "A DO loop must follow the %s directive"_err_en_US,
+            parser::ToUpperCaseLetters(dir.source.ToString()));
       }
+      // If we get here, we either found a loop, or issued an error message.
+      return;
     }
-    messages_.Say(dir.source,
-        "A DO loop must follow the %s directive"_err_en_US,
-        parser::ToUpperCaseLetters(dir.source.ToString()));
   }
 
   void RewriteOmpAllocations(parser::ExecutionPart &body) {

diff  --git a/flang/test/Semantics/OpenMP/loop-association.f90 b/flang/test/Semantics/OpenMP/loop-association.f90
index 8a28fd8878f496..d2167663c5ddea 100644
--- a/flang/test/Semantics/OpenMP/loop-association.f90
+++ b/flang/test/Semantics/OpenMP/loop-association.f90
@@ -30,6 +30,14 @@
      c = c - 1
   END DO outer
 
+  ! Accept directives between parallel do and actual loop.
+  !$OMP PARALLEL DO
+  !DIR$ VECTOR ALIGNED
+  DO 20 i=1,N
+     a = a + 0.5
+20   CONTINUE
+  !$OMP END PARALLEL DO
+
   c = 16
   !ERROR: DO loop after the PARALLEL DO directive must have loop control
   !$omp parallel do


        


More information about the flang-commits mailing list