From 8f7d99acf6d94eed6a7f9b9f76bd4c2243c660b2 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jos=C3=A9=20Rui=20Faustino=20de=20Sousa?= Date: Sun, 30 Aug 2020 17:58:13 +0000 Subject: [PATCH] =?utf8?q?=092020-8-20=20=20Jos=C3=A9=20Rui=20Faustino=20d?= =?utf8?q?e=20Sousa=20=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit gcc/fortran/ChangeLog: PR fortran/96726 * expr.c (check_references): Change different relational operator to less-than operator to avoid infinite loop. gcc/testsuite/ChangeLog: PR fortran/96726 * gfortran.dg/PR96726.f90: New test. --- gcc/fortran/expr.c | 2 +- gcc/testsuite/gfortran.dg/PR96726.f90 | 72 +++++++++++++++++++++++++++ 2 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gfortran.dg/PR96726.f90 diff --git a/gcc/fortran/expr.c b/gcc/fortran/expr.c index 6707ca550a0..2ef01f0f14f 100644 --- a/gcc/fortran/expr.c +++ b/gcc/fortran/expr.c @@ -3273,7 +3273,7 @@ check_references (gfc_ref* ref, bool (*checker) (gfc_expr*)) switch (ref->type) { case REF_ARRAY: - for (dim = 0; dim != ref->u.ar.dimen; ++dim) + for (dim = 0; dim < ref->u.ar.dimen; ++dim) { if (!checker (ref->u.ar.start[dim])) return false; diff --git a/gcc/testsuite/gfortran.dg/PR96726.f90 b/gcc/testsuite/gfortran.dg/PR96726.f90 new file mode 100644 index 00000000000..b0b26b90669 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/PR96726.f90 @@ -0,0 +1,72 @@ +! { dg-do run } +! +! Test the fix for PR96726 +! + +module cref_m + + implicit none + + private + + public :: & + sizeish + +contains + + pure function sizeish(a) result(s) + integer, intent(in) :: a(..) + + integer :: s + + s = size(a) + return + end function sizeish + +end module cref_m + +program cref_p + + use cref_m, only: & + sizeish + + implicit none + + integer :: i + + integer, parameter :: n = 3 + integer, parameter :: p(*) = [(i, i=1,n*n)] + + integer :: a(n,n) + integer :: b(n*n) + + a = reshape(p, shape=[n,n]) + call isub_a(a, b) + if (any(b/=p)) stop 1 + call isub_b(a, b) + if (any(b/=p)) stop 2 + stop + +contains + + subroutine isub_a(a, b) + integer, intent(in) :: a(..) + integer, intent(out) :: b(size(a)) + + integer :: i + + b = [(i, i=1,size(b))] + return + end subroutine isub_a + + subroutine isub_b(a, b) + integer, intent(in) :: a(..) + integer, intent(out) :: b(sizeish(a)) + + integer :: i + + b = [(i, i=1,sizeish(b))] + return + end subroutine isub_b + +end program cref_p -- 2.30.2