From: José Rui Faustino de Sousa Date: Sun, 30 Aug 2020 17:58:13 +0000 (+0000) Subject: 2020-8-20 José Rui Faustino de Sousa X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=8f7d99acf6d94eed6a7f9b9f76bd4c2243c660b2;p=gcc.git 2020-8-20 José Rui Faustino de Sousa 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. --- 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