Skip to content

Commit 7eb8b73

Browse files
[Flang][OpenMP][taskloop] Adding missing semantic checks in Taskloop (#128431)
Below semantic checks for Taskloop clause mentioned in OpenMP [5.2] specification were missing, this patch contains the semantic checks, corresponding error messages and test cases: OpenMP standard [5.2]: [12.6] Taskloop Construct [Restrictions] Restrictions to the taskloop construct are as follows: • The reduction-modifier must be default. • The conditional lastprivate-modifier must not be specified. Authored-by: shkaushi <[email protected]>
1 parent 78408fd commit 7eb8b73

File tree

4 files changed

+68
-4
lines changed

4 files changed

+68
-4
lines changed

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

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3538,13 +3538,18 @@ void OmpStructureChecker::CheckReductionModifier(
35383538
return;
35393539
}
35403540
const DirectiveContext &dirCtx{GetContext()};
3541-
if (dirCtx.directive == llvm::omp::Directive::OMPD_loop) {
3541+
if (dirCtx.directive == llvm::omp::Directive::OMPD_loop ||
3542+
dirCtx.directive == llvm::omp::Directive::OMPD_taskloop) {
35423543
// [5.2:257:33-34]
35433544
// If a reduction-modifier is specified in a reduction clause that
35443545
// appears on the directive, then the reduction modifier must be
35453546
// default.
3547+
// [5.2:268:16]
3548+
// The reduction-modifier must be default.
35463549
context_.Say(GetContext().clauseSource,
3547-
"REDUCTION modifier on LOOP directive must be DEFAULT"_err_en_US);
3550+
"REDUCTION modifier on %s directive must be DEFAULT"_err_en_US,
3551+
parser::ToUpperCaseLetters(GetContext().directiveSource.ToString()));
3552+
return;
35483553
}
35493554
if (modifier.v == ReductionModifier::Value::Task) {
35503555
// "Task" is only allowed on worksharing or "parallel" directive.
@@ -4425,8 +4430,30 @@ void OmpStructureChecker::Enter(const parser::OmpClause::Lastprivate &x) {
44254430
CheckPrivateSymbolsInOuterCxt(
44264431
currSymbols, dirClauseTriple, llvm::omp::Clause::OMPC_lastprivate);
44274432

4428-
OmpVerifyModifiers(
4429-
x.v, llvm::omp::OMPC_lastprivate, GetContext().clauseSource, context_);
4433+
if (OmpVerifyModifiers(x.v, llvm::omp::OMPC_lastprivate,
4434+
GetContext().clauseSource, context_)) {
4435+
auto &modifiers{OmpGetModifiers(x.v)};
4436+
using LastprivateModifier = parser::OmpLastprivateModifier;
4437+
if (auto *modifier{OmpGetUniqueModifier<LastprivateModifier>(modifiers)}) {
4438+
CheckLastprivateModifier(*modifier);
4439+
}
4440+
}
4441+
}
4442+
4443+
// Add any restrictions related to Modifiers/Directives with
4444+
// Lastprivate clause here:
4445+
void OmpStructureChecker::CheckLastprivateModifier(
4446+
const parser::OmpLastprivateModifier &modifier) {
4447+
using LastprivateModifier = parser::OmpLastprivateModifier;
4448+
const DirectiveContext &dirCtx{GetContext()};
4449+
if (modifier.v == LastprivateModifier::Value::Conditional &&
4450+
dirCtx.directive == llvm::omp::Directive::OMPD_taskloop) {
4451+
// [5.2:268:17]
4452+
// The conditional lastprivate-modifier must not be specified.
4453+
context_.Say(GetContext().clauseSource,
4454+
"'CONDITIONAL' modifier on lastprivate clause with TASKLOOP "
4455+
"directive is not allowed"_err_en_US);
4456+
}
44304457
}
44314458

44324459
void OmpStructureChecker::Enter(const parser::OmpClause::Copyin &x) {

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,7 @@ class OmpStructureChecker
288288
void CheckReductionObjectTypes(const parser::OmpObjectList &objects,
289289
const parser::OmpReductionIdentifier &ident);
290290
void CheckReductionModifier(const parser::OmpReductionModifier &);
291+
void CheckLastprivateModifier(const parser::OmpLastprivateModifier &);
291292
void CheckMasterNesting(const parser::OpenMPBlockConstruct &x);
292293
void ChecksOnOrderedAsBlock();
293294
void CheckBarrierNesting(const parser::OpenMPSimpleStandaloneConstruct &x);
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
!RUN: %python %S/../test_errors.py %s %flang -fopenmp -fopenmp-version=52
2+
3+
subroutine foo()
4+
integer :: x, i
5+
x = 1
6+
!ERROR: 'CONDITIONAL' modifier on lastprivate clause with TASKLOOP directive is not allowed
7+
!$omp taskloop lastprivate(conditional: x)
8+
do i = 1, 100
9+
x = x + 1
10+
enddo
11+
!$omp end taskloop
12+
end
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
!RUN: %python %S/../test_errors.py %s %flang -fopenmp -fopenmp-version=52
2+
3+
subroutine bar()
4+
integer :: x, i
5+
x = 1
6+
!ERROR: REDUCTION modifier on TASKLOOP directive must be DEFAULT
7+
!ERROR: List item x must appear in EXCLUSIVE or INCLUSIVE clause of an enclosed SCAN directive
8+
!$omp taskloop reduction(inscan, +:x)
9+
do i = 1, 100
10+
x = x + 1
11+
enddo
12+
!$omp end taskloop
13+
end
14+
15+
subroutine baz()
16+
integer :: x, i
17+
x = 1
18+
!ERROR: REDUCTION modifier on TASKLOOP directive must be DEFAULT
19+
!$omp taskloop reduction(task, +:x)
20+
do i = 1, 100
21+
x = x + 1
22+
enddo
23+
!$omp end taskloop
24+
end

0 commit comments

Comments
 (0)