[flang-commits] [flang] ba789c6 - [Flang] Add semantics checks for CrayPointer usage in DSA list (#123171)
via flang-commits
flang-commits at lists.llvm.org
Mon Jan 27 18:57:46 PST 2025
Author: Thirumalai Shaktivel
Date: 2025-01-28T08:27:42+05:30
New Revision: ba789c6f82a911f90a5d20b637e02df4439d0153
URL: https://github.com/llvm/llvm-project/commit/ba789c6f82a911f90a5d20b637e02df4439d0153
DIFF: https://github.com/llvm/llvm-project/commit/ba789c6f82a911f90a5d20b637e02df4439d0153.diff
LOG: [Flang] Add semantics checks for CrayPointer usage in DSA list (#123171)
Follow-up PR to fix the failure caused here:
https://github.com/llvm/llvm-project/pull/121028
Failure:
https://lab.llvm.org/buildbot/#/builders/89/builds/14474
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.
Added:
flang/test/Semantics/OpenMP/cray-pointer-usage.f90
Modified:
flang/lib/Semantics/check-omp-structure.cpp
flang/lib/Semantics/check-omp-structure.h
flang/lib/Semantics/resolve-directives.cpp
Removed:
################################################################################
diff --git a/flang/lib/Semantics/check-omp-structure.cpp b/flang/lib/Semantics/check-omp-structure.cpp
index c7ad9cc085a213..00a031e0dcad79 100644
--- a/flang/lib/Semantics/check-omp-structure.cpp
+++ b/flang/lib/Semantics/check-omp-structure.cpp
@@ -3438,6 +3438,7 @@ void OmpStructureChecker::Enter(const parser::OmpClause::Ordered &x) {
void OmpStructureChecker::Enter(const parser::OmpClause::Shared &x) {
CheckAllowedClause(llvm::omp::Clause::OMPC_shared);
CheckIsVarPartOfAnotherVar(GetContext().clauseSource, x.v, "SHARED");
+ CheckCrayPointee(x.v, "SHARED");
}
void OmpStructureChecker::Enter(const parser::OmpClause::Private &x) {
SymbolSourceMap symbols;
@@ -3445,6 +3446,7 @@ void OmpStructureChecker::Enter(const parser::OmpClause::Private &x) {
CheckAllowedClause(llvm::omp::Clause::OMPC_private);
CheckIsVarPartOfAnotherVar(GetContext().clauseSource, x.v, "PRIVATE");
CheckIntentInPointer(symbols, llvm::omp::Clause::OMPC_private);
+ CheckCrayPointee(x.v, "PRIVATE");
}
void OmpStructureChecker::Enter(const parser::OmpClause::Nowait &x) {
@@ -3524,6 +3526,7 @@ void OmpStructureChecker::Enter(const parser::OmpClause::Firstprivate &x) {
CheckAllowedClause(llvm::omp::Clause::OMPC_firstprivate);
CheckIsVarPartOfAnotherVar(GetContext().clauseSource, x.v, "FIRSTPRIVATE");
+ CheckCrayPointee(x.v, "FIRSTPRIVATE");
CheckIsLoopIvPartOfClause(llvmOmpClause::OMPC_firstprivate, x.v);
SymbolSourceMap currSymbols;
@@ -3758,6 +3761,7 @@ void OmpStructureChecker::Enter(const parser::OmpClause::Linear &x) {
SymbolSourceMap symbols;
auto &objects{std::get<parser::OmpObjectList>(x.v.t)};
+ CheckCrayPointee(objects, "LINEAR", false);
GetSymbolsInObjectList(objects, symbols);
auto CheckIntegerNoRef{[&](const Symbol *symbol, parser::CharBlock source) {
@@ -4203,6 +4207,7 @@ void OmpStructureChecker::Enter(const parser::OmpClause::Lastprivate &x) {
const auto &objectList{std::get<parser::OmpObjectList>(x.v.t)};
CheckIsVarPartOfAnotherVar(
GetContext().clauseSource, objectList, "LASTPRIVATE");
+ CheckCrayPointee(objectList, "LASTPRIVATE");
DirectivesClauseTriple dirClauseTriple;
SymbolSourceMap currSymbols;
@@ -4620,6 +4625,26 @@ void OmpStructureChecker::CheckProcedurePointer(
}
}
+void OmpStructureChecker::CheckCrayPointee(
+ const parser::OmpObjectList &objectList, llvm::StringRef clause,
+ bool suggestToUseCrayPointer) {
+ SymbolSourceMap symbols;
+ GetSymbolsInObjectList(objectList, symbols);
+ for (auto it{symbols.begin()}; it != symbols.end(); ++it) {
+ const auto *symbol{it->first};
+ const auto source{it->second};
+ if (symbol->test(Symbol::Flag::CrayPointee)) {
+ std::string suggestionMsg = "";
+ if (suggestToUseCrayPointer)
+ suggestionMsg = ", use Cray Pointer '" +
+ semantics::GetCrayPointer(*symbol).name().ToString() + "' instead";
+ context_.Say(source,
+ "Cray Pointee '%s' may not appear in %s clause%s"_err_en_US,
+ symbol->name(), clause.str(), suggestionMsg);
+ }
+ }
+}
+
void OmpStructureChecker::GetSymbolsInObjectList(
const parser::OmpObjectList &objectList, SymbolSourceMap &symbols) {
for (const auto &ompObject : objectList.v) {
diff --git a/flang/lib/Semantics/check-omp-structure.h b/flang/lib/Semantics/check-omp-structure.h
index 2b8304cb170372..51be9ba5f76bc7 100644
--- a/flang/lib/Semantics/check-omp-structure.h
+++ b/flang/lib/Semantics/check-omp-structure.h
@@ -199,6 +199,8 @@ class OmpStructureChecker
const parser::CharBlock &source, const parser::OmpObjectList &objList);
void CheckIntentInPointer(SymbolSourceMap &, const llvm::omp::Clause);
void CheckProcedurePointer(SymbolSourceMap &, const llvm::omp::Clause);
+ void CheckCrayPointee(const parser::OmpObjectList &objectList,
+ llvm::StringRef clause, bool suggestToUseCrayPointer = true);
void GetSymbolsInObjectList(const parser::OmpObjectList &, SymbolSourceMap &);
void CheckDefinableObjects(SymbolSourceMap &, const llvm::omp::Clause);
void CheckCopyingPolymorphicAllocatable(
diff --git a/flang/lib/Semantics/resolve-directives.cpp b/flang/lib/Semantics/resolve-directives.cpp
index 4e6d819f545a2d..2bd70d7d2b9358 100644
--- a/flang/lib/Semantics/resolve-directives.cpp
+++ b/flang/lib/Semantics/resolve-directives.cpp
@@ -2105,8 +2105,11 @@ void OmpAttributeVisitor::Post(const parser::OpenMPAllocatorsConstruct &x) {
static bool IsPrivatizable(const Symbol *sym) {
auto *misc{sym->detailsIf<MiscDetails>()};
return IsVariableName(*sym) && !IsProcedure(*sym) && !IsNamedConstant(*sym) &&
- !semantics::IsAssumedSizeArray(
- *sym) && /* OpenMP 5.2, 5.1.1: Assumed-size arrays are shared*/
+ ( // OpenMP 5.2, 5.1.1: Assumed-size arrays are shared
+ !semantics::IsAssumedSizeArray(*sym) ||
+ // If CrayPointer is among the DSA list then the
+ // CrayPointee is Privatizable
+ sym->test(Symbol::Flag::CrayPointee)) &&
!sym->owner().IsDerivedType() &&
sym->owner().kind() != Scope::Kind::ImpliedDos &&
sym->owner().kind() != Scope::Kind::Forall &&
@@ -2273,10 +2276,18 @@ void OmpAttributeVisitor::Post(const parser::Name &name) {
// the scope of the parallel region, and not in this scope.
// TODO: check whether this should be caught in IsObjectWithDSA
!symbol->test(Symbol::Flag::OmpPrivate)) {
- context_.Say(name.source,
- "The DEFAULT(NONE) clause requires that '%s' must be listed in "
- "a data-sharing attribute clause"_err_en_US,
- symbol->name());
+ if (symbol->test(Symbol::Flag::CrayPointee)) {
+ std::string crayPtrName{
+ semantics::GetCrayPointer(*symbol).name().ToString()};
+ if (!IsObjectWithDSA(*currScope().FindSymbol(crayPtrName)))
+ context_.Say(name.source,
+ "The DEFAULT(NONE) clause requires that the Cray Pointer '%s' must be listed in a data-sharing attribute clause"_err_en_US,
+ crayPtrName);
+ } else {
+ context_.Say(name.source,
+ "The DEFAULT(NONE) clause requires that '%s' must be listed in a data-sharing attribute clause"_err_en_US,
+ symbol->name());
+ }
}
}
}
diff --git a/flang/test/Semantics/OpenMP/cray-pointer-usage.f90 b/flang/test/Semantics/OpenMP/cray-pointer-usage.f90
new file mode 100644
index 00000000000000..6c74462dd27896
--- /dev/null
+++ b/flang/test/Semantics/OpenMP/cray-pointer-usage.f90
@@ -0,0 +1,44 @@
+!RUN: %python %S/../test_errors.py %s %flang -fopenmp
+subroutine test_cray_pointer_usage
+ implicit none
+ integer :: i
+ real(8) :: var(*), pointee(2)
+ pointer(ivar, var)
+ ! ERROR: Cray Pointee 'var' may not appear in LINEAR clause
+ ! ERROR: The list item 'var' specified without the REF 'linear-modifier' must be of INTEGER type
+ ! ERROR: The list item `var` must be a dummy argument
+ !$omp declare simd linear(var)
+
+ pointee = 42.0
+ ivar = loc(pointee)
+
+ !$omp parallel num_threads(2) default(none)
+ ! ERROR: The DEFAULT(NONE) clause requires that the Cray Pointer 'ivar' must be listed in a data-sharing attribute clause
+ print *, var(1)
+ !$omp end parallel
+
+ ! ERROR: Cray Pointee 'var' may not appear in PRIVATE clause, use Cray Pointer 'ivar' instead
+ !$omp parallel num_threads(2) default(none) private(var)
+ print *, var(1)
+ !$omp end parallel
+
+ ! ERROR: Cray Pointee 'var' may not appear in SHARED clause, use Cray Pointer 'ivar' instead
+ !$omp parallel num_threads(2) default(none) shared(var)
+ print *, var(1)
+ !$omp end parallel
+
+ ! ERROR: Cray Pointee 'var' may not appear in LASTPRIVATE clause, use Cray Pointer 'ivar' instead
+ !$omp do lastprivate(var)
+ do i = 1, 10
+ print *, var(1)
+ end do
+ !$omp end do
+
+ !$omp parallel num_threads(2) default(none) firstprivate(ivar)
+ print *, var(1)
+ !$omp end parallel
+
+ !$omp parallel num_threads(2) default(private) shared(ivar)
+ print *, var(1)
+ !$omp end parallel
+end subroutine test_cray_pointer_usage
More information about the flang-commits
mailing list