Hi! While porting doacross-1.c testcase to Fortran, I've discovered that I've used there schedule(static, 0), which is invalid (I've meant schedule(static) instead). This patch adds warning for this for all FEs.
Bootstrapped/regtested on x86_64-linux and i686-linux, committed to trunk. 2016-05-26 Jakub Jelinek <ja...@redhat.com> * 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. --- gcc/c/c-parser.c.jj 2016-05-26 10:37:53.000000000 +0200 +++ gcc/c/c-parser.c 2016-05-26 13:36:21.443785799 +0200 @@ -12128,7 +12128,20 @@ c_parser_omp_clause_schedule (c_parser * "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"); --- gcc/cp/semantics.c.jj 2016-05-26 10:38:01.000000000 +0200 +++ gcc/cp/semantics.c 2016-05-26 19:09:16.989908218 +0200 @@ -6326,6 +6326,17 @@ finish_omp_clauses (tree clauses, enum c 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; --- gcc/fortran/openmp.c.jj 2016-05-05 15:30:29.000000000 +0200 +++ gcc/fortran/openmp.c 2016-05-26 13:27:49.865524212 +0200 @@ -3259,6 +3259,11 @@ resolve_omp_clauses (gfc_code *code, gfc || 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 --- gcc/testsuite/c-c++-common/gomp/schedule-1.c.jj 2016-05-26 13:32:04.566169067 +0200 +++ gcc/testsuite/c-c++-common/gomp/schedule-1.c 2016-05-26 13:37:30.638874653 +0200 @@ -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++) + ; +} --- gcc/testsuite/gfortran.dg/gomp/schedule-1.f90.jj 2016-05-26 13:32:57.556471031 +0200 +++ gcc/testsuite/gfortran.dg/gomp/schedule-1.f90 2016-05-26 13:39:07.357601082 +0200 @@ -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 --- libgomp/testsuite/libgomp.c/doacross-1.c.jj 2015-10-13 20:57:41.000000000 +0200 +++ libgomp/testsuite/libgomp.c/doacross-1.c 2016-05-26 13:40:09.698780187 +0200 @@ -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++) --- libgomp/testsuite/libgomp.c/doacross-2.c.jj 2015-10-13 20:57:41.000000000 +0200 +++ libgomp/testsuite/libgomp.c/doacross-2.c 2016-05-26 13:43:18.794290218 +0200 @@ -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++) Jakub