[flang] [OpenMP] enable check for `IF` clause modifier
authorJinxin Yang <jinxiny@nvidia.com>
Thu, 5 Sep 2019 10:15:23 +0000 (03:15 -0700)
committerJinxin (Brian) Yang <brianyang1106@gmail.com>
Thu, 5 Sep 2019 20:35:21 +0000 (13:35 -0700)
Original-commit: flang-compiler/f18@f56fe4a3895a6ac444b45ad80b433c4dbeca4bbe

flang/lib/semantics/check-omp-structure.cc
flang/test/semantics/omp-clause-validity01.f90

index 91c968d..cb058ac 100644 (file)
@@ -774,8 +774,33 @@ void OmpStructureChecker::Enter(const parser::OmpDefaultClause &) {
 void OmpStructureChecker::Enter(const parser::OmpDependClause &) {
   CheckAllowed(OmpClause::DEPEND);
 }
-void OmpStructureChecker::Enter(const parser::OmpIfClause &) {
+void OmpStructureChecker::Enter(const parser::OmpIfClause &x) {
   CheckAllowed(OmpClause::IF);
+
+  using dirNameModifier = parser::OmpIfClause::DirectiveNameModifier;
+  static std::unordered_map<dirNameModifier, OmpDirective> dirNameModifierMap{
+      {dirNameModifier::Parallel, OmpDirective::PARALLEL},
+      {dirNameModifier::Target, OmpDirective::TARGET},
+      {dirNameModifier::TargetEnterData, OmpDirective::TARGET_ENTER_DATA},
+      {dirNameModifier::TargetExitData, OmpDirective::TARGET_EXIT_DATA},
+      {dirNameModifier::TargetData, OmpDirective::TARGET_DATA},
+      {dirNameModifier::TargetUpdate, OmpDirective::TARGET_UPDATE},
+      {dirNameModifier::Task, OmpDirective::TASK},
+      {dirNameModifier::Taskloop, OmpDirective::TASKLOOP}};
+  if (const auto &directiveName{
+          std::get<std::optional<dirNameModifier>>(x.t)}) {
+    auto search{dirNameModifierMap.find(*directiveName)};
+    if (search == dirNameModifierMap.end() ||
+        search->second != GetContext().directive) {
+      context_
+          .Say(GetContext().clauseSource,
+              "Unmatched directive name modifier %s on the IF clause"_err_en_US,
+              parser::ToUpperCaseLetters(
+                  parser::OmpIfClause::EnumToString(*directiveName)))
+          .Attach(
+              GetContext().directiveSource, "Does not match directive"_en_US);
+    }
+  }
 }
 void OmpStructureChecker::Enter(const parser::OmpLinearClause &x) {
   CheckAllowed(OmpClause::LINEAR);
index 04d008b..44ddac7 100644 (file)
   a = 1.
   !$omp end task
 
+  !ERROR: Unmatched directive name modifier TASKLOOP on the IF clause
+  !$omp task private(a) if(taskloop:a.eq.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.)