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

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


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

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

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


>From 3dfc430277045c7c20a2f6ecf84f7469d91ba648 Mon Sep 17 00:00:00 2001
From: Leandro Lupori <leandro.lupori at linaro.org>
Date: Thu, 21 Mar 2024 17:24:04 -0300
Subject: [PATCH] [flang][OpenMP] Allow loop iteration variables in DSA clauses

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

Fixes https://github.com/llvm/llvm-project/issues/78938
---
 flang/lib/Semantics/resolve-directives.cpp |  6 ++++++
 flang/test/Semantics/OpenMP/do20.f90       | 18 ++++++++++++++++++
 2 files changed, 24 insertions(+)
 create mode 100644 flang/test/Semantics/OpenMP/do20.f90

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



More information about the flang-commits mailing list