c-parser.c (c_parser_omp_clause_schedule): Warn if OMP_CLAUSE_SCHEDULE_CHUNK_EXPR...
authorJakub Jelinek <jakub@redhat.com>
Thu, 26 May 2016 19:12:27 +0000 (21:12 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Thu, 26 May 2016 19:12:27 +0000 (21:12 +0200)
* c-parser.c (c_parser_omp_clause_schedule): Warn if
OMP_CLAUSE_SCHEDULE_CHUNK_EXPR is known not to be positive.

* semantics.c (finish_omp_clauses) <case OMP_CLAUSE_SCHEDULE>: Warn
if OMP_CLAUSE_SCHEDULE_CHUNK_EXPR is known not to be positive.

* openmp.c (resolve_omp_clauses): Warn if chunk_size is known not to
be positive.

* c-c++-common/gomp/schedule-1.c: New test.
* gfortran.dg/gomp/schedule-1.f90: New test.

* testsuite/libgomp.c/doacross-1.c (main): Use schedule(static)
instead of invalid schedule(static, 0).
* testsuite/libgomp.c/doacross-2.c (main): Likewise.

From-SVN: r236793

12 files changed:
gcc/c/ChangeLog
gcc/c/c-parser.c
gcc/cp/ChangeLog
gcc/cp/semantics.c
gcc/fortran/ChangeLog
gcc/fortran/openmp.c
gcc/testsuite/ChangeLog
gcc/testsuite/c-c++-common/gomp/schedule-1.c [new file with mode: 0644]
gcc/testsuite/gfortran.dg/gomp/schedule-1.f90 [new file with mode: 0644]
libgomp/ChangeLog
libgomp/testsuite/libgomp.c/doacross-1.c
libgomp/testsuite/libgomp.c/doacross-2.c

index f3bb0e9d58a30c6f47a6b8ad9eb6d9599eb01164..f7d1a6d582ec12cbe9208d9b934e18acd0e1f364 100644 (file)
@@ -1,3 +1,8 @@
+2016-05-26  Jakub Jelinek  <jakub@redhat.com>
+
+       * c-parser.c (c_parser_omp_clause_schedule): Warn if
+       OMP_CLAUSE_SCHEDULE_CHUNK_EXPR is known not to be positive.
+
 2016-05-25  Marek Polacek  <polacek@redhat.com>
 
        PR c/71265
index 1cf4fb452aa8e66536789aa1c69909a487a50502..fda2df8e44e3950286718209f158911014c151ca 100644 (file)
@@ -12128,7 +12128,20 @@ c_parser_omp_clause_schedule (c_parser *parser, tree list)
                  "schedule %<auto%> does not take "
                  "a %<chunk_size%> parameter");
       else if (TREE_CODE (TREE_TYPE (t)) == INTEGER_TYPE)
-       OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c) = t;
+       {
+         /* Attempt to statically determine when the number isn't
+            positive.  */
+         tree s = fold_build2_loc (loc, LE_EXPR, boolean_type_node, t,
+                                   build_int_cst (TREE_TYPE (t), 0));
+         protected_set_expr_location (s, loc);
+         if (s == boolean_true_node)
+           {
+             warning_at (loc, 0,
+                         "chunk size value must be positive");
+             t = integer_one_node;
+           }
+         OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c) = t;
+       }
       else
        c_parser_error (parser, "expected integer expression");
 
index ff5d8f4825c247551eb7957f3b109ed002811495..770f817eecafa50b60db33e7366bfe63bd74be32 100644 (file)
@@ -1,3 +1,8 @@
+2016-05-26  Jakub Jelinek  <jakub@redhat.com>
+
+       * semantics.c (finish_omp_clauses) <case OMP_CLAUSE_SCHEDULE>: Warn
+       if OMP_CLAUSE_SCHEDULE_CHUNK_EXPR is known not to be positive.
+
 2016-05-26  Patrick Palka  <ppalka@gcc.gnu.org>
 
        PR c++/70822
index 0cef86758f8b57156c2c4259f545a4a305857fd7..253d31a4f4a7251a6b0f705f272fc2c17efa0910 100644 (file)
@@ -6319,6 +6319,17 @@ finish_omp_clauses (tree clauses, enum c_omp_region_type ort)
                          break;
                        }
                    }
+                 else
+                   {
+                     t = maybe_constant_value (t);
+                     if (TREE_CODE (t) == INTEGER_CST
+                         && tree_int_cst_sgn (t) != 1)
+                       {
+                         warning_at (OMP_CLAUSE_LOCATION (c), 0,
+                                     "chunk size value must be positive");
+                         t = integer_one_node;
+                       }
+                   }
                  t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
                }
              OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c) = t;
index 8db70173d2758e78f885f34ca4edfcee43f5afdd..73235c6d31cd80e7a1d0ceaab183d7484df92f15 100644 (file)
@@ -1,3 +1,8 @@
+2016-05-26  Jakub Jelinek  <jakub@redhat.com>
+
+       * openmp.c (resolve_omp_clauses): Warn if chunk_size is known not to
+       be positive.
+
 2016-05-23  Jerry DeLisle  <jvdelisle@gcc.gnu.org>
 
        PR fortran/66461
