From PR 34980, comment#7 by Tobias Burnus: a) The following should print "1 0" but it prints "1 -8": integer :: i,j, a(10,10),res(2) j = 1 i = 10 res = shape(a(1:1,i:j:1)) print *, res res = shape(a(1:1,j:i:-1)) print *, res end Not a regression.
A patch for when trunk reopens. Index: m4/shape.m4 =================================================================== --- m4/shape.m4 (revision 131915) +++ m4/shape.m4 (working copy) @@ -46,6 +46,7 @@ shape_'rtype_kind` ('rtype` * const rest { int n; index_type stride; + index_type extent; stride = ret->dim[0].stride; @@ -54,8 +55,8 @@ shape_'rtype_kind` ('rtype` * const rest for (n = 0; n < GFC_DESCRIPTOR_RANK (array); n++) { - ret->data[n * stride] = - array->dim[n].ubound + 1 - array->dim[n].lbound; + extent = array->dim[n].ubound + 1 - array->dim[n].lbound; + ret->data[n * stride] = extent > 0 ? extent : 0 ; } }
Thomas, this is OK to commit since it is fixing a wrong code bug, assuming you have regression tested. (Discussed with Richi on IRC.)
Subject: Bug 35001 Author: tkoenig Date: Sat Feb 2 13:50:55 2008 New Revision: 132070 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=132070 Log: 2008-02-02 Thomas Koenig <tkoenig@gcc.gnu.org> PR libfortran/35001 * m4/shape.m4: Return 0 for extents <= 0. * generated/shape_i4.c: Regenerated. * generated/shape_i8.c: Regenerated. * generated/shape_i16.c: Regenerated. 2008-02-02 Thomas Koenig <tkoenig@gcc.gnu.org> PR libfortran/35001 * gfortran.dg/shape_4.f90: New test. Fixed in regression-only mode by special dispense (see the PR). Added: trunk/gcc/testsuite/gfortran.dg/shape_4.f90 Modified: trunk/gcc/testsuite/ChangeLog trunk/libgfortran/ChangeLog trunk/libgfortran/generated/shape_i16.c trunk/libgfortran/generated/shape_i4.c trunk/libgfortran/generated/shape_i8.c trunk/libgfortran/m4/shape.m4
(In reply to comment #2) > Thomas, this is OK to commit since it is fixing a wrong code bug, assuming you > have regression tested. (Discussed with Richi on IRC.) Yes, I had done so. Commited to trunk. Thanks! Closing.