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

via flang-commits flang-commits at lists.llvm.org
Mon May 6 04:18:06 PDT 2024


Author: Leandro Lupori
Date: 2024-05-06T08:18:02-03:00
New Revision: e365ac809e1c01bbbcf70a20057f3dbbc7e14b49

URL: https://github.com/llvm/llvm-project/commit/e365ac809e1c01bbbcf70a20057f3dbbc7e14b49
DIFF: https://github.com/llvm/llvm-project/commit/e365ac809e1c01bbbcf70a20057f3dbbc7e14b49.diff

LOG: [flang][OpenMP] Fix symbol handling in critical/sections constructs  (#90671)

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

Added: 
    flang/test/Semantics/OpenMP/parallel-critical-do.f90
    flang/test/Semantics/OpenMP/parallel-sections-do.f90

Modified: 
    flang/lib/Semantics/resolve-directives.cpp

Removed: 
    


################################################################################
diff  --git a/flang/lib/Semantics/resolve-directives.cpp b/flang/lib/Semantics/resolve-directives.cpp
index 9c5d81be7ab7fd..2add2056f658d3 100644
--- a/flang/lib/Semantics/resolve-directives.cpp
+++ b/flang/lib/Semantics/resolve-directives.cpp
@@ -1813,6 +1813,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;
@@ -1825,6 +1826,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