[llvm-branch-commits] [flang] [flang][OpenMP] Semantic checks for DYN_GROUPPRIVATE (PR #166214)
Krzysztof Parzyszek via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Tue Nov 11 05:01:00 PST 2025
https://github.com/kparzysz updated https://github.com/llvm/llvm-project/pull/166214
>From ebe00ba9ee15119b2ce127971ab4e038ddf62308 Mon Sep 17 00:00:00 2001
From: Krzysztof Parzyszek <Krzysztof.Parzyszek at amd.com>
Date: Thu, 14 Aug 2025 13:26:23 -0500
Subject: [PATCH] [flang][OpenMP] Semantic checks for DYN_GROUPPRIVATE
---
.../flang/Semantics/openmp-modifiers.h | 2 ++
flang/lib/Semantics/check-omp-structure.cpp | 34 ++++++++++++++++++-
flang/lib/Semantics/openmp-modifiers.cpp | 32 +++++++++++++++++
.../Semantics/OpenMP/dyn-groupprivate.f90 | 8 +++++
4 files changed, 75 insertions(+), 1 deletion(-)
create mode 100644 flang/test/Semantics/OpenMP/dyn-groupprivate.f90
diff --git a/flang/include/flang/Semantics/openmp-modifiers.h b/flang/include/flang/Semantics/openmp-modifiers.h
index bfa3aa4939cb1..283bf2a4c895e 100644
--- a/flang/include/flang/Semantics/openmp-modifiers.h
+++ b/flang/include/flang/Semantics/openmp-modifiers.h
@@ -67,6 +67,7 @@ template <typename SpecificTy> const OmpModifierDescriptor &OmpGetDescriptor();
#define DECLARE_DESCRIPTOR(name) \
template <> const OmpModifierDescriptor &OmpGetDescriptor<name>()
+DECLARE_DESCRIPTOR(parser::OmpAccessGroup);
DECLARE_DESCRIPTOR(parser::OmpAlignment);
DECLARE_DESCRIPTOR(parser::OmpAlignModifier);
DECLARE_DESCRIPTOR(parser::OmpAllocatorComplexModifier);
@@ -82,6 +83,7 @@ DECLARE_DESCRIPTOR(parser::OmpDependenceType);
DECLARE_DESCRIPTOR(parser::OmpDeviceModifier);
DECLARE_DESCRIPTOR(parser::OmpDirectiveNameModifier);
DECLARE_DESCRIPTOR(parser::OmpExpectation);
+DECLARE_DESCRIPTOR(parser::OmpFallbackModifier);
DECLARE_DESCRIPTOR(parser::OmpInteropPreference);
DECLARE_DESCRIPTOR(parser::OmpInteropType);
DECLARE_DESCRIPTOR(parser::OmpIterator);
diff --git a/flang/lib/Semantics/check-omp-structure.cpp b/flang/lib/Semantics/check-omp-structure.cpp
index d7db15dd37949..4c46aba7391d6 100644
--- a/flang/lib/Semantics/check-omp-structure.cpp
+++ b/flang/lib/Semantics/check-omp-structure.cpp
@@ -682,6 +682,13 @@ void OmpStructureChecker::Enter(const parser::OmpClause::Hint &x) {
}
}
+void OmpStructureChecker::Enter(const parser::OmpClause::DynGroupprivate &x) {
+ CheckAllowedClause(llvm::omp::Clause::OMPC_dyn_groupprivate);
+ parser::CharBlock source{GetContext().clauseSource};
+
+ OmpVerifyModifiers(x.v, llvm::omp::OMPC_dyn_groupprivate, source, context_);
+}
+
void OmpStructureChecker::Enter(const parser::OmpDirectiveSpecification &x) {
// OmpDirectiveSpecification exists on its own only in METADIRECTIVE.
// In other cases it's a part of other constructs that handle directive
@@ -3316,6 +3323,32 @@ void OmpStructureChecker::Leave(const parser::OmpClauseList &) {
}
}
+ // Default access-group for DYN_GROUPPRIVATE is "cgroup". On a given
+ // construct there can be at most one DYN_GROUPPRIVATE with a given
+ // access-group.
+ const parser::OmpClause
+ *accGrpClause[parser::OmpAccessGroup::Value_enumSize] = {nullptr};
+ for (auto [_, clause] :
+ FindClauses(llvm::omp::Clause::OMPC_dyn_groupprivate)) {
+ auto &wrapper{std::get<parser::OmpClause::DynGroupprivate>(clause->u)};
+ auto &modifiers{OmpGetModifiers(wrapper.v)};
+ auto accGrp{parser::OmpAccessGroup::Value::Cgroup};
+ if (auto *ag{OmpGetUniqueModifier<parser::OmpAccessGroup>(modifiers)}) {
+ accGrp = ag->v;
+ }
+ auto &firstClause{accGrpClause[llvm::to_underlying(accGrp)]};
+ if (firstClause) {
+ context_
+ .Say(clause->source,
+ "The access-group modifier can only occur on a single clause in a construct"_err_en_US)
+ .Attach(firstClause->source,
+ "Previous clause with access-group modifier"_en_US);
+ break;
+ } else {
+ firstClause = clause;
+ }
+ }
+
CheckRequireAtLeastOneOf();
}
@@ -5472,7 +5505,6 @@ CHECK_SIMPLE_CLAUSE(Default, OMPC_default)
CHECK_SIMPLE_CLAUSE(Depobj, OMPC_depobj)
CHECK_SIMPLE_CLAUSE(DeviceType, OMPC_device_type)
CHECK_SIMPLE_CLAUSE(DistSchedule, OMPC_dist_schedule)
-CHECK_SIMPLE_CLAUSE(DynGroupprivate, OMPC_dyn_groupprivate)
CHECK_SIMPLE_CLAUSE(Exclusive, OMPC_exclusive)
CHECK_SIMPLE_CLAUSE(Fail, OMPC_fail)
CHECK_SIMPLE_CLAUSE(Filter, OMPC_filter)
diff --git a/flang/lib/Semantics/openmp-modifiers.cpp b/flang/lib/Semantics/openmp-modifiers.cpp
index 717fb0351ba5b..f191b4de2d579 100644
--- a/flang/lib/Semantics/openmp-modifiers.cpp
+++ b/flang/lib/Semantics/openmp-modifiers.cpp
@@ -74,6 +74,22 @@ unsigned OmpModifierDescriptor::since(llvm::omp::Clause id) const {
// Note: The intent for these functions is to have them be automatically-
// generated in the future.
+template <>
+const OmpModifierDescriptor &OmpGetDescriptor<parser::OmpAccessGroup>() {
+ static const OmpModifierDescriptor desc{
+ /*name=*/"access-group",
+ /*props=*/
+ {
+ {61, {OmpProperty::Unique}},
+ },
+ /*clauses=*/
+ {
+ {61, {Clause::OMPC_dyn_groupprivate}},
+ },
+ };
+ return desc;
+}
+
template <>
const OmpModifierDescriptor &OmpGetDescriptor<parser::OmpAlignment>() {
static const OmpModifierDescriptor desc{
@@ -321,6 +337,22 @@ const OmpModifierDescriptor &OmpGetDescriptor<parser::OmpExpectation>() {
return desc;
}
+template <>
+const OmpModifierDescriptor &OmpGetDescriptor<parser::OmpFallbackModifier>() {
+ static const OmpModifierDescriptor desc{
+ /*name=*/"fallback-modifier",
+ /*props=*/
+ {
+ {61, {OmpProperty::Unique}},
+ },
+ /*clauses=*/
+ {
+ {61, {Clause::OMPC_dyn_groupprivate}},
+ },
+ };
+ return desc;
+}
+
template <>
const OmpModifierDescriptor &OmpGetDescriptor<parser::OmpInteropPreference>() {
static const OmpModifierDescriptor desc{
diff --git a/flang/test/Semantics/OpenMP/dyn-groupprivate.f90 b/flang/test/Semantics/OpenMP/dyn-groupprivate.f90
new file mode 100644
index 0000000000000..f77a0b0d35f44
--- /dev/null
+++ b/flang/test/Semantics/OpenMP/dyn-groupprivate.f90
@@ -0,0 +1,8 @@
+!RUN: %python %S/../test_errors.py %s %flang -fopenmp -fopenmp-version=61
+
+subroutine f00(x)
+ integer :: x
+ !ERROR: The access-group modifier can only occur on a single clause in a construct
+ !$omp target dyn_groupprivate(cgroup: x), dyn_groupprivate(10)
+ !$omp end target
+end
More information about the llvm-branch-commits
mailing list