2013-12-01 Paul Thomas <pault@gcc.gnu.org>
authorpault <pault@138bc75d-0d04-0410-961f-82ee72b054a4>
Sun, 1 Dec 2013 11:50:20 +0000 (11:50 +0000)
committerpault <pault@138bc75d-0d04-0410-961f-82ee72b054a4>
Sun, 1 Dec 2013 11:50:20 +0000 (11:50 +0000)
PR fortran/57354
* trans-array.c (gfc_conv_resolve_dependencies): For other than
SS_SECTION, do a dependency check if the lhs is liable to be
reallocated.

2013-12-01  Paul Thomas  <pault@gcc.gnu.org>

PR fortran/57354
* gfortran.dg/realloc_on_assign_23.f90 : New test

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@205567 138bc75d-0d04-0410-961f-82ee72b054a4

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

index 5e4294a..a92561c 100644 (file)
@@ -1,5 +1,12 @@
 2013-12-01  Paul Thomas  <pault@gcc.gnu.org>
 
+       PR fortran/57354
+       * trans-array.c (gfc_conv_resolve_dependencies): For other than
+       SS_SECTION, do a dependency check if the lhs is liable to be
+       reallocated.
+
+2013-12-01  Paul Thomas  <pault@gcc.gnu.org>
+
        PR fortran/58410
        * trans-array.c (gfc_alloc_allocatable_for_assignment): Do not
        use the array bounds of an unallocated array but set its size
index 7e73e23..78b08d7 100644 (file)
@@ -4335,10 +4335,18 @@ gfc_conv_resolve_dependencies (gfc_loopinfo * loop, gfc_ss * dest,
 
   for (ss = rss; ss != gfc_ss_terminator; ss = ss->next)
     {
+      ss_expr = ss->info->expr;
+
       if (ss->info->type != GFC_SS_SECTION)
-       continue;
+       {
+         if (gfc_option.flag_realloc_lhs
+             && dest_expr != ss_expr
+             && gfc_is_reallocatable_lhs (dest_expr)
+             && ss_expr->rank)
+           nDepend = gfc_check_dependency (dest_expr, ss_expr, true);
 
-      ss_expr = ss->info->expr;
+         continue;
+       }
 
       if (dest_expr->symtree->n.sym != ss_expr->symtree->n.sym)
        {
index b63f3de..01a160e 100644 (file)
@@ -1,5 +1,10 @@
 2013-12-01  Paul Thomas  <pault@gcc.gnu.org>
 
+       PR fortran/57354
+       * gfortran.dg/realloc_on_assign_23.f90 : New test
+
+2013-12-01  Paul Thomas  <pault@gcc.gnu.org>
+
        PR fortran/34547
        * gfortran.dg/null_5.f90 : Include new error.
        * gfortran.dg/null_6.f90 : Include new error.
diff --git a/gcc/testsuite/gfortran.dg/realloc_on_assign_23.f90 b/gcc/testsuite/gfortran.dg/realloc_on_assign_23.f90
new file mode 100644 (file)
index 0000000..f9897f1
--- /dev/null
@@ -0,0 +1,30 @@
+! { dg-do run }
+!
+! PR fortran/57354
+!
+! Contributed by Vladimir Fuka  <vladimir.fuka@gmail.com>
+!
+  type t
+    integer,allocatable :: i
+  end type
+
+  type(t) :: e
+  type(t), allocatable :: a(:)
+  integer :: chksum = 0
+
+  do i=1,3   ! Was 100 in original
+    e%i = i
+    chksum = chksum + i
+    if (.not.allocated(a)) then
+      a = [e]
+    else
+      call foo
+    end if
+  end do
+
+  if (sum ([(a(i)%i, i=1,size(a))]) .ne. chksum) call abort
+contains
+  subroutine foo
+    a = [a, e]
+  end subroutine
+end