[flang] Corrected check for required OpenMP clauses
authorDavid Truby <david.truby@arm.com>
Tue, 17 Sep 2019 08:53:27 +0000 (09:53 +0100)
committerDavid Truby <david.truby@arm.com>
Fri, 27 Sep 2019 12:57:51 +0000 (13:57 +0100)
Original-commit: flang-compiler/f18@ce3ec50c3f01785f8bc0f92f1a7f6b65b2e52973
Reviewed-on: https://github.com/flang-compiler/f18/pull/748
Tree-same-pre-rewrite: false

flang/lib/semantics/check-omp-structure.cc
flang/lib/semantics/check-omp-structure.h
flang/test/semantics/omp-device-constructs.f90

index e5d7fdc..28f39cf 100644 (file)
@@ -437,9 +437,8 @@ void OmpStructureChecker::Enter(const parser::OpenMPBlockConstruct &x) {
     OmpClauseSet allowed{
         OmpClause::IF, OmpClause::MAP, OmpClause::USE_DEVICE_PTR};
     SetContextAllowed(allowed);
-    OmpClauseSet allowedOnce{OmpClause::DEVICE};
-    SetContextAllowedOnce(allowedOnce);
-    SetContextRequired(OmpClauseSet{OmpClause::MAP});
+    SetContextAllowedOnce({OmpClause::DEVICE});
+    SetContextRequired({OmpClause::MAP});
   } break;
   default:
     // TODO others
@@ -557,7 +556,7 @@ void OmpStructureChecker::Enter(
     SetContextAllowed(allowed);
     OmpClauseSet allowedOnce{OmpClause::DEVICE, OmpClause::IF};
     SetContextAllowedOnce(allowedOnce);
-    SetContextRequired(OmpClauseSet{OmpClause::MAP});
+    SetContextRequired({OmpClause::MAP});
   } break;
   case parser::OmpSimpleStandaloneDirective::Directive::TargetExitData: {
     // 2.10.3 target-exit-data
@@ -566,7 +565,7 @@ void OmpStructureChecker::Enter(
     SetContextAllowed(allowed);
     OmpClauseSet allowedOnce{OmpClause::DEVICE, OmpClause::IF};
     SetContextAllowedOnce(allowedOnce);
-    SetContextRequired(OmpClauseSet{OmpClause::MAP});
+    SetContextRequired({OmpClause::MAP});
   } break;
   case parser::OmpSimpleStandaloneDirective::Directive::TargetUpdate: {
     // 2.10.5 target-update
@@ -731,6 +730,9 @@ void OmpStructureChecker::Leave(const parser::OmpClauseList &) {
       }
     }
   }
+
+  GetContext().requiredClauses.IterateOverMembers(
+      [this](OmpClause c) { CheckRequired(c); });
 }
 
 void OmpStructureChecker::Enter(const parser::OmpClause &x) {
@@ -941,7 +943,7 @@ void OmpStructureChecker::Enter(const parser::OmpMapClause &x) {
       if (type != Type::To && type != Type::From && type != Type::Tofrom &&
           type != Type::Alloc) {
         context_.Say(GetContext().clauseSource,
-            "Only the TO, FROM, TOFROM or ALLOC map types are permitted "
+            "Only the TO, FROM, TOFROM, or ALLOC map types are permitted "
             "for MAP clauses on the %s directive"_err_en_US,
             ContextDirectiveAsFortran());
       }
@@ -957,7 +959,7 @@ void OmpStructureChecker::Enter(const parser::OmpMapClause &x) {
     case OmpDirective::TARGET_EXIT_DATA: {
       if (type != Type::Delete && type != Type::Release && type != Type::From) {
         context_.Say(GetContext().clauseSource,
-            "Only the FROM, RELEASE or DELETE map types are permitted "
+            "Only the FROM, RELEASE, or DELETE map types are permitted "
             "for MAP clauses on the %s directive"_err_en_US,
             ContextDirectiveAsFortran());
       }
index 574facd..a2c0f50 100644 (file)
@@ -152,8 +152,6 @@ private:
   // collected information for END directive
   void ResetPartialContext(const parser::CharBlock &source) {
     CHECK(!ompContext_.empty());
-    GetContext().requiredClauses.IterateOverMembers(
-        [this](OmpClause c) { CheckRequired(c); });
     SetContextDirectiveSource(source);
     GetContext().allowedClauses = {};
     GetContext().allowedOnceClauses = {};
index 8fb37d5..90a12f7 100644 (file)
@@ -117,7 +117,7 @@ program main
   enddo
   !$omp end target
 
-  !ERROR: Only the TO, FROM, TOFROM or ALLOC map types are permitted for MAP clauses on the TARGET directive
+  !ERROR: Only the TO, FROM, TOFROM, or ALLOC map types are permitted for MAP clauses on the TARGET directive
   !$omp target map(delete:a)
   do i = 1, N
      a = 3.14
@@ -148,6 +148,6 @@ program main
   !ERROR: At most one DEVICE clause can appear on the TARGET EXIT DATA directive
   !$omp target exit data map(from:a) device(0) device(1)
 
-  !ERROR: Only the FROM, RELEASE or DELETE map types are permitted for MAP clauses on the TARGET EXIT DATA directive
+  !ERROR: Only the FROM, RELEASE, or DELETE map types are permitted for MAP clauses on the TARGET EXIT DATA directive
   !$omp target exit data map(to:a)
 end program main