[flang-commits] [flang] [llvm] [Flang][OpenMP][Sema] Adding parsing and semantic support for scan directive. (PR #102792)

Sergio Afonso via flang-commits flang-commits at lists.llvm.org
Fri Sep 13 06:24:28 PDT 2024


================
@@ -751,7 +759,43 @@ void OmpStructureChecker::CheckDistLinear(
   }
 }
 
-void OmpStructureChecker::Leave(const parser::OpenMPLoopConstruct &) {
+void OmpStructureChecker::Leave(const parser::OpenMPLoopConstruct &x) {
+  const auto &beginLoopDir = std::get<parser::OmpBeginLoopDirective>(x.t);
+  const auto &clauseList{std::get<parser::OmpClauseList>(beginLoopDir.t)};
+  for (const auto &clause : clauseList.v) {
+    if (const auto *reductionClause{
+            std::get_if<parser::OmpClause::Reduction>(&clause.u)}) {
+      using ReductionModifier = parser::OmpReductionClause::ReductionModifier;
+      const auto &maybeModifier{
+          std::get<std::optional<ReductionModifier>>(reductionClause->v.t)};
+      if (maybeModifier && *maybeModifier == ReductionModifier::Inscan) {
+
+        const auto &objectList{
+            std::get<parser::OmpObjectList>(reductionClause->v.t)};
+        for (const auto &ompObj : objectList.v) {
+          common::visit(
+              common::visitors{
+                  [&](const parser::Designator &designator) {
+                    if (const auto *name{semantics::getDesignatorNameIfDataRef(
+                            designator)}) {
+                      std::string nameStr = name->symbol->name().ToString();
+                      if (GetContext().usedInScanDirective.find(nameStr) ==
+                          GetContext().usedInScanDirective.end()) {
+                        context_.Say(name->source,
+                            "List item %s must appear in 'inclusive' or "
+                            "'exclusive' clause of an "
+                            "enclosed scan directive"_err_en_US,
+                            nameStr);
+                      }
+                    }
+                  },
+                  [&](const auto &name) {},
----------------
skatrak wrote:

Shouldn't we check `name.symbol` as well here? I understand this code path is triggered by passing a common block to the reduction clause, which doesn't seem to be forbidden by the spec (I could be wrong, though). In that case, perhaps the simplest solution here would be to extract part of the body of the `parser::Designator` case above into a lambda taking a `Symbol *` as parameter to be called from both places.

https://github.com/llvm/llvm-project/pull/102792


More information about the flang-commits mailing list