[flang] Added tofrom:scalar check for defaultmap clause
authorDavid Truby <david.truby@arm.com>
Tue, 10 Sep 2019 10:02:17 +0000 (11:02 +0100)
committerDavid Truby <david.truby@arm.com>
Tue, 10 Sep 2019 13:04:03 +0000 (14:04 +0100)
Original-commit: flang-compiler/f18@1025649b647f670aa05d7779319591440dae6c27
Reviewed-on: https://github.com/flang-compiler/f18/pull/719
Tree-same-pre-rewrite: false

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

index 6f00101..f5319b3 100644 (file)
@@ -396,8 +396,9 @@ void OmpStructureChecker::Enter(const parser::OpenMPBlockConstruct &x) {
   //                         depend-clause
   case parser::OmpBlockDirective::Directive::Target: {
     PushContext(beginDir.source, OmpDirective::TARGET);
-    OmpClauseSet allowed{OmpClause::IF, OmpClause::PRIVATE, OmpClause::MAP,
-        OmpClause::DEPEND, OmpClause::FIRSTPRIVATE, OmpClause::IS_DEVICE_PTR};
+    OmpClauseSet allowed{OmpClause::IF, OmpClause::PRIVATE,
+        OmpClause::FIRSTPRIVATE, OmpClause::MAP, OmpClause::IS_DEVICE_PTR,
+        OmpClause::DEPEND};
     SetContextAllowed(allowed);
     OmpClauseSet allowedOnce{
         OmpClause::DEVICE, OmpClause::DEFAULTMAP, OmpClause::NOWAIT};
@@ -825,8 +826,14 @@ void OmpStructureChecker::Enter(const parser::OmpAlignedClause &x) {
 void OmpStructureChecker::Enter(const parser::OmpDefaultClause &) {
   CheckAllowed(OmpClause::DEFAULT);
 }
-void OmpStructureChecker::Enter(const parser::OmpDefaultmapClause &) {
+void OmpStructureChecker::Enter(const parser::OmpDefaultmapClause &x) {
   CheckAllowed(OmpClause::DEFAULTMAP);
+  using VariableCategory = parser::OmpDefaultmapClause::VariableCategory;
+  if (!std::get<std::optional<VariableCategory>>(x.t)) {
+    context_.Say(GetContext().clauseSource,
+        "The scalar VARIABLECATEGORY must be specified on the DEFAULTMAP "
+        "clause"_err_en_US);
+  }
 }
 void OmpStructureChecker::Enter(const parser::OmpDependClause &) {
   CheckAllowed(OmpClause::DEPEND);
index 56e89d6..ef9266e 100644 (file)
@@ -36,7 +36,6 @@ program main
   enddo
   !$omp end target
 
-
   !ERROR: At most one DEVICE clause can appear on the TARGET directive
   !$omp target device(0) device(1)
   do i = 1, N
@@ -51,6 +50,19 @@ program main
   enddo
   !$omp end target
 
+  !$omp target defaultmap(tofrom:scalar)
+  do i = 1, N
+     a = 3.14
+  enddo
+  !$omp end target
+
+  !ERROR: The scalar VARIABLECATEGORY must be specified on the DEFAULTMAP clause
+  !$omp target defaultmap(tofrom)
+  do i = 1, N
+     a = 3.14
+  enddo
+  !$omp end target
+
   !ERROR: At most one DEFAULTMAP clause can appear on the TARGET directive
   !$omp target defaultmap(tofrom:scalar) defaultmap(tofrom:scalar)
   do i = 1, N