diff mbox

[fortran] Fix PR 46007, segfault with shape

Message ID 1287661047.3660.12.camel@linux-fd1f.site
State New
Headers show

Commit Message

Thomas Koenig Oct. 21, 2010, 11:37 a.m. UTC
Hello world,

this rather straightforward patch fixes PR 46007.

Regression-tested on trunk.  OK for trunk?  Also OK for 4.5 after
regression-testing there?

	Thomas

2010-10-21  Thomas Koenig  <tkoenig@gcc.gnu.org>

	PR fortran/46007
	* m4/shape.m4 (shape_'rtype_kind`):  Use variable for rank.
	Allocate return array if unallocated.
	* generated/shape_i4.c:  Regenerated.
	* generated/shape_i8.c:  Regenerated.
	* generated/shape_i16.c:  Regenerated.

2010-10-21  Thomas Koenig  <tkoenig@gcc.gnu.org>

	PR fortran/46007
	* gfortran.dg/shape_5.f90:  New test case.

Comments

Tobias Burnus Oct. 21, 2010, 11:44 a.m. UTC | #1
On 10/21/2010 01:37 PM, Thomas Koenig wrote:
> this rather straightforward patch fixes PR 46007.
>
> Regression-tested on trunk.  OK for trunk?  Also OK for 4.5 after
> regression-testing there?

OK. Thanks for the patch!

Tobias

> 2010-10-21  Thomas Koenig<tkoenig@gcc.gnu.org>
>
> 	PR fortran/46007
> 	* m4/shape.m4 (shape_'rtype_kind`):  Use variable for rank.
> 	Allocate return array if unallocated.
> 	* generated/shape_i4.c:  Regenerated.
> 	* generated/shape_i8.c:  Regenerated.
> 	* generated/shape_i16.c:  Regenerated.
>
> 2010-10-21  Thomas Koenig<tkoenig@gcc.gnu.org>
>
> 	PR fortran/46007
> 	* gfortran.dg/shape_5.f90:  New test case.
>
Thomas Koenig Oct. 21, 2010, 1:04 p.m. UTC | #2
Am Donnerstag, den 21.10.2010, 13:44 +0200 schrieb Tobias Burnus:
> On 10/21/2010 01:37 PM, Thomas Koenig wrote:
> > this rather straightforward patch fixes PR 46007.
> >
> > Regression-tested on trunk.  OK for trunk?  Also OK for 4.5 after
> > regression-testing there?
> 
> OK. Thanks for the patch!
> 
> Tobias
> 
> > 2010-10-21  Thomas Koenig<tkoenig@gcc.gnu.org>
> >
> > 	PR fortran/46007
> > 	* m4/shape.m4 (shape_'rtype_kind`):  Use variable for rank.
> > 	Allocate return array if unallocated.
> > 	* generated/shape_i4.c:  Regenerated.
> > 	* generated/shape_i8.c:  Regenerated.
> > 	* generated/shape_i16.c:  Regenerated.
> >
> > 2010-10-21  Thomas Koenig<tkoenig@gcc.gnu.org>
> >
> > 	PR fortran/46007
> > 	* gfortran.dg/shape_5.f90:  New test case.
> >
> 

Committed to trunk as revision 165770.
Committed to 4.5 as revision 165773.

Thanks for the review!

	Thomas
diff mbox

Patch

Index: m4/shape.m4
===================================================================
--- m4/shape.m4	(Revision 165561)
+++ m4/shape.m4	(Arbeitskopie)
@@ -42,13 +42,23 @@  shape_'rtype_kind` ('rtype` * const restrict ret,
   int n;
   index_type stride;
   index_type extent;
+  int rank;
 
+  rank = GFC_DESCRIPTOR_RANK (array);
+
+  if (ret->data == NULL)
+    {
+      GFC_DIMENSION_SET(ret->dim[0], 0, rank - 1, 1);
+      ret->offset = 0;
+      ret->data = internal_malloc_size (sizeof ('rtype_name`) * rank);
+    }
+
   stride = GFC_DESCRIPTOR_STRIDE(ret,0);
 
   if (GFC_DESCRIPTOR_EXTENT(ret,0) < 1)
     return;
 
-  for (n = 0; n < GFC_DESCRIPTOR_RANK (array); n++)
+  for (n = 0; n < rank; n++)
     {
       extent = GFC_DESCRIPTOR_EXTENT(array,n);
       ret->data[n * stride] = extent > 0 ? extent : 0 ;