[flang-commits] [flang] [flang][OpenMP] Fix symbol handling in critical constructs (PR #90671)

Leandro Lupori via flang-commits flang-commits at lists.llvm.org
Fri May 3 14:30:36 PDT 2024


https://github.com/luporl updated https://github.com/llvm/llvm-project/pull/90671

>From 240a9851173875267dbbfd28d9b35ca3454ac228 Mon Sep 17 00:00:00 2001
From: Leandro Lupori <leandro.lupori at linaro.org>
Date: Tue, 30 Apr 2024 18:38:29 -0300
Subject: [PATCH] [flang][OpenMP] Fix symbol handling in critical/sections
 constructs

Fixes https://github.com/llvm/llvm-project/issues/78936
---
 flang/lib/Semantics/resolve-directives.cpp    |  2 ++
 .../Semantics/OpenMP/parallel-critical-do.f90 | 18 ++++++++++++++++++
 .../Semantics/OpenMP/parallel-sections-do.f90 | 19 +++++++++++++++++++
 3 files changed, 39 insertions(+)
 create mode 100644 flang/test/Semantics/OpenMP/parallel-critical-do.f90
 create mode 100644 flang/test/Semantics/OpenMP/parallel-sections-do.f90

diff --git a/flang/lib/Semantics/resolve-directives.cpp b/flang/lib/Semantics/resolve-directives.cpp
index 318687508ff1f5..1238e7df66278d 100644
--- a/flang/lib/Semantics/resolve-directives.cpp
+++ b/flang/lib/Semantics/resolve-directives.cpp
@@ -1811,6 +1811,7 @@ bool OmpAttributeVisitor::Pre(const parser::OpenMPSectionsConstruct &x) {
   case llvm::omp::Directive::OMPD_parallel_sections:
   case llvm::omp::Directive::OMPD_sections:
     PushContext(beginDir.source, beginDir.v);
+    GetContext().withinConstruct = true;
     break;
   default:
     break;
@@ -1823,6 +1824,7 @@ bool OmpAttributeVisitor::Pre(const parser::OpenMPCriticalConstruct &x) {
   const auto &beginCriticalDir{std::get<parser::OmpCriticalDirective>(x.t)};
   const auto &endCriticalDir{std::get<parser::OmpEndCriticalDirective>(x.t)};
   PushContext(beginCriticalDir.source, llvm::omp::Directive::OMPD_critical);
+  GetContext().withinConstruct = true;
   if (const auto &criticalName{
           std::get<std::optional<parser::Name>>(beginCriticalDir.t)}) {
     ResolveOmpName(*criticalName, Symbol::Flag::OmpCriticalLock);
diff --git a/flang/test/Semantics/OpenMP/parallel-critical-do.f90 b/flang/test/Semantics/OpenMP/parallel-critical-do.f90
new file mode 100644
index 00000000000000..6e10b46dea9a00
--- /dev/null
+++ b/flang/test/Semantics/OpenMP/parallel-critical-do.f90
@@ -0,0 +1,18 @@
+! RUN: %python %S/../test_symbols.py %s %flang_fc1 -fopenmp
+
+! Check that loop iteration variables are private and predetermined, even when
+! nested inside parallel/critical constructs.
+
+!DEF: /test1 (Subroutine) Subprogram
+subroutine test1
+  !DEF: /test1/i ObjectEntity INTEGER(4)
+  integer i
+
+  !$omp parallel default(none)
+    !$omp critical
+      !DEF: /test1/OtherConstruct1/i (OmpPrivate, OmpPreDetermined) HostAssoc INTEGER(4)
+      do i = 1, 10
+      end do
+    !$omp end critical
+  !$omp end parallel
+end subroutine
diff --git a/flang/test/Semantics/OpenMP/parallel-sections-do.f90 b/flang/test/Semantics/OpenMP/parallel-sections-do.f90
new file mode 100644
index 00000000000000..39102175299bab
--- /dev/null
+++ b/flang/test/Semantics/OpenMP/parallel-sections-do.f90
@@ -0,0 +1,19 @@
+! RUN: %python %S/../test_symbols.py %s %flang_fc1 -fopenmp
+
+! Check that loop iteration variables are private and predetermined, even when
+! nested inside parallel/sections constructs.
+
+!DEF: /test1 (Subroutine) Subprogram
+subroutine test1
+  !DEF: /test1/i ObjectEntity INTEGER(4)
+  integer i
+
+  !$omp parallel default(none)
+    !$omp sections
+      !$omp section
+        !DEF: /test1/OtherConstruct1/i (OmpPrivate, OmpPreDetermined) HostAssoc INTEGER(4)
+        do i = 1, 10
+        end do
+    !$omp end sections
+  !$omp end parallel
+end subroutine



More information about the flang-commits mailing list