Skip to content

[flang][OpenMP] Fix symbol handling in critical/sections constructs #90671

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions flang/lib/Semantics/resolve-directives.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down
18 changes: 18 additions & 0 deletions flang/test/Semantics/OpenMP/parallel-critical-do.f90
Original file line number Diff line number Diff line change
@@ -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
19 changes: 19 additions & 0 deletions flang/test/Semantics/OpenMP/parallel-sections-do.f90
Original file line number Diff line number Diff line change
@@ -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
Loading