Skip to content

Commit 240a985

Browse files
committed
[flang][OpenMP] Fix symbol handling in critical/sections constructs
Fixes #78936
1 parent bb1a8bb commit 240a985

File tree

3 files changed

+39
-0
lines changed

3 files changed

+39
-0
lines changed

flang/lib/Semantics/resolve-directives.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1811,6 +1811,7 @@ bool OmpAttributeVisitor::Pre(const parser::OpenMPSectionsConstruct &x) {
18111811
case llvm::omp::Directive::OMPD_parallel_sections:
18121812
case llvm::omp::Directive::OMPD_sections:
18131813
PushContext(beginDir.source, beginDir.v);
1814+
GetContext().withinConstruct = true;
18141815
break;
18151816
default:
18161817
break;
@@ -1823,6 +1824,7 @@ bool OmpAttributeVisitor::Pre(const parser::OpenMPCriticalConstruct &x) {
18231824
const auto &beginCriticalDir{std::get<parser::OmpCriticalDirective>(x.t)};
18241825
const auto &endCriticalDir{std::get<parser::OmpEndCriticalDirective>(x.t)};
18251826
PushContext(beginCriticalDir.source, llvm::omp::Directive::OMPD_critical);
1827+
GetContext().withinConstruct = true;
18261828
if (const auto &criticalName{
18271829
std::get<std::optional<parser::Name>>(beginCriticalDir.t)}) {
18281830
ResolveOmpName(*criticalName, Symbol::Flag::OmpCriticalLock);
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
! RUN: %python %S/../test_symbols.py %s %flang_fc1 -fopenmp
2+
3+
! Check that loop iteration variables are private and predetermined, even when
4+
! nested inside parallel/critical constructs.
5+
6+
!DEF: /test1 (Subroutine) Subprogram
7+
subroutine test1
8+
!DEF: /test1/i ObjectEntity INTEGER(4)
9+
integer i
10+
11+
!$omp parallel default(none)
12+
!$omp critical
13+
!DEF: /test1/OtherConstruct1/i (OmpPrivate, OmpPreDetermined) HostAssoc INTEGER(4)
14+
do i = 1, 10
15+
end do
16+
!$omp end critical
17+
!$omp end parallel
18+
end subroutine
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
! RUN: %python %S/../test_symbols.py %s %flang_fc1 -fopenmp
2+
3+
! Check that loop iteration variables are private and predetermined, even when
4+
! nested inside parallel/sections constructs.
5+
6+
!DEF: /test1 (Subroutine) Subprogram
7+
subroutine test1
8+
!DEF: /test1/i ObjectEntity INTEGER(4)
9+
integer i
10+
11+
!$omp parallel default(none)
12+
!$omp sections
13+
!$omp section
14+
!DEF: /test1/OtherConstruct1/i (OmpPrivate, OmpPreDetermined) HostAssoc INTEGER(4)
15+
do i = 1, 10
16+
end do
17+
!$omp end sections
18+
!$omp end parallel
19+
end subroutine

0 commit comments

Comments
 (0)