From c4fa8b867e700a46534028e61a9e8ff90c51678e Mon Sep 17 00:00:00 2001 From: Jinxin Yang Date: Wed, 4 Sep 2019 23:35:44 -0700 Subject: [PATCH] [flang] [OpenMP] Add structural checks for `TASK` 1. fix `OmpIfClause` on `Task` 2. add structural checks Original-commit: flang-compiler/f18@a77830a191989d7885337cf6182ac82ccf9c5ae9 --- flang/lib/parser/openmp-grammar.h | 4 +-- flang/lib/semantics/check-omp-structure.cc | 26 ++++++++++++++++-- .../test/semantics/omp-clause-validity01.f90 | 27 ++++++++++++++++++- 3 files changed, 52 insertions(+), 5 deletions(-) diff --git a/flang/lib/parser/openmp-grammar.h b/flang/lib/parser/openmp-grammar.h index 6408e49c2974..ab6b338864bb 100644 --- a/flang/lib/parser/openmp-grammar.h +++ b/flang/lib/parser/openmp-grammar.h @@ -107,8 +107,8 @@ TYPE_PARSER(construct( "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)) diff --git a/flang/lib/semantics/check-omp-structure.cc b/flang/lib/semantics/check-omp-structure.cc index 795dfcedcdad..91c968dbf005 100644 --- a/flang/lib/semantics/check-omp-structure.cc +++ b/flang/lib/semantics/check-omp-structure.cc @@ -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())); } @@ -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; @@ -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); diff --git a/flang/test/semantics/omp-clause-validity01.f90 b/flang/test/semantics/omp-clause-validity01.f90 index 1ca70e7822e4..04d008ba1d75 100644 --- a/flang/test/semantics/omp-clause-validity01.f90 +++ b/flang/test/semantics/omp-clause-validity01.f90 @@ -376,7 +376,6 @@ a = 3.14 enddo - ! Standalone Directives (basic) !$omp taskyield @@ -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