Skip to content

[Flang][OpenMP][taskloop] Adding missing semantic checks in Taskloop #128431

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 31 additions & 4 deletions flang/lib/Semantics/check-omp-structure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3369,13 +3369,18 @@ void OmpStructureChecker::CheckReductionModifier(
return;
}
const DirectiveContext &dirCtx{GetContext()};
if (dirCtx.directive == llvm::omp::Directive::OMPD_loop) {
if (dirCtx.directive == llvm::omp::Directive::OMPD_loop ||
dirCtx.directive == llvm::omp::Directive::OMPD_taskloop) {
// [5.2:257:33-34]
// If a reduction-modifier is specified in a reduction clause that
// appears on the directive, then the reduction modifier must be
// default.
// [5.2:268:16]
// The reduction-modifier must be default.
context_.Say(GetContext().clauseSource,
"REDUCTION modifier on LOOP directive must be DEFAULT"_err_en_US);
"REDUCTION modifier on %s directive must be DEFAULT"_err_en_US,
parser::ToUpperCaseLetters(GetContext().directiveSource.ToString()));
return;
}
if (modifier.v == ReductionModifier::Value::Task) {
// "Task" is only allowed on worksharing or "parallel" directive.
Expand Down Expand Up @@ -4274,8 +4279,30 @@ void OmpStructureChecker::Enter(const parser::OmpClause::Lastprivate &x) {
CheckPrivateSymbolsInOuterCxt(
currSymbols, dirClauseTriple, llvm::omp::Clause::OMPC_lastprivate);

OmpVerifyModifiers(
x.v, llvm::omp::OMPC_lastprivate, GetContext().clauseSource, context_);
if (OmpVerifyModifiers(x.v, llvm::omp::OMPC_lastprivate,
GetContext().clauseSource, context_)) {
auto &modifiers{OmpGetModifiers(x.v)};
using LastprivateModifier = parser::OmpLastprivateModifier;
if (auto *modifier{OmpGetUniqueModifier<LastprivateModifier>(modifiers)}) {
CheckLastprivateModifier(*modifier);
}
}
}

// Add any restrictions related to Modifiers/Directives with
// Lastprivate clause here:
void OmpStructureChecker::CheckLastprivateModifier(
const parser::OmpLastprivateModifier &modifier) {
using LastprivateModifier = parser::OmpLastprivateModifier;
const DirectiveContext &dirCtx{GetContext()};
if (modifier.v == LastprivateModifier::Value::Conditional &&
dirCtx.directive == llvm::omp::Directive::OMPD_taskloop) {
// [5.2:268:17]
// The conditional lastprivate-modifier must not be specified.
context_.Say(GetContext().clauseSource,
"'CONDITIONAL' modifier on lastprivate clause with TASKLOOP "
"directive is not allowed"_err_en_US);
}
}

void OmpStructureChecker::Enter(const parser::OmpClause::Copyin &x) {
Expand Down
1 change: 1 addition & 0 deletions flang/lib/Semantics/check-omp-structure.h
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ class OmpStructureChecker
void CheckReductionObjectTypes(const parser::OmpObjectList &objects,
const parser::OmpReductionIdentifier &ident);
void CheckReductionModifier(const parser::OmpReductionModifier &);
void CheckLastprivateModifier(const parser::OmpLastprivateModifier &);
void CheckMasterNesting(const parser::OpenMPBlockConstruct &x);
void ChecksOnOrderedAsBlock();
void CheckBarrierNesting(const parser::OpenMPSimpleStandaloneConstruct &x);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
!RUN: %python %S/../test_errors.py %s %flang -fopenmp -fopenmp-version=52

subroutine foo()
integer :: x, i
x = 1
!ERROR: 'CONDITIONAL' modifier on lastprivate clause with TASKLOOP directive is not allowed
!$omp taskloop lastprivate(conditional: x)
do i = 1, 100
x = x + 1
enddo
!$omp end taskloop
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
!RUN: %python %S/../test_errors.py %s %flang -fopenmp -fopenmp-version=52

subroutine bar()
integer :: x, i
x = 1
!ERROR: REDUCTION modifier on TASKLOOP directive must be DEFAULT
!ERROR: List item x must appear in EXCLUSIVE or INCLUSIVE clause of an enclosed SCAN directive
!$omp taskloop reduction(inscan, +:x)
do i = 1, 100
x = x + 1
enddo
!$omp end taskloop
end

subroutine baz()
integer :: x, i
x = 1
!ERROR: REDUCTION modifier on TASKLOOP directive must be DEFAULT
!$omp taskloop reduction(task, +:x)
do i = 1, 100
x = x + 1
enddo
!$omp end taskloop
end