This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[patch, libfortran] PR 38135, RESHAPE, empty SOURCE with PAD


Hello world,

as mentioned in the PR, here's a fix for the f95 part of PR 38135.
Regression-tested on i686-pc-linux-gnu.

OK for trunk?  What about 4.3?

	Thomas

2008-11-18  Thomas Koenig  <tkoenig@gcc.gnu.org>

	PR libfortran/38135
	* m4/reshape.m4:  Correct bounds checking when PAD is present.
	Treat PAD as if it were SOURCE when SOURCE is empty.
	* intrinsics/reshape_generic.c:  Likewise.
	* generated/reshape_c10.c Regenerated.
	* generated/reshape_c16.c Regenerated.
	* generated/reshape_c4.c Regenerated.
	* generated/reshape_c8.c Regenerated.
	* generated/reshape_i16.c Regenerated.
	* generated/reshape_i4.c Regenerated.
	* generated/reshape_i8.c Regenerated.
	* generated/reshape_r10.c Regenerated.
	* generated/reshape_r16.c Regenerated.
	* generated/reshape_r4.c Regenerated.
	* generated/reshape_r8.c Regenerated.

2008-11-18  Thomas Koenig  <tkoenig@gcc.gnu.org>

	PR libfortran/38135
	* gfortran.dg/reshape_pad_1.f90:  New test case

! { dg-do run }
! PR 38135 - pad to RESHAPE didn't work correctly when SOURCE
! was an empty array.

program main
  implicit none
  integer, parameter :: N = 3
  integer(kind=1) :: A1(N,N)
  integer(kind=1) :: b1(n+1)
  integer(kind=4) :: A4(n,n)
  integer(kind=4) :: b4(n+1)
  character(len=9) :: line

  b1 = (/ 1, 2, 2, 2 /)

  A1(1:N,1:N)=reshape(A1(1:0,1),(/N,N/),b1)
  write(unit=line,fmt='(100i1)') A1
  if (line .ne. "122212221") call abort

  b4 = (/ 3, 4, 4, 4 /)

  a4 = reshape(a4(:0,1),(/n,n/),b4)
  write(unit=line,fmt='(100i1)') a4
  if (line .ne. "344434443") call abort
end program main
Index: m4/reshape.m4
===================================================================
--- m4/reshape.m4	(revision 141326)
+++ m4/reshape.m4	(working copy)
@@ -141,7 +141,7 @@ reshape_'rtype_ccode` ('rtype` * const r
 
       source_extent = source->dim[0].ubound + 1 - source->dim[0].lbound;
 
-      if (rs != source_extent)
+      if (rs < source_extent || (rs > source_extent && !pad))
 	runtime_error("Incorrect size in SOURCE argument to RESHAPE"
 		      " intrinsic: is %ld, should be %ld",
 		      (long int) source_extent, (long int) rs);
@@ -266,16 +266,16 @@ reshape_'rtype_ccode` ('rtype` * const r
 
   if (sempty)
     {
-      /* Switch immediately to the pad array.  */
+      /* Pretend we are using the pad array the first time around, too.  */
       src = pptr;
-      sptr = NULL;
+      sptr = pptr;
       sdim = pdim;
       for (dim = 0; dim < pdim; dim++)
 	{
 	  scount[dim] = pcount[dim];
 	  sextent[dim] = pextent[dim];
 	  sstride[dim] = pstride[dim];
-	  sstride0 = sstride[0] * sizeof ('rtype_name`);
+	  sstride0 = pstride[0];
 	}
     }
 
Index: intrinsics/reshape_generic.c
===================================================================
--- intrinsics/reshape_generic.c	(revision 141326)
+++ intrinsics/reshape_generic.c	(working copy)
@@ -126,7 +126,7 @@ reshape_internal (parray *ret, parray *s
 
       source_extent = source->dim[0].ubound + 1 - source->dim[0].lbound;
 
-      if (rs != source_extent)
+      if (rs < source_extent || (rs > source_extent && !pad))
 	runtime_error("Incorrect size in SOURCE argument to RESHAPE"
 		      " intrinsic: is %ld, should be %ld",
 		      (long int) source_extent, (long int) rs);
@@ -249,16 +249,16 @@ reshape_internal (parray *ret, parray *s
 
   if (sempty)
     {
-      /* Switch immediately to the pad array.  */
+      /* Pretend we are using the pad array the first time around, too.  */
       src = pptr;
-      sptr = NULL;
+      sptr = pptr;
       sdim = pdim;
       for (dim = 0; dim < pdim; dim++)
 	{
 	  scount[dim] = pcount[dim];
 	  sextent[dim] = pextent[dim];
 	  sstride[dim] = pstride[dim];
-	  sstride0 = sstride[0] * size;
+	  sstride0 = pstride[0] * size;
 	}
     }
 

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]