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

Leandro Lupori via flang-commits flang-commits at lists.llvm.org
Fri Jan 17 05:35:56 PST 2025


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

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


>From 4e291f6df265155b3558b0cb996ff5bd10f62574 Mon Sep 17 00:00:00 2001
From: Leandro Lupori <leandro.lupori at linaro.org>
Date: Fri, 17 Jan 2025 09:23:55 -0300
Subject: [PATCH] [flang][OpenMP] Don't try to privatize FORALL indices

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
---
 flang/lib/Semantics/resolve-directives.cpp |  1 +
 flang/test/Semantics/OpenMP/forall.f90     | 30 ++++++++++++++++++++++
 2 files changed, 31 insertions(+)
 create mode 100644 flang/test/Semantics/OpenMP/forall.f90

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



More information about the flang-commits mailing list