Skip to content

Commit 9c464e6

Browse files
authored
[flang][OpenMP] Don't try to privatize FORALL/DO CONCURRENT indices (#123341)
FORALL/DO CONCURRENT indices have predetermined private DSA (OpenMP 5.2 5.1.1). As FORALL/DO CONCURRENT indices are defined in the construct itself, and OpenMP directives may not appear in it, they are already private and don't need to be modified. Fixes #100919 Fixes #120023 Fixes #123537
1 parent 623ba9b commit 9c464e6

File tree

3 files changed

+40
-21
lines changed

3 files changed

+40
-21
lines changed

flang/lib/Semantics/resolve-directives.cpp

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1777,28 +1777,13 @@ void OmpAttributeVisitor::ResolveSeqLoopIndexInParallelOrTaskConstruct(
17771777
// Use of DO CONCURRENT inside OpenMP construct is unspecified behavior
17781778
// till OpenMP-5.0 standard.
17791779
// In above both cases we skip the privatization of iteration variables.
1780-
// [OpenMP 5.1] DO CONCURRENT indices are private
17811780
bool OmpAttributeVisitor::Pre(const parser::DoConstruct &x) {
17821781
if (!dirContext_.empty() && GetContext().withinConstruct) {
17831782
llvm::SmallVector<const parser::Name *> ivs;
17841783
if (x.IsDoNormal()) {
17851784
const parser::Name *iv{GetLoopIndex(x)};
17861785
if (iv && iv->symbol)
17871786
ivs.push_back(iv);
1788-
} else if (x.IsDoConcurrent()) {
1789-
const Fortran::parser::LoopControl *loopControl = &*x.GetLoopControl();
1790-
const Fortran::parser::LoopControl::Concurrent &concurrent =
1791-
std::get<Fortran::parser::LoopControl::Concurrent>(loopControl->u);
1792-
const Fortran::parser::ConcurrentHeader &concurrentHeader =
1793-
std::get<Fortran::parser::ConcurrentHeader>(concurrent.t);
1794-
const std::list<Fortran::parser::ConcurrentControl> &controls =
1795-
std::get<std::list<Fortran::parser::ConcurrentControl>>(
1796-
concurrentHeader.t);
1797-
for (const auto &control : controls) {
1798-
const parser::Name *iv{&std::get<0>(control.t)};
1799-
if (iv && iv->symbol)
1800-
ivs.push_back(iv);
1801-
}
18021787
}
18031788
ordCollapseLevel--;
18041789
for (auto iv : ivs) {
@@ -1810,9 +1795,6 @@ bool OmpAttributeVisitor::Pre(const parser::DoConstruct &x) {
18101795
if (ordCollapseLevel) {
18111796
if (const auto *details{iv->symbol->detailsIf<HostAssocDetails>()}) {
18121797
const Symbol *tpSymbol = &details->symbol();
1813-
// TODO: DoConcurrent won't capture the following check because a new
1814-
// symbol is declared in ResolveIndexName(), which will not have the
1815-
// OmpThreadprivate flag.
18161798
if (tpSymbol->test(Symbol::Flag::OmpThreadprivate)) {
18171799
context_.Say(iv->source,
18181800
"Loop iteration variable %s is not allowed in THREADPRIVATE."_err_en_US,
@@ -2119,6 +2101,7 @@ static bool IsPrivatizable(const Symbol *sym) {
21192101
*sym) && /* OpenMP 5.2, 5.1.1: Assumed-size arrays are shared*/
21202102
!sym->owner().IsDerivedType() &&
21212103
sym->owner().kind() != Scope::Kind::ImpliedDos &&
2104+
sym->owner().kind() != Scope::Kind::Forall &&
21222105
!sym->detailsIf<semantics::AssocEntityDetails>() &&
21232106
!sym->detailsIf<semantics::NamelistDetails>() &&
21242107
(!misc ||

flang/test/Semantics/OpenMP/doconcurrent01.f90

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
! RUN: %python %S/../test_symbols.py %s %flang_fc1 -fopenmp
22

3-
! OpenMP 5.1.1
4-
! DO Concurrent indices are private
3+
! OpenMP 5.2 5.1.1 Variables Referenced in a Construct
4+
! DO CONCURRENT indices have predetermined private DSA.
5+
!
6+
! As DO CONCURRENT indices are defined in the construct itself, and OpenMP
7+
! directives may not appear in it, they are already private.
8+
! Check that index symbols are not modified.
59

610
!DEF: /private_iv (Subroutine)Subprogram
711
subroutine private_iv
812
!DEF: /private_iv/i ObjectEntity INTEGER(4)
913
integer i
1014
!$omp parallel default(private)
1115
!$omp single
12-
!DEF: /private_iv/OtherConstruct1/i (OmpPrivate, OmpPreDetermined) HostAssoc INTEGER(4)
16+
!DEF: /private_iv/OtherConstruct1/OtherConstruct1/Forall1/i ObjectEntity INTEGER(4)
1317
do concurrent(i=1:2)
1418
end do
1519
!$omp end single
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
! RUN: %python %S/../test_symbols.py %s %flang_fc1 -fopenmp
2+
3+
! OpenMP 5.2 5.1.1 Variables Referenced in a Construct
4+
! FORALL indices have predetermined private DSA.
5+
!
6+
! As FORALL indices are defined in the construct itself, and OpenMP
7+
! directives may not appear in it, they are already private.
8+
! Check that index symbols are not modified.
9+
10+
!DEF: /MainProgram1/a ObjectEntity INTEGER(4)
11+
!DEF: /MainProgram1/b ObjectEntity INTEGER(4)
12+
integer a(5), b(5)
13+
14+
!REF: /MainProgram1/a
15+
a = 0
16+
!REF: /MainProgram1/b
17+
b = 0
18+
19+
!$omp parallel
20+
!DEF: /MainProgram1/OtherConstruct1/Forall1/i (Implicit) ObjectEntity INTEGER(4)
21+
!DEF: /MainProgram1/OtherConstruct1/a HostAssoc INTEGER(4)
22+
!DEF: /MainProgram1/OtherConstruct1/b HostAssoc INTEGER(4)
23+
forall(i = 1:5) a(i) = b(i) * 2
24+
!$omp end parallel
25+
26+
!$omp parallel default(private)
27+
!DEF: /MainProgram1/OtherConstruct2/Forall1/i (Implicit) ObjectEntity INTEGER(4)
28+
!DEF: /MainProgram1/OtherConstruct2/a (OmpPrivate) HostAssoc INTEGER(4)
29+
!DEF: /MainProgram1/OtherConstruct2/b (OmpPrivate) HostAssoc INTEGER(4)
30+
forall(i = 1:5) a(i) = b(i) * 2
31+
!$omp end parallel
32+
end program

0 commit comments

Comments
 (0)