Skip to content

Commit 990774a

Browse files
[Flang] Add semantic checks for cray pointer usage in DSA list (#121028)
Problems: - Cray pointee cannot be used in the DSA list (If used results in segmentation fault) - Cray pointer has to be in the DSA list when Cray pointee is used in the default (none) region Fix: Added required semantic checks along the tests Reference from the documentation (OpenMP 5.0: 2.19.1): - Cray pointees have the same data-sharing attribute as the storage with which their Cray pointers are associated.
1 parent f30ff0b commit 990774a

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
@@ -3374,13 +3374,15 @@ void OmpStructureChecker::Enter(const parser::OmpClause::Ordered &x) {
33743374
void OmpStructureChecker::Enter(const parser::OmpClause::Shared &x) {
33753375
CheckAllowedClause(llvm::omp::Clause::OMPC_shared);
33763376
CheckIsVarPartOfAnotherVar(GetContext().clauseSource, x.v, "SHARED");
3377+
CheckCrayPointee(x.v, "SHARED");
33773378
}
33783379
void OmpStructureChecker::Enter(const parser::OmpClause::Private &x) {
33793380
SymbolSourceMap symbols;
33803381
GetSymbolsInObjectList(x.v, symbols);
33813382
CheckAllowedClause(llvm::omp::Clause::OMPC_private);
33823383
CheckIsVarPartOfAnotherVar(GetContext().clauseSource, x.v, "PRIVATE");
33833384
CheckIntentInPointer(symbols, llvm::omp::Clause::OMPC_private);
3385+
CheckCrayPointee(x.v, "PRIVATE");
33843386
}
33853387

33863388
void OmpStructureChecker::Enter(const parser::OmpClause::Nowait &x) {
@@ -3460,6 +3462,7 @@ void OmpStructureChecker::Enter(const parser::OmpClause::Firstprivate &x) {
34603462
CheckAllowedClause(llvm::omp::Clause::OMPC_firstprivate);
34613463

34623464
CheckIsVarPartOfAnotherVar(GetContext().clauseSource, x.v, "FIRSTPRIVATE");
3465+
CheckCrayPointee(x.v, "FIRSTPRIVATE");
34633466
CheckIsLoopIvPartOfClause(llvmOmpClause::OMPC_firstprivate, x.v);
34643467

34653468
SymbolSourceMap currSymbols;
@@ -4556,6 +4559,22 @@ void OmpStructureChecker::CheckProcedurePointer(
45564559
}
45574560
}
45584561

4562+
void OmpStructureChecker::CheckCrayPointee(
4563+
const parser::OmpObjectList &objectList, llvm::StringRef clause) {
4564+
SymbolSourceMap symbols;
4565+
GetSymbolsInObjectList(objectList, symbols);
4566+
for (auto it{symbols.begin()}; it != symbols.end(); ++it) {
4567+
const auto *symbol{it->first};
4568+
const auto source{it->second};
4569+
if (symbol->test(Symbol::Flag::CrayPointee)) {
4570+
context_.Say(source,
4571+
"Cray Pointee '%s' may not appear in %s clause, use Cray Pointer '%s' instead"_err_en_US,
4572+
symbol->name(), clause.str(),
4573+
semantics::GetCrayPointer(*symbol).name());
4574+
}
4575+
}
4576+
}
4577+
45594578
void OmpStructureChecker::GetSymbolsInObjectList(
45604579
const parser::OmpObjectList &objectList, SymbolSourceMap &symbols) {
45614580
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
@@ -197,6 +197,8 @@ class OmpStructureChecker
197197
const parser::CharBlock &source, const parser::OmpObjectList &objList);
198198
void CheckIntentInPointer(SymbolSourceMap &, const llvm::omp::Clause);
199199
void CheckProcedurePointer(SymbolSourceMap &, const llvm::omp::Clause);
200+
void CheckCrayPointee(
201+
const parser::OmpObjectList &objectList, llvm::StringRef clause);
200202
void GetSymbolsInObjectList(const parser::OmpObjectList &, SymbolSourceMap &);
201203
void CheckDefinableObjects(SymbolSourceMap &, const llvm::omp::Clause);
202204
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)