Skip to content

Commit

Permalink
[flang] [OpenMP] Add structural checks for TASK
Browse files Browse the repository at this point in the history
1. fix `OmpIfClause` on `Task`
2. add structural checks

Original-commit: flang-compiler/f18@a77830a
  • Loading branch information
gpupuck authored and ichoyjx committed Sep 5, 2019
1 parent 77ed1df commit c4fa8b8
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 5 deletions.
4 changes: 2 additions & 2 deletions flang/lib/parser/openmp-grammar.h
Expand Up @@ -107,8 +107,8 @@ TYPE_PARSER(construct<OmpIfClause>(
"TARGET UPDATE" >>
pure(OmpIfClause::DirectiveNameModifier::TargetUpdate) ||
"TARGET" >> pure(OmpIfClause::DirectiveNameModifier::Target) ||
"TASK"_id >> pure(OmpIfClause::DirectiveNameModifier::Taskloop) ||
"TASKLOOP" >> pure(OmpIfClause::DirectiveNameModifier::Task)) /
"TASK"_id >> pure(OmpIfClause::DirectiveNameModifier::Task) ||
"TASKLOOP" >> pure(OmpIfClause::DirectiveNameModifier::Taskloop)) /
":"),
scalarLogicalExpr))

Expand Down
26 changes: 24 additions & 2 deletions flang/lib/semantics/check-omp-structure.cc
Expand Up @@ -97,7 +97,8 @@ void OmpStructureChecker::CheckAllowed(OmpClause type) {
});
for (const auto &e : others) {
context_.Say(GetContext().clauseSource,
"%s and %s are mutually exclusive and may not appear on the same %s directive"_err_en_US,
"%s and %s are mutually exclusive and may not appear on the "
"same %s directive"_err_en_US,
EnumToString(type), EnumToString(e),
parser::ToUpperCaseLetters(GetContext().directiveSource.ToString()));
}
Expand Down Expand Up @@ -326,6 +327,26 @@ void OmpStructureChecker::Enter(const parser::OpenMPBlockConstruct &x) {
case parser::OmpBlockDirective::Directive::Workshare:
PushContext(beginDir.source, OmpDirective::WORKSHARE);
break;
// 2.9.1 task-clause -> if-clause |
// final-clause |
// untied-clause |
// default-clause |
// mergeable-clause |
// private-clause |
// firstprivate-clause |
// shared-clause |
// depend-clause |
// priority-clause
case parser::OmpBlockDirective::Directive::Task: {
PushContext(beginDir.source, OmpDirective::TASK);
OmpClauseSet allowed{OmpClause::UNTIED, OmpClause::DEFAULT,
OmpClause::MERGEABLE, OmpClause::PRIVATE, OmpClause::FIRSTPRIVATE,
OmpClause::SHARED, OmpClause::DEPEND};
SetContextAllowed(allowed);
OmpClauseSet allowedOnce{
OmpClause::IF, OmpClause::FINAL, OmpClause::PRIORITY};
SetContextAllowedOnce(allowedOnce);
} break;
default:
// TODO others
break;
Expand Down Expand Up @@ -695,8 +716,9 @@ void OmpStructureChecker::Enter(const parser::OmpClause::Ordered &x) {
}
}
}
void OmpStructureChecker::Enter(const parser::OmpClause::Priority &) {
void OmpStructureChecker::Enter(const parser::OmpClause::Priority &x) {
CheckAllowed(OmpClause::PRIORITY);
RequiresPositiveParameter(OmpClause::PRIORITY, x.v);
}
void OmpStructureChecker::Enter(const parser::OmpClause::Private &) {
CheckAllowed(OmpClause::PRIVATE);
Expand Down
27 changes: 26 additions & 1 deletion flang/test/semantics/omp-clause-validity01.f90
Expand Up @@ -376,7 +376,6 @@
a = 3.14
enddo


! Standalone Directives (basic)

!$omp taskyield
Expand All @@ -399,4 +398,30 @@
a = 3.14
!ERROR: Internal: no symbol found for 'first'
!$omp end critical (first)

! 2.9.1 task-clause -> if-clause |
! final-clause |
! untied-clause |
! default-clause |
! mergeable-clause |
! private-clause |
! firstprivate-clause |
! shared-clause |
! depend-clause |
! priority-clause

!$omp task shared(a) default(none) if(task:a > 1.)
a = 1.
!$omp end task

!ERROR: LASTPRIVATE clause is not allowed on the TASK directive
!ERROR: At most one FINAL clause can appear on the TASK directive
!$omp task lastprivate(b) final(a.GE.1) final(.false.)
b = 1
!$omp end task

!ERROR: The parameter of the PRIORITY clause must be a positive integer expression
!$omp task priority(-1) firstprivate(a) mergeable
a = 3.14
!$omp end task
end program

0 comments on commit c4fa8b8

Please sign in to comment.