Hi all!

Proposed patch to PR96726 - ICE with user defined specification function on assumed-rank array.

Patch tested only on x86_64-pc-linux-gnu.

Obvious fix, replace different operator with less than to avoid infinite loop.

Thank you very much.

Best regards,
José Rui


2020-8-20  José Rui Faustino de Sousa  <jrfso...@gmail.com>

 PR fortran/96726
 * expr.c (check_references): Change different relational operator to
 less-than operator to avoid infinite loop.

2020-8-20  José Rui Faustino de Sousa  <jrfso...@gmail.com>

 PR fortran/96726
 * PR96726.f90: New test.
diff --git a/gcc/fortran/expr.c b/gcc/fortran/expr.c
index 6707ca5..2ef01f0 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 0000000..b0b26b9
--- /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

Reply via email to