[llvm-branch-commits] [flang] fbf716f - [flang] Fixed restrictions checking for OpenACC loop-associated constructs.

Tobias Hieta via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Thu Mar 23 07:35:11 PDT 2023


Author: Slava Zakharin
Date: 2023-03-23T15:33:09+01:00
New Revision: fbf716ffe163eb03a81f66eaa3db839cc6d3975e

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

LOG: [flang] Fixed restrictions checking for OpenACC loop-associated constructs.

CheckDoConcurrentClauseRestriction and CheckTileClauseRestriction expect
that the construct has associated DoConstruct, while it is not set
when the do-loop has no loop control. The change is to skip the clauses
checks, when the do-loop does not have the loop control.

An alternative fix would be to associate the DoConstruct even when
the do-loop has no loop control and let Check*ClauseRestriction run their
checks, but I am not sure if associating invalid DoConstruct is a good idea.

This fixes failure in Semantics/OpenACC/acc-canonicalization-validity.f90
reported in D142279.

Reviewed By: clementval

Differential Revision: https://reviews.llvm.org/D142652

(cherry picked from commit 02445263e2f533573a935c1bd502d848bbe6bb27)

Added: 
    

Modified: 
    flang/lib/Semantics/canonicalize-acc.cpp

Removed: 
    


################################################################################
diff  --git a/flang/lib/Semantics/canonicalize-acc.cpp b/flang/lib/Semantics/canonicalize-acc.cpp
index 855f62f53ff8d..5afae172cfaa2 100644
--- a/flang/lib/Semantics/canonicalize-acc.cpp
+++ b/flang/lib/Semantics/canonicalize-acc.cpp
@@ -127,17 +127,17 @@ class CanonicalizationOfAcc {
     nextIt = it;
     if (++nextIt != block.end()) {
       if (auto *doCons{parser::Unwrap<parser::DoConstruct>(*nextIt)}) {
-        if (doCons->GetLoopControl()) {
-          // move DoConstruct
-          std::get<std::optional<parser::DoConstruct>>(x.t) =
-              std::move(*doCons);
-          nextIt = block.erase(nextIt);
-        } else {
+        if (!doCons->GetLoopControl()) {
           messages_.Say(dir.source,
               "DO loop after the %s directive must have loop control"_err_en_US,
               parser::ToUpperCaseLetters(dir.source.ToString()));
+          return;
         }
 
+        // move DoConstruct
+        std::get<std::optional<parser::DoConstruct>>(x.t) = std::move(*doCons);
+        nextIt = block.erase(nextIt);
+
         CheckDoConcurrentClauseRestriction<parser::OpenACCLoopConstruct,
             parser::AccBeginLoopDirective>(x);
         CheckTileClauseRestriction<parser::OpenACCLoopConstruct,
@@ -173,24 +173,23 @@ class CanonicalizationOfAcc {
     nextIt = it;
     if (++nextIt != block.end()) {
       if (auto *doCons{parser::Unwrap<parser::DoConstruct>(*nextIt)}) {
-        if (doCons->GetLoopControl()) {
-          // move DoConstruct
-          std::get<std::optional<parser::DoConstruct>>(x.t) =
-              std::move(*doCons);
-          nextIt = block.erase(nextIt);
-          // try to match AccEndCombinedDirective
-          if (nextIt != block.end()) {
-            if (auto *endDir{
-                    parser::Unwrap<parser::AccEndCombinedDirective>(*nextIt)}) {
-              std::get<std::optional<parser::AccEndCombinedDirective>>(x.t) =
-                  std::move(*endDir);
-              block.erase(nextIt);
-            }
-          }
-        } else {
+        if (!doCons->GetLoopControl()) {
           messages_.Say(dir.source,
               "DO loop after the %s directive must have loop control"_err_en_US,
               parser::ToUpperCaseLetters(dir.source.ToString()));
+          return;
+        }
+        // move DoConstruct
+        std::get<std::optional<parser::DoConstruct>>(x.t) = std::move(*doCons);
+        nextIt = block.erase(nextIt);
+        // try to match AccEndCombinedDirective
+        if (nextIt != block.end()) {
+          if (auto *endDir{
+                  parser::Unwrap<parser::AccEndCombinedDirective>(*nextIt)}) {
+            std::get<std::optional<parser::AccEndCombinedDirective>>(x.t) =
+                std::move(*endDir);
+            block.erase(nextIt);
+          }
         }
 
         CheckDoConcurrentClauseRestriction<parser::OpenACCCombinedConstruct,


        


More information about the llvm-branch-commits mailing list