index 1481719f6e695ecbc375a1f95813270a8467dc8d..2689d302c77dc75ff6ee29d831c91f831500395b 100644 (file)
@@ -3259,6 +3259,11 @@ resolve_omp_clauses (gfc_code *code, gfc_omp_clauses *omp_clauses,
          || expr->ts.type != BT_INTEGER || expr->rank != 0)
        gfc_error ("SCHEDULE clause's chunk_size at %L requires "
                   "a scalar INTEGER expression", &expr->where);
+      else if (expr->expr_type == EXPR_CONSTANT
+              && expr->ts.type == BT_INTEGER
+              && mpz_sgn (expr->value.integer) <= 0)
+       gfc_warning (0, "INTEGER expression of SCHEDULE clause's chunk_size "
+                    "at %L must be positive", &expr->where);
     }
 
   /* Check that no symbol appears on multiple clauses, except that
index 962421200cdceef185381d8b9918f458c098553d..f2a7a56bf052b1bbdc1069d734ca3ab9a0e15791 100644 (file)
@@ -1,3 +1,8 @@
+2016-05-26  Jakub Jelinek  <jakub@redhat.com>
+
+       * c-c++-common/gomp/schedule-1.c: New test.
+       * gfortran.dg/gomp/schedule-1.f90: New test.
+
 2016-05-26  Patrick Palka  <ppalka@gcc.gnu.org>
 
        PR c++/70822
diff --git a/gcc/testsuite/c-c++-common/gomp/schedule-1.c b/gcc/testsuite/c-c++-common/gomp/schedule-1.c
new file mode 100644 (file)
index 0000000..8700ff6
--- /dev/null
@@ -0,0 +1,14 @@
+void
+foo (void)
+{
+  int i;
+  #pragma omp for schedule(static, 1)
+  for (i = 0; i < 10; i++)
+    ;
+  #pragma omp for schedule(static, 0)          /* { dg-warning "chunk size value must be positive" } */
+  for (i = 0; i < 10; i++)
+    ;
+  #pragma omp for schedule(static, -7)         /* { dg-warning "chunk size value must be positive" } */
+  for (i = 0; i < 10; i++)
+    ;
+}
diff --git a/gcc/testsuite/gfortran.dg/gomp/schedule-1.f90 b/gcc/testsuite/gfortran.dg/gomp/schedule-1.f90
new file mode 100644 (file)
index 0000000..3d64294
--- /dev/null
@@ -0,0 +1,11 @@
+  integer :: i
+  !$omp do schedule(static, 1)
+  do i = 1, 10
+  end do
+  !$omp do schedule(static, 0) ! { dg-warning "must be positive" }
+  do i = 1, 10
+  end do
+  !$omp do schedule(static, -7)        ! { dg-warning "must be positive" }
+  do i = 1, 10
+  end do
+end
index b4ae304dabb99700f45f65cf18b553481b429c7b..9dcdda83b5d6e586c8cf9bc34fbc42d8f0251a8a 100644 (file)
@@ -1,3 +1,9 @@
+2016-05-26  Jakub Jelinek  <jakub@redhat.com>
+
+       * testsuite/libgomp.c/doacross-1.c (main): Use schedule(static)
+       instead of invalid schedule(static, 0).
+       * testsuite/libgomp.c/doacross-2.c (main): Likewise.
+
 2016-05-26  Chung-Lin Tang  <cltang@codesourcery.com>
 
        * oacc-plugin.h (GOMP_PLUGIN_async_unmap_vars): Add int parameter.
index 0794c80ec2e99631e95757174a1664412170c978..d27fc00b24bedbaf84975b92783e97441b0d58ca 100644 (file)
@@ -36,7 +36,7 @@ main ()
        #pragma omp atomic write
        a[i] = 3;
       }
-    #pragma omp for schedule(static, 0) ordered (3) nowait
+    #pragma omp for schedule(static) ordered (3) nowait
     for (i = 2; i < N / 16 - 1; i++)
       for (j = 0; j < 8; j += 2)
        for (k = 1; k <= 3; k++)
index e491bb22965164200c5a755f0c5eb48ad51d5771..e147b741a7c4efb4854c580a7318c2b79ad52d82 100644 (file)
@@ -38,7 +38,7 @@ main ()
        #pragma omp atomic write
        a[i] = 3;
       }
-    #pragma omp for schedule(static, 0) ordered (3) nowait
+    #pragma omp for schedule(static) ordered (3) nowait
     for (i = 3; i < N / 16 - 1 + f; i++)
       for (j = 0; j < 8; j += 2)
        for (k = 1; k <= 3; k++)
@@ -120,7 +120,7 @@ main ()
              #pragma omp atomic write
              c[i][j][k] = 3;
            }
-    #pragma omp for schedule(static, 0) ordered (3) nowait
+    #pragma omp for schedule(static) ordered (3) nowait
     for (j = 0; j < N / 16 - 1; j++)
       for (k = 0; k < 8; k += 2)
        for (i = 3; i <= 5 + f; i++)