Dear All, This is a partial fix for this problem in that it generates a temporary to provide a correct assignment but then goes on to do an unnecessary reallocation of the lhs. That is to say, the temporary could be taken over by the array descriptor. At the moment, I could not see a good way to do this. I propose to change the PR to reflect this. I will retain the PR and will have another go at suppressing the reallocation in a few weeks time.
Bootstrapped and regtested on Fc17/x86_64 - OK for trunk? Cheers Paul 2013-11-30 Paul Thomas <pa...@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-11-30 Paul Thomas <pa...@gcc.gnu.org> PR fortran/57354 * gfortran.dg/realloc_on_assign_23.f90 : New test
Index: gcc/fortran/trans-array.c =================================================================== *** gcc/fortran/trans-array.c (revision 205031) --- gcc/fortran/trans-array.c (working copy) *************** gfc_conv_resolve_dependencies (gfc_loopi *** 4335,4344 **** for (ss = rss; ss != gfc_ss_terminator; ss = ss->next) { if (ss->info->type != GFC_SS_SECTION) ! continue; ! ss_expr = ss->info->expr; if (dest_expr->symtree->n.sym != ss_expr->symtree->n.sym) { --- 4335,4352 ---- for (ss = rss; ss != gfc_ss_terminator; ss = ss->next) { + ss_expr = ss->info->expr; + if (ss->info->type != GFC_SS_SECTION) ! { ! 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); ! continue; ! } if (dest_expr->symtree->n.sym != ss_expr->symtree->n.sym) { Index: gcc/testsuite/gfortran.dg/realloc_on_assign_23.f90 =================================================================== *** gcc/testsuite/gfortran.dg/realloc_on_assign_23.f90 (revision 0) --- gcc/testsuite/gfortran.dg/realloc_on_assign_23.f90 (working copy) *************** *** 0 **** --- 1,30 ---- + ! { dg-do run } + ! + ! PR fortran/57354 + ! + ! Contributed by Vladimir Fuka <vladimir.f...@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