This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug fortran/52012] [4.6/4.7 Regression] Wrong-code with realloc on assignment and RESHAPE w/ ORDER=
- From: "burnus at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Fri, 27 Jan 2012 09:18:10 +0000
- Subject: [Bug fortran/52012] [4.6/4.7 Regression] Wrong-code with realloc on assignment and RESHAPE w/ ORDER=
- Auto-submitted: auto-generated
- References: <bug-52012-4@http.gcc.gnu.org/bugzilla/>
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52012
Tobias Burnus <burnus at gcc dot gnu.org> 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 <burnus at gcc dot gnu.org> 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