[flang] Semantic checks for teams directive
authorDavid Truby <david.truby@arm.com>
Tue, 17 Sep 2019 11:08:04 +0000 (12:08 +0100)
committerDavid Truby <david.truby@arm.com>
Tue, 17 Sep 2019 11:08:04 +0000 (12:08 +0100)
Original-commit: flang-compiler/f18@ec22e9c4c2b5592975c53869f3cfbcd097222203
Reviewed-on: https://github.com/flang-compiler/f18/pull/750
Tree-same-pre-rewrite: false

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

index a51842a..45bfdbd 100644 (file)
@@ -404,6 +404,15 @@ void OmpStructureChecker::Enter(const parser::OpenMPBlockConstruct &x) {
         OmpClause::DEVICE, OmpClause::DEFAULTMAP, OmpClause::NOWAIT};
     SetContextAllowedOnce(allowedOnce);
   } break;
+  case parser::OmpBlockDirective::Directive::Teams: {
+    PushContext(beginDir.source, OmpDirective::TEAMS);
+    OmpClauseSet allowed{OmpClause::PRIVATE, OmpClause::FIRSTPRIVATE,
+        OmpClause::SHARED, OmpClause::REDUCTION};
+    SetContextAllowed(allowed);
+    OmpClauseSet allowedOnce{
+        OmpClause::NUM_TEAMS, OmpClause::THREAD_LIMIT, OmpClause::DEFAULT};
+    SetContextAllowedOnce(allowedOnce);
+  } break;
   default:
     // TODO others
     break;
@@ -747,8 +756,9 @@ void OmpStructureChecker::Enter(const parser::OmpClause::NumTasks &x) {
   CheckAllowed(OmpClause::NUM_TASKS);
   RequiresPositiveParameter(OmpClause::NUM_TASKS, x.v);
 }
-void OmpStructureChecker::Enter(const parser::OmpClause::NumTeams &) {
+void OmpStructureChecker::Enter(const parser::OmpClause::NumTeams &x) {
   CheckAllowed(OmpClause::NUM_TEAMS);
+  RequiresPositiveParameter(OmpClause::NUM_TEAMS, x.v);
 }
 void OmpStructureChecker::Enter(const parser::OmpClause::NumThreads &x) {
   CheckAllowed(OmpClause::NUM_THREADS);
@@ -789,8 +799,9 @@ void OmpStructureChecker::Enter(const parser::OmpClause::Simdlen &x) {
   CheckAllowed(OmpClause::SIMDLEN);
   RequiresConstantPositiveParameter(OmpClause::SIMDLEN, x.v);
 }
-void OmpStructureChecker::Enter(const parser::OmpClause::ThreadLimit &) {
+void OmpStructureChecker::Enter(const parser::OmpClause::ThreadLimit &x) {
   CheckAllowed(OmpClause::THREAD_LIMIT);
+  RequiresPositiveParameter(OmpClause::THREAD_LIMIT, x.v);
 }
 void OmpStructureChecker::Enter(const parser::OmpClause::To &) {
   CheckAllowed(OmpClause::TO);
index 767af89..656e1d8 100644 (file)
@@ -70,4 +70,45 @@ program main
   enddo
   !$omp end target
 
+  !$omp teams num_teams(3) thread_limit(10) default(shared) private(i) shared(a)
+  do i = 1, N
+     a = 3.14
+  enddo
+  !$omp end teams
+
+  !ERROR: At most one NUM_TEAMS clause can appear on the TEAMS directive
+  !$omp teams num_teams(2) num_teams(3)
+  do i = 1, N
+     a = 3.14
+  enddo
+  !$omp end teams
+
+  !ERROR: The parameter of the NUM_TEAMS clause must be a positive integer expression
+  !$omp teams num_teams(-1)
+  do i = 1, N
+     a = 3.14
+  enddo
+  !$omp end teams
+
+  !ERROR: At most one THREAD_LIMIT clause can appear on the TEAMS directive
+  !$omp teams thread_limit(2) thread_limit(3)
+  do i = 1, N
+     a = 3.14
+  enddo
+  !$omp end teams
+
+  !ERROR: The parameter of the THREAD_LIMIT clause must be a positive integer expression
+  !$omp teams thread_limit(-1)
+  do i = 1, N
+     a = 3.14
+  enddo
+  !$omp end teams
+
+  !ERROR: At most one DEFAULT clause can appear on the TEAMS directive
+  !$omp teams default(shared) default(none)
+  do i = 1, N
+     a = 3.14
+  enddo
+  !$omp end teams
+
 end program main