[flang-commits] [flang] [Flang][OpenMP] Support iterator modifier in map and motion clauses (PR #197757)

via flang-commits flang-commits at lists.llvm.org
Tue Aug 4 19:49:05 PDT 2026


================
@@ -4932,7 +4955,30 @@ void OmpStructureChecker::Enter(const parser::OmpClause::Map &x) {
   if (!hasRefModifier &&
       (llvm::is_contained(leafs, Directive::OMPD_target_enter_data) ||
           llvm::is_contained(leafs, Directive::OMPD_target_exit_data))) {
+    UnorderedSymbolSet iteratorSymbols;
+    if (iterator) {
+      for (const parser::OmpIteratorSpecifier &iterSpec : iterator->v) {
+        const auto &typeDecl{std::get<parser::TypeDeclarationStmt>(iterSpec.t)};
+        const auto &entities{
+            std::get<std::list<parser::EntityDecl>>(typeDecl.t)};
+        for (const parser::EntityDecl &entity : entities) {
+          const auto &name{std::get<parser::ObjectName>(entity.t)};
+          if (name.symbol)
+            iteratorSymbols.insert(name.symbol->GetUltimate());
+        }
+      }
+    }
+
     for (const parser::OmpObject &object : objects.v) {
+      bool referencesIterator{false};
+      if (const auto *designator{GetDesignatorFromObj(object)}) {
+        OmpIteratorReferenceChecker checker{iteratorSymbols};
+        parser::Walk(*designator, checker);
+        referencesIterator = checker.found();
+      }
+      if (referencesIterator)
----------------
MattPD wrote:

Skipping iterator-referencing objects applies to the enter and the exit side alike, so an iterator exit map no longer registers as the matching exit. A plain `target enter data map(to: a)` followed by `target exit data map(iterator(i = 1:n), from: a(i))` now warns on the plain enter map with "The map of 'a' may include a descriptor that is created locally". Before this PR that enter map did not warn. I think the new warning is semantically correct, because an iterator exit map removes selected data but not the descriptor. If so, an enter-plain/exit-iterator case in `target-enter-data-temp-descriptor.f90` would document it, since the new tests cover only the same-clause case.

Is the new warning on the plain enter map intended?

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


More information about the flang-commits mailing list