[flang-commits] [flang] [flang][OpenMP] Allow loop iteration variables in DSA clauses (PR #86194)

via flang-commits flang-commits at lists.llvm.org
Thu Mar 21 13:29:57 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-flang-openmp

Author: Leandro Lupori (luporl)

<details>
<summary>Changes</summary>

Iteration variables of non-associated loops may be listed in DSA
clauses.

Fixes https://github.com/llvm/llvm-project/issues/78938


---
Full diff: https://github.com/llvm/llvm-project/pull/86194.diff


2 Files Affected:

- (modified) flang/lib/Semantics/resolve-directives.cpp (+6) 
- (added) flang/test/Semantics/OpenMP/do20.f90 (+18) 


``````````diff
diff --git a/flang/lib/Semantics/resolve-directives.cpp b/flang/lib/Semantics/resolve-directives.cpp
index 6d58013b87d298..95dea05d9a760d 100644
--- a/flang/lib/Semantics/resolve-directives.cpp
+++ b/flang/lib/Semantics/resolve-directives.cpp
@@ -1649,6 +1649,12 @@ void OmpAttributeVisitor::ResolveSeqLoopIndexInParallelOrTaskConstruct(
       break;
     }
   }
+  // If this symbol already has a data-sharing attribute then there is nothing
+  // to do here.
+  if (const Symbol *symbol = iv.symbol)
+    for (auto symMap : targetIt->objectWithDSA)
+      if (symMap.first->name() == symbol->name())
+        return;
   // If this symbol is already Private or Firstprivate in the enclosing
   // OpenMP parallel or task then there is nothing to do here.
   if (auto *symbol{targetIt->scope.FindSymbol(iv.source)}) {
diff --git a/flang/test/Semantics/OpenMP/do20.f90 b/flang/test/Semantics/OpenMP/do20.f90
new file mode 100644
index 00000000000000..915d01e69edd74
--- /dev/null
+++ b/flang/test/Semantics/OpenMP/do20.f90
@@ -0,0 +1,18 @@
+! RUN: %python %S/../test_symbols.py %s %flang_fc1 -fopenmp
+
+! OpenMP 5.2 5.1.1
+! Iteration variables of non-associated loops may be listed in DSA clauses.
+
+!DEF: /shared_iv (Subroutine)Subprogram
+subroutine shared_iv
+  !DEF: /shared_iv/i ObjectEntity INTEGER(4)
+  integer i
+
+  !$omp parallel shared(i)
+    !$omp single
+      !REF: /shared_iv/i
+      do i = 0, 1
+      end do
+    !$omp end single
+  !$omp end parallel
+end subroutine

``````````

</details>


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


More information about the flang-commits mailing list