Skip to content

Commit 20c5432

Browse files
authored
[flang][Semantics][OpenMP] Don't privatise associate names (#108856)
The associate name preserves the association with the selector established in the associate statement. Therefore it is incorrect to change the data-sharing attribute of the name. Closes #58041
1 parent b6f72fc commit 20c5432

File tree

2 files changed

+42
-3
lines changed

2 files changed

+42
-3
lines changed

flang/lib/Semantics/resolve-directives.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "flang/Parser/parse-tree.h"
2020
#include "flang/Parser/tools.h"
2121
#include "flang/Semantics/expression.h"
22+
#include "flang/Semantics/symbol.h"
2223
#include "flang/Semantics/tools.h"
2324
#include <list>
2425
#include <map>
@@ -717,7 +718,7 @@ class OmpAttributeVisitor : DirectiveAttributeVisitor<llvm::omp::Directive> {
717718
void CheckDataCopyingClause(
718719
const parser::Name &, const Symbol &, Symbol::Flag);
719720
void CheckAssocLoopLevel(std::int64_t level, const parser::OmpClause *clause);
720-
void CheckObjectInNamelist(
721+
void CheckObjectInNamelistOrAssociate(
721722
const parser::Name &, const Symbol &, Symbol::Flag);
722723
void CheckSourceLabel(const parser::Label &);
723724
void CheckLabelContext(const parser::CharBlock, const parser::CharBlock,
@@ -2356,7 +2357,7 @@ void OmpAttributeVisitor::ResolveOmpObject(
23562357
CheckMultipleAppearances(*name, *symbol, ompFlag);
23572358
}
23582359
if (privateDataSharingAttributeFlags.test(ompFlag)) {
2359-
CheckObjectInNamelist(*name, *symbol, ompFlag);
2360+
CheckObjectInNamelistOrAssociate(*name, *symbol, ompFlag);
23602361
}
23612362

23622363
if (ompFlag == Symbol::Flag::OmpAllocate) {
@@ -2713,7 +2714,7 @@ void OmpAttributeVisitor::CheckDataCopyingClause(
27132714
}
27142715
}
27152716

2716-
void OmpAttributeVisitor::CheckObjectInNamelist(
2717+
void OmpAttributeVisitor::CheckObjectInNamelistOrAssociate(
27172718
const parser::Name &name, const Symbol &symbol, Symbol::Flag ompFlag) {
27182719
const auto &ultimateSymbol{symbol.GetUltimate()};
27192720
llvm::StringRef clauseName{"PRIVATE"};
@@ -2728,6 +2729,12 @@ void OmpAttributeVisitor::CheckObjectInNamelist(
27282729
"Variable '%s' in NAMELIST cannot be in a %s clause"_err_en_US,
27292730
name.ToString(), clauseName.str());
27302731
}
2732+
2733+
if (ultimateSymbol.has<AssocEntityDetails>()) {
2734+
context_.Say(name.source,
2735+
"Variable '%s' in ASSOCIATE cannot be in a %s clause"_err_en_US,
2736+
name.ToString(), clauseName.str());
2737+
}
27312738
}
27322739

27332740
void OmpAttributeVisitor::CheckSourceLabel(const parser::Label &label) {
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
! RUN: %python %S/../test_errors.py %s %flang -fopenmp
2+
3+
! The ASSOCIATE name preserves the association with the selector established
4+
! in the associate statement. Therefore it is incorrect to change the
5+
! data-sharing attribute of the name.
6+
7+
subroutine assoc_private(x)
8+
integer :: x
9+
associate(z => x)
10+
!ERROR: Variable 'z' in ASSOCIATE cannot be in a PRIVATE clause
11+
!$omp parallel private(z)
12+
!$omp end parallel
13+
end associate
14+
end subroutine
15+
16+
subroutine assoc_firstprivate(x)
17+
integer :: x
18+
associate(z => x)
19+
!ERROR: Variable 'z' in ASSOCIATE cannot be in a FIRSTPRIVATE clause
20+
!$omp parallel firstprivate(z)
21+
!$omp end parallel
22+
end associate
23+
end subroutine
24+
25+
subroutine assoc_lastprivate(x)
26+
integer :: x
27+
associate(z => x)
28+
!ERROR: Variable 'z' in ASSOCIATE cannot be in a LASTPRIVATE clause
29+
!$omp parallel sections lastprivate(z)
30+
!$omp end parallel sections
31+
end associate
32+
end subroutine

0 commit comments

Comments
 (0)