Skip to content

Commit c1fa630

Browse files
[Flang OpenMP] Add semantics checks for cray pointer usage in DSA list
Problems: - Cray pointee cannot be used in the DSA list - Cray pointer has to be in DSA list when cray pointee is used in the default (none) region Fix: Added required semantic checks along the tests
1 parent c2bd5c2 commit c1fa630

File tree

4 files changed

+66
-6
lines changed

4 files changed

+66
-6
lines changed

flang/lib/Semantics/check-omp-structure.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3340,13 +3340,15 @@ void OmpStructureChecker::Enter(const parser::OmpClause::Ordered &x) {
33403340
void OmpStructureChecker::Enter(const parser::OmpClause::Shared &x) {
33413341
CheckAllowedClause(llvm::omp::Clause::OMPC_shared);
33423342
CheckIsVarPartOfAnotherVar(GetContext().clauseSource, x.v, "SHARED");
3343+
CheckCrayPointee(x.v, "SHARED");
33433344
}
33443345
void OmpStructureChecker::Enter(const parser::OmpClause::Private &x) {
33453346
SymbolSourceMap symbols;
33463347
GetSymbolsInObjectList(x.v, symbols);
33473348
CheckAllowedClause(llvm::omp::Clause::OMPC_private);
33483349
CheckIsVarPartOfAnotherVar(GetContext().clauseSource, x.v, "PRIVATE");
33493350
CheckIntentInPointer(symbols, llvm::omp::Clause::OMPC_private);
3351+
CheckCrayPointee(x.v, "PRIVATE");
33503352
}
33513353

33523354
void OmpStructureChecker::Enter(const parser::OmpClause::Nowait &x) {
@@ -3426,6 +3428,7 @@ void OmpStructureChecker::Enter(const parser::OmpClause::Firstprivate &x) {
34263428
CheckAllowedClause(llvm::omp::Clause::OMPC_firstprivate);
34273429

34283430
CheckIsVarPartOfAnotherVar(GetContext().clauseSource, x.v, "FIRSTPRIVATE");
3431+
CheckCrayPointee(x.v, "FIRSTPRIVATE");
34293432
CheckIsLoopIvPartOfClause(llvmOmpClause::OMPC_firstprivate, x.v);
34303433

34313434
SymbolSourceMap currSymbols;
@@ -4522,6 +4525,22 @@ void OmpStructureChecker::CheckProcedurePointer(
45224525
}
45234526
}
45244527

4528+
void OmpStructureChecker::CheckCrayPointee(
4529+
const parser::OmpObjectList &objectList, llvm::StringRef clause) {
4530+
SymbolSourceMap symbols;
4531+
GetSymbolsInObjectList(objectList, symbols);
4532+
for (auto it{symbols.begin()}; it != symbols.end(); ++it) {
4533+
const auto *symbol{it->first};
4534+
const auto source{it->second};
4535+
if (symbol->test(Symbol::Flag::CrayPointee)) {
4536+
context_.Say(source,
4537+
"Cray Pointee '%s' may not appear in %s clause, use Cray Pointer '%s' instead"_err_en_US,
4538+
symbol->name(), clause.str(),
4539+
semantics::GetCrayPointer(*symbol).name());
4540+
}
4541+
}
4542+
}
4543+
45254544
void OmpStructureChecker::GetSymbolsInObjectList(
45264545
const parser::OmpObjectList &objectList, SymbolSourceMap &symbols) {
45274546
for (const auto &ompObject : objectList.v) {

flang/lib/Semantics/check-omp-structure.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,8 @@ class OmpStructureChecker
194194
const parser::CharBlock &source, const parser::OmpObjectList &objList);
195195
void CheckIntentInPointer(SymbolSourceMap &, const llvm::omp::Clause);
196196
void CheckProcedurePointer(SymbolSourceMap &, const llvm::omp::Clause);
197+
void CheckCrayPointee(
198+
const parser::OmpObjectList &objectList, llvm::StringRef clause);
197199
void GetSymbolsInObjectList(const parser::OmpObjectList &, SymbolSourceMap &);
198200
void CheckDefinableObjects(SymbolSourceMap &, const llvm::omp::Clause);
199201
void CheckCopyingPolymorphicAllocatable(

flang/lib/Semantics/resolve-directives.cpp

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2115,8 +2115,12 @@ void OmpAttributeVisitor::Post(const parser::OpenMPAllocatorsConstruct &x) {
21152115
static bool IsPrivatizable(const Symbol *sym) {
21162116
auto *misc{sym->detailsIf<MiscDetails>()};
21172117
return IsVariableName(*sym) && !IsProcedure(*sym) && !IsNamedConstant(*sym) &&
2118-
!semantics::IsAssumedSizeArray(
2119-
*sym) && /* OpenMP 5.2, 5.1.1: Assumed-size arrays are shared*/
2118+
(!semantics::IsAssumedSizeArray(
2119+
*sym) || /* OpenMP 5.2, 5.1.1: Assumed-size arrays are shared*/
2120+
(sym->test(Symbol::Flag::CrayPointee) &&
2121+
// If CrayPointer is among the DSA list then the
2122+
// CrayPointee is Privatizable
2123+
&semantics::GetCrayPointer(*sym))) &&
21202124
!sym->owner().IsDerivedType() &&
21212125
sym->owner().kind() != Scope::Kind::ImpliedDos &&
21222126
!sym->detailsIf<semantics::AssocEntityDetails>() &&
@@ -2282,10 +2286,18 @@ void OmpAttributeVisitor::Post(const parser::Name &name) {
22822286
// the scope of the parallel region, and not in this scope.
22832287
// TODO: check whether this should be caught in IsObjectWithDSA
22842288
!symbol->test(Symbol::Flag::OmpPrivate)) {
2285-
context_.Say(name.source,
2286-
"The DEFAULT(NONE) clause requires that '%s' must be listed in "
2287-
"a data-sharing attribute clause"_err_en_US,
2288-
symbol->name());
2289+
if (symbol->test(Symbol::Flag::CrayPointee)) {
2290+
std::string crayPtrName{
2291+
semantics::GetCrayPointer(*symbol).name().ToString()};
2292+
if (!IsObjectWithDSA(*currScope().FindSymbol(crayPtrName)))
2293+
context_.Say(name.source,
2294+
"The DEFAULT(NONE) clause requires that the Cray Pointer '%s' must be listed in a data-sharing attribute clause"_err_en_US,
2295+
crayPtrName);
2296+
} else {
2297+
context_.Say(name.source,
2298+
"The DEFAULT(NONE) clause requires that '%s' must be listed in a data-sharing attribute clause"_err_en_US,
2299+
symbol->name());
2300+
}
22892301
}
22902302
}
22912303
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
!RUN: %python %S/../test_errors.py %s %flang -fopenmp
2+
subroutine test_cray_pointer_usage
3+
implicit none
4+
real(8) :: var(*), pointee(2)
5+
pointer(ivar, var)
6+
7+
pointee = 42.0
8+
ivar = loc(pointee)
9+
10+
!$omp parallel num_threads(2) default(none)
11+
! ERROR: The DEFAULT(NONE) clause requires that the Cray Pointer 'ivar' must be listed in a data-sharing attribute clause
12+
print *, var(1)
13+
!$omp end parallel
14+
15+
! ERROR: Cray Pointee 'var' may not appear in PRIVATE clause, use Cray Pointer 'ivar' instead
16+
!$omp parallel num_threads(2) default(none) private(var)
17+
print *, var(1)
18+
!$omp end parallel
19+
20+
!$omp parallel num_threads(2) default(none) firstprivate(ivar)
21+
print *, var(1)
22+
!$omp end parallel
23+
24+
!$omp parallel num_threads(2) default(private) shared(ivar)
25+
print *, var(1)
26+
!$omp end parallel
27+
end subroutine test_cray_pointer_usage

0 commit comments

Comments
 (0)