From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 482 invoked by alias); 27 Jan 2012 09:18:43 -0000 Received: (qmail 470 invoked by uid 22791); 27 Jan 2012 09:18:42 -0000 X-SWARE-Spam-Status: No, hits=-2.9 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00 X-Spam-Check-By: sourceware.org Received: from localhost (HELO gcc.gnu.org) (127.0.0.1) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 27 Jan 2012 09:18:29 +0000 From: "burnus at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug fortran/52012] [4.6/4.7 Regression] Wrong-code with realloc on assignment and RESHAPE w/ ORDER= Date: Fri, 27 Jan 2012 10:06: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-Keywords: wrong-code X-Bugzilla-Severity: critical X-Bugzilla-Who: burnus at gcc dot gnu.org X-Bugzilla-Status: NEW X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: 4.6.3 X-Bugzilla-Changed-Fields: Summary Message-ID: In-Reply-To: References: X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" MIME-Version: 1.0 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 X-SW-Source: 2012-01/txt/msg03094.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52012 Tobias Burnus changed: What |Removed |Added ---------------------------------------------------------------------------- Summary|[4.6/4.7 Regression] |[4.6/4.7 Regression] |Wrong-code with realloc on |Wrong-code with realloc on |assignment |assignment and RESHAPE w/ | |ORDER= --- Comment #4 from Tobias Burnus 2012-01-27 09:18:10 UTC --- Up and including the RESHAPE call, everything looks fine. However, one then updates the bounds as follows, which seems to fail. If one does not use RESHAPE with the ORDER= argument, it works that the "shape(a)" is used as argument to RESHAPE does not play a role. a.offset = 1; a.dim[0].lbound = 1; a.dim[0].ubound = a.dim[0].ubound + 1; a.offset = (a.dim[0].ubound - a.dim[0].lbound) + 1; a.dim[1].lbound = 1; a.dim[1].ubound = a.dim[1].ubound + 1; a.offset = (a.dim[1].ubound - a.dim[1].lbound) + 1; a.dim[2].lbound = 1; a.dim[2].ubound = a.dim[2].ubound + 1; a.offset = ~((a.dim[0].ubound - a.dim[0].lbound) + 1) + ~(a.dim[1].ubound - a.dim[1].lbound); * * * Additionally, the realloc on assignment may sets the wrong bounds if no (re)allocation is needed. From trans-expr.c's fcncall_realloc_result: /* Now reset the bounds from zero based to unity based. */ That's wrong. The lower bounds are remain the same, unless the RHS has a different shape. Then, the LHS is reallocated with a lower bound of lbound(RHS). Thus, one expects "7 9 / 1 3" for the program below, but gfortran has "1 3 / 1 3". Using for the RHS external functions, other expressions and variables correctly keep the bounds, if no realloc happens. integer, allocatable :: a(:), b(:) allocate(b(3)) b = [1,2,3] allocate (a(7:9)) a = reshape( b, shape=[size(b)]) print *, lbound(a), ubound(a) ! Expected: 7 9 deallocate (a) a = reshape( b, shape=[size(b)]) print *, lbound(a), ubound(a) ! Expected: 1 3 end