[flang-commits] [flang] c3b1395 - Add Semantic check for Flang OpenMP 4.5 - 2.7.1 schedule clause

via flang-commits flang-commits at lists.llvm.org
Wed Nov 11 02:30:20 PST 2020


Author: Yashaswini
Date: 2020-11-11T15:56:18+05:30
New Revision: c3b1395384e5ebe27c3ddea10f940c19386927d3

URL: https://github.com/llvm/llvm-project/commit/c3b1395384e5ebe27c3ddea10f940c19386927d3
DIFF: https://github.com/llvm/llvm-project/commit/c3b1395384e5ebe27c3ddea10f940c19386927d3.diff

LOG: Add Semantic check for Flang OpenMP 4.5 - 2.7.1 schedule clause

Semantic check for the positive chunk size.

Test Cases:
omp-do-schedule01.f90
omp-do-schedule02.f90
omp-do-schedule03.f90
omp-do-schedule04.f90

Reviewed by: Kiran Chandramohan @kiranchandramohan

Differential Revision: https://reviews.llvm.org/D89546

Added: 
    flang/test/Semantics/omp-do-schedule01.f90
    flang/test/Semantics/omp-do-schedule02.f90
    flang/test/Semantics/omp-do-schedule03.f90
    flang/test/Semantics/omp-do-schedule04.f90

Modified: 
    flang/lib/Semantics/check-directive-structure.h
    flang/lib/Semantics/check-omp-structure.cpp

Removed: 
    


