From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 20745 invoked by alias); 23 Nov 2013 14:02:51 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org Received: (qmail 20695 invoked by uid 48); 23 Nov 2013 14:02:48 -0000 From: "pault at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug fortran/57354] Wrong run-time assignment of allocatable array of derived type with allocatable component Date: Sat, 23 Nov 2013 14:02:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: fortran X-Bugzilla-Version: 4.8.0 X-Bugzilla-Keywords: wrong-code X-Bugzilla-Severity: normal X-Bugzilla-Who: pault at gcc dot gnu.org X-Bugzilla-Status: NEW X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: pault at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_status cf_reconfirmed_on assigned_to everconfirmed attachments.created Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-SW-Source: 2013-11/txt/msg02407.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57354 Paul Thomas changed: What |Removed |Added ---------------------------------------------------------------------------- Status|UNCONFIRMED |NEW Last reconfirmed| |2013-11-23 Assignee|unassigned at gcc dot gnu.org |pault at gcc dot gnu.org Ever confirmed|0 |1 --- Comment #3 from Paul Thomas --- Created attachment 31280 --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=31280&action=edit Preliminary patch This patch is preliminary since a temporary is produced, for each assignment, copied to the newly reallocated lhs and then deallocated. Clearly it would be more efficient to deallocate the lhs and then point the lhs to the temporary. My first attempt to do this segfaulted because the temporary was still deleted, in spite of my attempt to suppress it! I will persevere. The test case will be along the following lines: ! { 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 Note that 'foo' is for diagnostic purposes - the code is separated nicely. Cheers Paul