This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[patch, fortran] Fix PR 80988


Hello world,

the attached patch fixes the PR by not doing a replacement of
(a(i,i),i=1,3) by an array expression (which does not exist).

Regression-tested.  OK for trunk?

Regards

	Thomas

2017-06-09  Thomas Koenig  <tkoenig@gcc.gnu.org>

        PR fortran/80988
        * frontend-passes.c (traverse_io_block):  Also
        check for variables occurring as indices multiple
        time in a single implied DO loop.

2017-06-09  Thomas Koenig  <tkoenig@gcc.gnu.org>

        PR fortran/80988
        * gfortran.dg/implied_do_io_3.f90:  New test.
Index: frontend-passes.c
===================================================================
--- frontend-passes.c	(Revision 249039)
+++ frontend-passes.c	(Arbeitskopie)
@@ -1164,7 +1164,14 @@ traverse_io_block (gfc_code *code, bool *has_reach
 	  /*  Check for (a(k), i=1,4) or ((a(j, i), i=1,4), j=1,4).  */
 	  if (!stack_top || !stack_top->iter
 	      || stack_top->iter->var->symtree != start->symtree)
-	    iters[i] = NULL;
+	    {
+	      /* Check for (a(i,i), i=1,3).  */
+	      for (j=0; j<i; j++)
+		if (iters[j] && iters[j]->var->symtree == start->symtree)
+		  return false;
+
+	      iters[i] = NULL;
+	    }
 	  else
 	    {
 	      iters[i] = stack_top->iter;
! { dg-do run }
! { dg-options "-ffrontend-optimize" }
! PR 80988 - implied do loops with diagonal elements
! were not written correctly
program main
  implicit none
  integer :: i,j,k
  integer, dimension(3,3) :: a
  integer, dimension(3,3,3) :: b
  character(len=40) :: line
  a = reshape([(((i*10+j),i=1,3),j=1,3)], shape(a))
  i = 2147483548
  write (unit=line,fmt='(10I3)') (a(i,i),i=1,3)
  if (line /= ' 11 22 33') call abort
  write (unit=line,fmt='(10I3)') (a(i+1,i+1),i=1,2)
  if (line /= ' 22 33') call abort
  do k=1,3
     do j=1,3
        do i=1,3
           b(i,j,k) = i*100 + j*10 + k
        end do
     end do
  end do
  i = -2147483548
  write (unit=line,fmt='(10I4)') ((b(i,j,i),i=1,3),j=1,3)
  if (line /= ' 111 212 313 121 222 323 131 232 333') call abort
end program main

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]