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

Anchu Rajendran S via llvm-commits llvm-commits at lists.llvm.org
Sun Sep 22 22:08:10 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) {},
----------------
anchuraj wrote:

Modified this. Thankyou. 

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


More information about the llvm-commits mailing list