aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Koenig <tkoenig@gcc.gnu.org>2019-08-12 20:21:37 +0000
committerThomas Koenig <tkoenig@gcc.gnu.org>2019-08-12 20:21:37 +0000
commit393fdeb1e42d9ed78546f350b474183aac463da5 (patch)
tree2896814b1c2ce28c76fee7e3b119024a966c4a0e
parent0124d2c5bb0ac41a6f3288b5f11861c127f13409 (diff)
downloadgcc-393fdeb1e42d9ed78546f350b474183aac463da5.zip
gcc-393fdeb1e42d9ed78546f350b474183aac463da5.tar.gz
gcc-393fdeb1e42d9ed78546f350b474183aac463da5.tar.bz2
re PR fortran/91424 (Extend warnings about DO loops)
2019-08-12 Thomas Koenig <tkoenig@gcc.gnu.org> PR fortran/91424 * frontend-passes.c (do_subscript): Do not warn for an expression a second time. Do not warn about a zero-trip loop. (doloop_warn): Also look at contained namespaces. 2019-08-12 Thomas Koenig <tkoenig@gcc.gnu.org> PR fortran/91424 * gfortran.dg/do_subscript_3.f90: New test. * gfortran.dg/do_subscript_4.f90: New test. * gfortran.dg/pr70754.f90: Use indices that to not overflow. 2019-08-12 Thomas Koenig <tkoenig@gcc.gnu.org> PR fortran/91422 * testsuite/libgomp.oacc-fortran/routine-7.f90: Correct array dimension. From-SVN: r274320
-rw-r--r--gcc/fortran/ChangeLog7
-rw-r--r--gcc/fortran/frontend-passes.c24
-rw-r--r--gcc/testsuite/ChangeLog7
-rw-r--r--gcc/testsuite/gfortran.dg/do_subscript_3.f9022
-rw-r--r--gcc/testsuite/gfortran.dg/do_subscript_4.f9011
-rw-r--r--gcc/testsuite/gfortran.dg/pr70754.f9013
-rw-r--r--libgomp/ChangeLog10
-rw-r--r--libgomp/testsuite/libgomp.oacc-fortran/routine-7.f902
8 files changed, 86 insertions, 10 deletions
diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog
index d554991..05e5ba5 100644
--- a/gcc/fortran/ChangeLog
+++ b/gcc/fortran/ChangeLog
@@ -1,3 +1,10 @@
+2019-08-12 Thomas Koenig <tkoenig@gcc.gnu.org>
+
+ PR fortran/91424
+ * frontend-passes.c (do_subscript): Do not warn for an
+ expression a second time. Do not warn about a zero-trip loop.
+ (doloop_warn): Also look at contained namespaces.
+
2019-08-11 Janne Blomqvist <jb@gcc.gnu.org>
PR fortran/91413
diff --git a/gcc/fortran/frontend-passes.c b/gcc/fortran/frontend-passes.c
index 87df504..37c767f 100644
--- a/gcc/fortran/frontend-passes.c
+++ b/gcc/fortran/frontend-passes.c
@@ -2556,6 +2556,12 @@ do_subscript (gfc_expr **e)
if (in_assoc_list)
return 0;
+ /* We already warned about this. */
+ if (v->do_not_warn)
+ return 0;
+
+ v->do_not_warn = 1;
+
for (ref = v->ref; ref; ref = ref->next)
{
if (ref->type == REF_ARRAY && ref->u.ar.type == AR_ELEMENT)
@@ -2608,7 +2614,6 @@ do_subscript (gfc_expr **e)
else
have_do_start = false;
-
if (dl->ext.iterator->end->expr_type == EXPR_CONSTANT)
{
have_do_end = true;
@@ -2620,6 +2625,17 @@ do_subscript (gfc_expr **e)
if (!have_do_start && !have_do_end)
return 0;
+ /* No warning inside a zero-trip loop. */
+ if (have_do_start && have_do_end)
+ {
+ int sgn, cmp;
+
+ sgn = mpz_cmp_ui (do_step, 0);
+ cmp = mpz_cmp (do_end, do_start);
+ if ((sgn > 0 && cmp < 0) || (sgn < 0 && cmp > 0))
+ break;
+ }
+
/* May have to correct the end value if the step does not equal
one. */
if (have_do_start && have_do_end && mpz_cmp_ui (do_step, 1) != 0)
@@ -2761,6 +2777,12 @@ static void
doloop_warn (gfc_namespace *ns)
{
gfc_code_walker (&ns->code, doloop_code, do_function, NULL);
+
+ for (ns = ns->contained; ns; ns = ns->sibling)
+ {
+ if (ns->code == NULL || ns->code->op != EXEC_BLOCK)
+ doloop_warn (ns);
+ }
}
/* This selction deals with inlining calls to MATMUL. */
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index fc1175f..18dac06 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,10 @@
+2019-08-12 Thomas Koenig <tkoenig@gcc.gnu.org>
+
+ PR fortran/91424
+ * gfortran.dg/do_subscript_3.f90: New test.
+ * gfortran.dg/do_subscript_4.f90: New test.
+ * gfortran.dg/pr70754.f90: Use indices that to not overflow.
+
2019-08-12 Jakub Jelinek <jakub@redhat.com>
PR target/83250
diff --git a/gcc/testsuite/gfortran.dg/do_subscript_3.f90 b/gcc/testsuite/gfortran.dg/do_subscript_3.f90
new file mode 100644
index 0000000..2f62f58
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/do_subscript_3.f90
@@ -0,0 +1,22 @@
+! { dg-do compile }
+! PR fortran/91424
+! Check that only one warning is issued inside blocks, and that
+! warnings are also issued for contained subroutines.
+
+program main
+ real :: a(5)
+ block
+ integer :: j
+ do j=0, 5 ! { dg-warning "out of bounds" }
+ a(j) = 2. ! { dg-warning "out of bounds" }
+ end do
+ end block
+ call x
+contains
+ subroutine x
+ integer :: i
+ do i=1,6 ! { dg-warning "out of bounds" }
+ a(i) = 2. ! { dg-warning "out of bounds" }
+ end do
+ end subroutine x
+end program main
diff --git a/gcc/testsuite/gfortran.dg/do_subscript_4.f90 b/gcc/testsuite/gfortran.dg/do_subscript_4.f90
new file mode 100644
index 0000000..c773fe7
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/do_subscript_4.f90
@@ -0,0 +1,11 @@
+! { dg-do compile }
+! PR 91424 - this used to warn although the DO loop is zero trip.
+program main
+ implicit none
+ integer :: i
+ real :: a(2)
+ do i=1,3,-1
+ a(i) = 2.
+ end do
+ print *,a
+end program main
diff --git a/gcc/testsuite/gfortran.dg/pr70754.f90 b/gcc/testsuite/gfortran.dg/pr70754.f90
index d7e790c..593acf9 100644
--- a/gcc/testsuite/gfortran.dg/pr70754.f90
+++ b/gcc/testsuite/gfortran.dg/pr70754.f90
@@ -18,12 +18,13 @@ contains
integer (ii4), dimension(40,40) :: c
integer i, j
- do i=1,20
- b(i,j) = 123 * a(i,j) + 34 * a(i,j+1) &
- + 34 * a(i,j-1) + a(i+1,j+1) &
- + a(i+1,j-1) + a(i-1,j+1) &
- + a(i-1,j-1)
- c(i,j) = 123
+ j = 10
+ do i=11,30
+ b(i,j) = 123 * a(i,j) + 34 * a(i,j+1) &
+ + 34 * a(i,j-1) + a(i+1,j+1) &
+ + a(i+1,j-1) + a(i-1,j+1) &
+ + a(i-1,j-1)
+ c(i,j) = 123
end do
where ((xyz(:,:,2) /= 0) .and. (c /= 0))
diff --git a/libgomp/ChangeLog b/libgomp/ChangeLog
index 5356d00..a2737c3 100644
--- a/libgomp/ChangeLog
+++ b/libgomp/ChangeLog
@@ -1,3 +1,9 @@
+2019-08-12 Thomas Koenig <tkoenig@gcc.gnu.org>
+
+ PR fortran/91422
+ * testsuite/libgomp.oacc-fortran/routine-7.f90: Correct array
+ dimension.
+
2019-08-08 Jakub Jelinek <jakub@redhat.com>
* target.c (gomp_map_vars_internal): For GOMP_MAP_USE_DEVICE_PTR
@@ -32,9 +38,9 @@
2019-07-23 Steven G. Kargl <kargl@gcc.gnu.org>
- * testsuite/libgomp.fortran/reduction4.f90: Update BOZ usage
+ * testsuite/libgomp.fortran/reduction4.f90: Update BOZ usage.
* testsuite/libgomp.fortran/reduction5.f90: Ditto.
-
+
2019-07-20 Jakub Jelinek <jakub@redhat.com>
* testsuite/libgomp.c-c++-common/loop-1.c: New test.
diff --git a/libgomp/testsuite/libgomp.oacc-fortran/routine-7.f90 b/libgomp/testsuite/libgomp.oacc-fortran/routine-7.f90
index f58a95f..1009f4a 100644
--- a/libgomp/testsuite/libgomp.oacc-fortran/routine-7.f90
+++ b/libgomp/testsuite/libgomp.oacc-fortran/routine-7.f90
@@ -109,7 +109,7 @@ end subroutine gang
subroutine seq (a)
!$acc routine seq
- integer, intent (inout) :: a(M)
+ integer, intent (inout) :: a(N)
integer :: i
do i = 1, N