From: Jakub Jelinek Date: Thu, 26 May 2016 19:12:27 +0000 (+0200) Subject: c-parser.c (c_parser_omp_clause_schedule): Warn if OMP_CLAUSE_SCHEDULE_CHUNK_EXPR... X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=7211a0975c25b21baa8e31ebc2946f4d6d136fed;p=gcc.git c-parser.c (c_parser_omp_clause_schedule): Warn if OMP_CLAUSE_SCHEDULE_CHUNK_EXPR is known not to be positive. * 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) : 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 --- diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog index f3bb0e9d58a..f7d1a6d582e 100644 --- a/gcc/c/ChangeLog +++ b/gcc/c/ChangeLog @@ -1,3 +1,8 @@ +2016-05-26 Jakub Jelinek + + * 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 PR c/71265 diff --git a/gcc/c/c-parser.c b/gcc/c/c-parser.c index 1cf4fb452aa..fda2df8e44e 100644 --- a/gcc/c/c-parser.c +++ b/gcc/c/c-parser.c @@ -12128,7 +12128,20 @@ c_parser_omp_clause_schedule (c_parser *parser, tree list) "schedule % does not take " "a % 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"); diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index ff5d8f4825c..770f817eeca 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,8 @@ +2016-05-26 Jakub Jelinek + + * semantics.c (finish_omp_clauses) : Warn + if OMP_CLAUSE_SCHEDULE_CHUNK_EXPR is known not to be positive. + 2016-05-26 Patrick Palka PR c++/70822 diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index 0cef86758f8..253d31a4f4a 100644 --- a/gcc/cp/semantics.c +++ b/gcc/cp/semantics.c @@ -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; diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index 8db70173d27..73235c6d31c 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,8 @@ +2016-05-26 Jakub Jelinek + + * openmp.c (resolve_omp_clauses): Warn if chunk_size is known not to + be positive. + 2016-05-23 Jerry DeLisle PR fortran/66461 diff --git a/gcc/fortran/openmp.c b/gcc/fortran/openmp.c index 1481719f6e6..2689d302c77 100644 --- a/gcc/fortran/openmp.c +++ b/gcc/fortran/openmp.c @@ -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 diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 962421200cd..f2a7a56bf05 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2016-05-26 Jakub Jelinek + + * c-c++-common/gomp/schedule-1.c: New test. + * gfortran.dg/gomp/schedule-1.f90: New test. + 2016-05-26 Patrick Palka 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 index 00000000000..8700ff6772e --- /dev/null +++ b/gcc/testsuite/c-c++-common/gomp/schedule-1.c @@ -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 index 00000000000..3d64294282b --- /dev/null +++ b/gcc/testsuite/gfortran.dg/gomp/schedule-1.f90 @@ -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 diff --git a/libgomp/ChangeLog b/libgomp/ChangeLog index b4ae304dabb..9dcdda83b5d 100644 --- a/libgomp/ChangeLog +++ b/libgomp/ChangeLog @@ -1,3 +1,9 @@ +2016-05-26 Jakub Jelinek + + * 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 * oacc-plugin.h (GOMP_PLUGIN_async_unmap_vars): Add int parameter. diff --git a/libgomp/testsuite/libgomp.c/doacross-1.c b/libgomp/testsuite/libgomp.c/doacross-1.c index 0794c80ec2e..d27fc00b24b 100644 --- a/libgomp/testsuite/libgomp.c/doacross-1.c +++ b/libgomp/testsuite/libgomp.c/doacross-1.c @@ -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++) diff --git a/libgomp/testsuite/libgomp.c/doacross-2.c b/libgomp/testsuite/libgomp.c/doacross-2.c index e491bb22965..e147b741a7c 100644 --- a/libgomp/testsuite/libgomp.c/doacross-2.c +++ b/libgomp/testsuite/libgomp.c/doacross-2.c @@ -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++)