From 240a9851173875267dbbfd28d9b35ca3454ac228 Mon Sep 17 00:00:00 2001 From: Leandro Lupori 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 318687508ff1f..1238e7df66278 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(x.t)}; const auto &endCriticalDir{std::get(x.t)}; PushContext(beginCriticalDir.source, llvm::omp::Directive::OMPD_critical); + GetContext().withinConstruct = true; if (const auto &criticalName{ std::get>(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 0000000000000..6e10b46dea9a0 --- /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 0000000000000..39102175299ba --- /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