[flang-commits] [flang] [flang][OpenMP] Don't try to privatize FORALL indices (PR #123341)

via flang-commits flang-commits at lists.llvm.org
Fri Jan 17 05:36:31 PST 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-flang-semantics

@llvm/pr-subscribers-flang-openmp

Author: Leandro Lupori (luporl)

<details>
<summary>Changes</summary>

FORALL indices have predetermined private DSA (OpenMP 5.2 5.1.1).

As lowering already makes them private, don't modify FORALL index
symbols.

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


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


2 Files Affected:

- (modified) flang/lib/Semantics/resolve-directives.cpp (+1) 
- (added) flang/test/Semantics/OpenMP/forall.f90 (+30) 


``````````diff
diff --git a/flang/lib/Semantics/resolve-directives.cpp b/flang/lib/Semantics/resolve-directives.cpp
index 39478b58a9070d..878021e0f71609 100644
--- a/flang/lib/Semantics/resolve-directives.cpp
+++ b/flang/lib/Semantics/resolve-directives.cpp
@@ -2119,6 +2119,7 @@ static bool IsPrivatizable(const Symbol *sym) {
           *sym) && /* OpenMP 5.2, 5.1.1: Assumed-size arrays are shared*/
       !sym->owner().IsDerivedType() &&
       sym->owner().kind() != Scope::Kind::ImpliedDos &&
+      sym->owner().kind() != Scope::Kind::Forall &&
       !sym->detailsIf<semantics::AssocEntityDetails>() &&
       !sym->detailsIf<semantics::NamelistDetails>() &&
       (!misc ||
diff --git a/flang/test/Semantics/OpenMP/forall.f90 b/flang/test/Semantics/OpenMP/forall.f90
new file mode 100644
index 00000000000000..c7fb8c64edb24e
--- /dev/null
+++ b/flang/test/Semantics/OpenMP/forall.f90
@@ -0,0 +1,30 @@
+! RUN: %python %S/../test_symbols.py %s %flang_fc1 -fopenmp
+
+! OpenMP 5.2 5.1.1 Variables Referenced in a Construct
+! FORALL indices have predetermined private DSA.
+! As lowering already makes them private, check that their symbols are not
+! modified.
+
+  !DEF: /MainProgram1/a ObjectEntity INTEGER(4)
+  !DEF: /MainProgram1/b ObjectEntity INTEGER(4)
+  integer a(5), b(5)
+
+  !REF: /MainProgram1/a
+  a = 0
+  !REF: /MainProgram1/b
+  b = 0
+
+  !$omp parallel
+    !DEF: /MainProgram1/OtherConstruct1/Forall1/i (Implicit) ObjectEntity INTEGER(4)
+    !DEF: /MainProgram1/OtherConstruct1/a HostAssoc INTEGER(4)
+    !DEF: /MainProgram1/OtherConstruct1/b HostAssoc INTEGER(4)
+    forall(i = 1:5) a(i) = b(i) * 2
+  !$omp end parallel
+
+  !$omp parallel default(private)
+    !DEF: /MainProgram1/OtherConstruct2/Forall1/i (Implicit) ObjectEntity INTEGER(4)
+    !DEF: /MainProgram1/OtherConstruct2/a (OmpPrivate) HostAssoc INTEGER(4)
+    !DEF: /MainProgram1/OtherConstruct2/b (OmpPrivate) HostAssoc INTEGER(4)
+    forall(i = 1:5) a(i) = b(i) * 2
+  !$omp end parallel
+end program

``````````

</details>


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


More information about the flang-commits mailing list