From: Paul Thomas Date: Sun, 1 Dec 2013 11:50:20 +0000 (+0000) Subject: re PR fortran/57354 (Wrong run-time assignment of allocatable array of derived type... X-Git-Tag: releases/gcc-4.9.0~2343 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=343ab49260fd5f88e228df6a38cb27b19fb9045f;p=thirdparty%2Fgcc.git re PR fortran/57354 (Wrong run-time assignment of allocatable array of derived type with allocatable component) 2013-12-01 Paul Thomas 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 PR fortran/57354 * gfortran.dg/realloc_on_assign_23.f90 : New test From-SVN: r205567 --- diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index 5e4294a930a0..a92561cf5653 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,10 @@ +2013-12-01 Paul Thomas + + 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 PR fortran/58410 diff --git a/gcc/fortran/trans-array.c b/gcc/fortran/trans-array.c index 7e73e23a77ec..78b08d70951e 100644 --- a/gcc/fortran/trans-array.c +++ b/gcc/fortran/trans-array.c @@ -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) { diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index b63f3de24842..01a160e9dcf7 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2013-12-01 Paul Thomas + + PR fortran/57354 + * gfortran.dg/realloc_on_assign_23.f90 : New test + 2013-12-01 Paul Thomas PR fortran/34547 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 index 000000000000..f9897f17401e --- /dev/null +++ b/gcc/testsuite/gfortran.dg/realloc_on_assign_23.f90 @@ -0,0 +1,30 @@ +! { dg-do run } +! +! PR fortran/57354 +! +! Contributed by Vladimir Fuka +! + 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