User account creation filtered due to spam.

Bug 35001 - shape for negative sizes
Summary: shape for negative sizes
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: libfortran (show other bugs)
Version: unknown
: P3 normal
Target Milestone: ---
Assignee: Thomas Koenig
URL:
Keywords: wrong-code
Depends on:
Blocks: 32834
  Show dependency treegraph
 
Reported: 2008-01-28 19:06 UTC by Thomas Koenig
Modified: 2008-02-02 13:51 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2008-01-28 19:08:24


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Thomas Koenig 2008-01-28 19:06:23 UTC
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.
Comment 1 Thomas Koenig 2008-01-31 21:10:28 UTC
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 ;
     }
 }
Comment 2 Jerry DeLisle 2008-02-01 01:37:45 UTC
Thomas, this is OK to commit since it is fixing a wrong code bug, assuming you have regression tested. (Discussed with Richi on IRC.)
Comment 3 Thomas Koenig 2008-02-02 13:51:39 UTC
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

Comment 4 Thomas Koenig 2008-02-02 13:51:45 UTC
(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.