Skip to content

Commit 17e67b0

Browse files
authored
[flang][OpenMP] Semantic checks for DYN_GROUPPRIVATE (#166214)
1 parent 5d062bf commit 17e67b0

File tree

4 files changed

+75
-1
lines changed

4 files changed

+75
-1
lines changed

flang/include/flang/Semantics/openmp-modifiers.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ template <typename SpecificTy> const OmpModifierDescriptor &OmpGetDescriptor();
6767
#define DECLARE_DESCRIPTOR(name) \
6868
template <> const OmpModifierDescriptor &OmpGetDescriptor<name>()
6969

70+
DECLARE_DESCRIPTOR(parser::OmpAccessGroup);
7071
DECLARE_DESCRIPTOR(parser::OmpAlignment);
7172
DECLARE_DESCRIPTOR(parser::OmpAlignModifier);
7273
DECLARE_DESCRIPTOR(parser::OmpAllocatorComplexModifier);
@@ -82,6 +83,7 @@ DECLARE_DESCRIPTOR(parser::OmpDependenceType);
8283
DECLARE_DESCRIPTOR(parser::OmpDeviceModifier);
8384
DECLARE_DESCRIPTOR(parser::OmpDirectiveNameModifier);
8485
DECLARE_DESCRIPTOR(parser::OmpExpectation);
86+
DECLARE_DESCRIPTOR(parser::OmpFallbackModifier);
8587
DECLARE_DESCRIPTOR(parser::OmpInteropPreference);
8688
DECLARE_DESCRIPTOR(parser::OmpInteropType);
8789
DECLARE_DESCRIPTOR(parser::OmpIterator);

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

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -682,6 +682,13 @@ void OmpStructureChecker::Enter(const parser::OmpClause::Hint &x) {
682682
}
683683
}
684684

685+
void OmpStructureChecker::Enter(const parser::OmpClause::DynGroupprivate &x) {
686+
CheckAllowedClause(llvm::omp::Clause::OMPC_dyn_groupprivate);
687+
parser::CharBlock source{GetContext().clauseSource};
688+
689+
OmpVerifyModifiers(x.v, llvm::omp::OMPC_dyn_groupprivate, source, context_);
690+
}
691+
685692
void OmpStructureChecker::Enter(const parser::OmpDirectiveSpecification &x) {
686693
// OmpDirectiveSpecification exists on its own only in METADIRECTIVE.
687694
// In other cases it's a part of other constructs that handle directive
@@ -3316,6 +3323,32 @@ void OmpStructureChecker::Leave(const parser::OmpClauseList &) {
33163323
}
33173324
}
33183325

3326+
// Default access-group for DYN_GROUPPRIVATE is "cgroup". On a given
3327+
// construct there can be at most one DYN_GROUPPRIVATE with a given
3328+
// access-group.
3329+
const parser::OmpClause
3330+
*accGrpClause[parser::OmpAccessGroup::Value_enumSize] = {nullptr};
3331+
for (auto [_, clause] :
3332+
FindClauses(llvm::omp::Clause::OMPC_dyn_groupprivate)) {
3333+
auto &wrapper{std::get<parser::OmpClause::DynGroupprivate>(clause->u)};
3334+
auto &modifiers{OmpGetModifiers(wrapper.v)};
3335+
auto accGrp{parser::OmpAccessGroup::Value::Cgroup};
3336+
if (auto *ag{OmpGetUniqueModifier<parser::OmpAccessGroup>(modifiers)}) {
3337+
accGrp = ag->v;
3338+
}
3339+
auto &firstClause{accGrpClause[llvm::to_underlying(accGrp)]};
3340+
if (firstClause) {
3341+
context_
3342+
.Say(clause->source,
3343+
"The access-group modifier can only occur on a single clause in a construct"_err_en_US)
3344+
.Attach(firstClause->source,
3345+
"Previous clause with access-group modifier"_en_US);
3346+
break;
3347+
} else {
3348+
firstClause = clause;
3349+
}
3350+
}
3351+
33193352
CheckRequireAtLeastOneOf();
33203353
}
33213354

@@ -5475,7 +5508,6 @@ CHECK_SIMPLE_CLAUSE(Default, OMPC_default)
54755508
CHECK_SIMPLE_CLAUSE(Depobj, OMPC_depobj)
54765509
CHECK_SIMPLE_CLAUSE(DeviceType, OMPC_device_type)
54775510
CHECK_SIMPLE_CLAUSE(DistSchedule, OMPC_dist_schedule)
5478-
CHECK_SIMPLE_CLAUSE(DynGroupprivate, OMPC_dyn_groupprivate)
54795511
CHECK_SIMPLE_CLAUSE(Exclusive, OMPC_exclusive)
54805512
CHECK_SIMPLE_CLAUSE(Fail, OMPC_fail)
54815513
CHECK_SIMPLE_CLAUSE(Filter, OMPC_filter)

flang/lib/Semantics/openmp-modifiers.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,22 @@ unsigned OmpModifierDescriptor::since(llvm::omp::Clause id) const {
7474
// Note: The intent for these functions is to have them be automatically-
7575
// generated in the future.
7676

77+
template <>
78+
const OmpModifierDescriptor &OmpGetDescriptor<parser::OmpAccessGroup>() {
79+
static const OmpModifierDescriptor desc{
80+
/*name=*/"access-group",
81+
/*props=*/
82+
{
83+
{61, {OmpProperty::Unique}},
84+
},
85+
/*clauses=*/
86+
{
87+
{61, {Clause::OMPC_dyn_groupprivate}},
88+
},
89+
};
90+
return desc;
91+
}
92+
7793
template <>
7894
const OmpModifierDescriptor &OmpGetDescriptor<parser::OmpAlignment>() {
7995
static const OmpModifierDescriptor desc{
@@ -321,6 +337,22 @@ const OmpModifierDescriptor &OmpGetDescriptor<parser::OmpExpectation>() {
321337
return desc;
322338
}
323339

340+
template <>
341+
const OmpModifierDescriptor &OmpGetDescriptor<parser::OmpFallbackModifier>() {
342+
static const OmpModifierDescriptor desc{
343+
/*name=*/"fallback-modifier",
344+
/*props=*/
345+
{
346+
{61, {OmpProperty::Unique}},
347+
},
348+
/*clauses=*/
349+
{
350+
{61, {Clause::OMPC_dyn_groupprivate}},
351+
},
352+
};
353+
return desc;
354+
}
355+
324356
template <>
325357
const OmpModifierDescriptor &OmpGetDescriptor<parser::OmpInteropPreference>() {
326358
static const OmpModifierDescriptor desc{
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
!RUN: %python %S/../test_errors.py %s %flang -fopenmp -fopenmp-version=61
2+
3+
subroutine f00(x)
4+
integer :: x
5+
!ERROR: The access-group modifier can only occur on a single clause in a construct
6+
!$omp target dyn_groupprivate(cgroup: x), dyn_groupprivate(10)
7+
!$omp end target
8+
end

0 commit comments

Comments
 (0)