re PR fortran/66102 (dependency mishandling with reallocation on assignment)
authorThomas Koenig <tkoenig@gcc.gnu.org>
Mon, 24 Jul 2017 09:50:28 +0000 (09:50 +0000)
committerThomas Koenig <tkoenig@gcc.gnu.org>
Mon, 24 Jul 2017 09:50:28 +0000 (09:50 +0000)
2017-07-24  Thomas Koenig  <tkoenig@gcc.gnu.org>
    Mikael Morin <mikael@gcc.gnu.org>

PR fortran/66102
* fortran/trans-array.c (gfc_conv_resolve_dependencies):
Break if dependency has been found.

2017-07-24  Thomas Koenig  <tkoenig@gcc.gnu.org>
    Mikael Morin <mikael@gcc.gnu.org>

PR fortran/66102
* gfortran.dg/realloc_on_assign_28.f90:  New test.

Co-Authored-By: Mikael Morin <mikael@gcc.gnu.org>
From-SVN: r250471

gcc/fortran/ChangeLog
gcc/fortran/trans-array.c
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/realloc_on_assign_28.f90 [new file with mode: 0644]

index 048a835d7fc2f8d1820414b3f639d7164b02247f..96b445afb79cae97da90a3ec4ab9e3dcc0dcd52f 100644 (file)
@@ -1,3 +1,10 @@
+2017-07-24  Thomas Koenig  <tkoenig@gcc.gnu.org>
+           Mikael Morin <mikael@gcc.gnu.org>
+
+       PR fortran/66102
+       * fortran/trans-array.c (gfc_conv_resolve_dependencies):
+       Break if dependency has been found.
+
 2017-07-23  Alexander Monakov  <amonakov@ispras.ru>
 
        * interface.c (pair_cmp): Fix gfc_symbol comparison.  Adjust comment.
index 47e8c091a9b08b343a4bc3045edc1abdb38fa06f..9efb531a7221bcaa403f5281b3759ecfe35ef516 100644 (file)
@@ -4577,7 +4577,10 @@ gfc_conv_resolve_dependencies (gfc_loopinfo * loop, gfc_ss * dest,
              && gfc_check_dependency (dest_expr, ss_expr, false))
            ss_info->data.scalar.needs_temporary = 1;
 
-         continue;
+         if (nDepend)
+           break;
+         else
+           continue;
        }
 
       if (dest_expr->symtree->n.sym != ss_expr->symtree->n.sym)
index fa5733ed23a6e2d3313ae755ce23ff66fdb7bc9d..b1e5730db7e1cc7a8d5d3f674a6edfb46e25c721 100644 (file)
@@ -1,3 +1,9 @@
+2017-07-24  Thomas Koenig  <tkoenig@gcc.gnu.org>
+           Mikael Morin <mikael@gcc.gnu.org>
+
+       PR fortran/66102
+       * gfortran.dg/realloc_on_assign_28.f90:  New test.
+
 2017-07-23  David Edelsohn  <dje.gcc@gmail.com>
 
        * gcc.dg/pr56727-2.c: Limit to powerpc-linux.
diff --git a/gcc/testsuite/gfortran.dg/realloc_on_assign_28.f90 b/gcc/testsuite/gfortran.dg/realloc_on_assign_28.f90
new file mode 100644 (file)
index 0000000..2e338e4
--- /dev/null
@@ -0,0 +1,40 @@
+! { dg-do run }
+!
+! PR fortran/66102
+!
+! Contributed by Vladimir Fuka  <vladimir.fuka@gmail.com>
+!
+  type t
+    integer,allocatable :: i
+  end type
+
+  type(t) :: e
+  type(t), allocatable, dimension(:) :: a, b
+  integer :: chksum = 0
+
+  do i=1,3   ! Was 100 in original
+    e%i = i
+    chksum = chksum + i
+    if (.not.allocated(a)) then
+      a = [e]
+      b = first_arg([e], [e])
+    else
+      call foo
+    end if
+  end do
+
+  if (sum ([(a(i)%i, i=1,size(a))]) .ne. chksum) call abort
+  if (any([(a(i)%i, i=1,size(a))] /= [(i, i=1,size(a))])) call abort
+  if (size(a) /= size(b)) call abort
+  if (any([(b(i)%i, i=1,size(b))] /= [(i, i=1,size(b))])) call abort
+contains
+  subroutine foo
+    b = first_arg([b, e], [a, e])
+    a = [a, e]
+  end subroutine
+  elemental function first_arg(arg1, arg2)
+    type(t), intent(in) :: arg1, arg2
+    type(t)             :: first_arg
+    first_arg = arg1
+  end function first_arg
+end