################################################################################
diff  --git a/flang/lib/Semantics/check-directive-structure.h b/flang/lib/Semantics/check-directive-structure.h
index 29996a75823d..822cdca9b66a 100644
--- a/flang/lib/Semantics/check-directive-structure.h
+++ b/flang/lib/Semantics/check-directive-structure.h
@@ -248,8 +248,8 @@ class DirectiveStructureChecker : public virtual BaseChecker {
   void RequiresConstantPositiveParameter(
       const C &clause, const parser::ScalarIntConstantExpr &i);
 
-  void RequiresPositiveParameter(
-      const C &clause, const parser::ScalarIntExpr &i);
+  void RequiresPositiveParameter(const C &clause,
+      const parser::ScalarIntExpr &i, llvm::StringRef paramName = "parameter");
 
   void OptionalConstantPositiveParameter(
       const C &clause, const std::optional<parser::ScalarIntConstantExpr> &o);
@@ -462,12 +462,13 @@ void DirectiveStructureChecker<D, C, PC, ClauseEnumSize>::CheckRequired(C c) {
 template <typename D, typename C, typename PC, std::size_t ClauseEnumSize>
 void DirectiveStructureChecker<D, C, PC,
     ClauseEnumSize>::RequiresPositiveParameter(const C &clause,
-    const parser::ScalarIntExpr &i) {
+    const parser::ScalarIntExpr &i, llvm::StringRef paramName) {
   if (const auto v{GetIntValue(i)}) {
     if (*v <= 0) {
       context_.Say(GetContext().clauseSource,
-          "The parameter of the %s clause must be "
+          "The %s of the %s clause must be "
           "a positive integer expression"_err_en_US,
+          paramName.str(),
           parser::ToUpperCaseLetters(getClauseName(clause).str()));
     }
   }

diff  --git a/flang/lib/Semantics/check-omp-structure.cpp b/flang/lib/Semantics/check-omp-structure.cpp
index 07060be3670f..56eeed259697 100644
--- a/flang/lib/Semantics/check-omp-structure.cpp
+++ b/flang/lib/Semantics/check-omp-structure.cpp
@@ -578,6 +578,11 @@ void OmpStructureChecker::Enter(const parser::OmpScheduleClause &x) {
             parser::ToUpperCaseLetters(
                 parser::OmpScheduleClause::EnumToString(kind)));
       }
+      if (const auto &chunkExpr{
+              std::get<std::optional<parser::ScalarIntExpr>>(x.t)}) {
+        RequiresPositiveParameter(
+            llvm::omp::Clause::OMPC_schedule, *chunkExpr, "chunk size");
+      }
     }
 
     if (ScheduleModifierHasType(

diff  --git a/flang/test/Semantics/omp-do-schedule01.f90 b/flang/test/Semantics/omp-do-schedule01.f90
new file mode 100644
index 000000000000..fbce3e53447d
--- /dev/null
+++ b/flang/test/Semantics/omp-do-schedule01.f90
@@ -0,0 +1,13 @@
+! RUN: %S/test_errors.sh %s %t %f18 -fopenmp
+! OpenMP Version 4.5
+! 2.7.1 Schedule Clause
+program omp_doSchedule
+  integer :: i,n
+  real ::  a(100), y(100), z(100)
+  !ERROR: The chunk size of the SCHEDULE clause must be a positive integer expression
+  !$omp do schedule(static, -1)
+  do i=2,n+1
+    y(i) = z(i-1) + a(i)
+  end do
+  !$omp end do
+end program omp_doSchedule

diff  --git a/flang/test/Semantics/omp-do-schedule02.f90 b/flang/test/Semantics/omp-do-schedule02.f90
new file mode 100644
index 000000000000..993663503d74
--- /dev/null
+++ b/flang/test/Semantics/omp-do-schedule02.f90
@@ -0,0 +1,15 @@
+!RUN: %S/test_errors.sh %s %t %f18 -fopenmp
+! OpenMP Version 4.5
+! 2.7.1 Schedule Clause
+program omp_doSchedule
+  integer :: i,n
+  real ::  a(100), y(100), z(100)
+  integer,parameter :: b = 10
+  integer,parameter :: c = 11
+  !ERROR: The chunk size of the SCHEDULE clause must be a positive integer expression
+  !$omp do schedule(static,b-c)
+  do i=2,n+1
+    y(i) = z(i-1) + a(i)
+  end do
+  !$omp end do
+end program omp_doSchedule

diff  --git a/flang/test/Semantics/omp-do-schedule03.f90 b/flang/test/Semantics/omp-do-schedule03.f90
new file mode 100644
index 000000000000..818482539c74
--- /dev/null
+++ b/flang/test/Semantics/omp-do-schedule03.f90
@@ -0,0 +1,28 @@
+! RUN: %S/test_symbols.sh %s %t %f18 -fopenmp
+! OpenMP Version 4.5
+! 2.7.1 Schedule Clause
+! Test that does not catch non constant integer expressions like xx - xx.
+  !DEF: /ompdoschedule MainProgram
+program ompdoschedule
+  !DEF: /ompdoschedule/a ObjectEntity REAL(4)
+  !DEF: /ompdoschedule/y ObjectEntity REAL(4)
+  !DEF: /ompdoschedule/z ObjectEntity REAL(4)
+  real  a(100),y(100),z(100)
+  !DEF: /ompdoschedule/b ObjectEntity INTEGER(4)
+  !DEF: /ompdoschedule/i ObjectEntity INTEGER(4)
+  !DEF: /ompdoschedule/n ObjectEntity INTEGER(4)
+  integer  b,i,n
+  !REF: /ompdoschedule/b
+  b = 10
+  !$omp do  schedule(static,b-b)
+  !DEF: /ompdoschedule/Block1/i (OmpPrivate, OmpPreDetermined) HostAssoc INTEGER(4)
+  !REF: /ompdoschedule/n
+  do i = 2,n+1
+    !REF: /ompdoschedule/y
+    !REF: /ompdoschedule/Block1/i
+    !REF: /ompdoschedule/z
+    !REF: /ompdoschedule/a
+    y(i) = z(i-1) + a(i)
+  end do
+  !$omp end do
+end program ompdoschedule

diff  --git a/flang/test/Semantics/omp-do-schedule04.f90 b/flang/test/Semantics/omp-do-schedule04.f90
new file mode 100644
index 000000000000..4dba5092726f
--- /dev/null
+++ b/flang/test/Semantics/omp-do-schedule04.f90
@@ -0,0 +1,32 @@
+! RUN: %S/test_symbols.sh %s %t %f18 -fopenmp
+! OpenMP Version 4.5
+! 2.7.1 Schedule Clause
+! Test that does not catch non constant integer expressions like xx - yy.
+
+  !DEF: /tds (Subroutine) Subprogram
+subroutine tds
+  implicit none
+  !DEF: /tds/a ObjectEntity REAL(4)
+  !DEF: /tds/y ObjectEntity REAL(4)
+  !DEF: /tds/z ObjectEntity REAL(4)
+  real a(100),y(100),z(100)
+  !DEF: /tds/i ObjectEntity INTEGER(4)
+  !DEF: /tds/j ObjectEntity INTEGER(4)
+  !DEF: /tds/k ObjectEntity INTEGER(4)
+  integer i,j,k
+
+  !REF: /tds/j
+  j = 11
+  !REF: /tds/k
+  k = 12
+  !$omp do  schedule(static,j-k)
+  !DEF: /tds/Block1/i (OmpPrivate,OmpPreDetermined) HostAssoc INTEGER(4)
+  do i = 1,10
+    !REF: /tds/y
+    !REF: /tds/Block1/i
+    !REF: /tds/z
+    !REF: /tds/a
+    y(i) = z(i-1)+a(i)
+  end do
+  !$omp end do
+end subroutine tds


        


More information about the flang-commits mailing list