2005-06-25 Thomas Koenig <Thomas.Koenig@online.de>
authortkoenig <tkoenig@138bc75d-0d04-0410-961f-82ee72b054a4>
Sat, 25 Jun 2005 09:56:37 +0000 (09:56 +0000)
committertkoenig <tkoenig@138bc75d-0d04-0410-961f-82ee72b054a4>
Sat, 25 Jun 2005 09:56:37 +0000 (09:56 +0000)
        PR libfortran/22144
        * m4/cshift1.m4: Remove const from argument ret.
        Populate return array descriptor if ret->data is NULL.
        * m4/eoshift1.m4: Likewise.
        * m4/eoshift3.m4: Likewise.
        * generated/cshift1_4.c:  Regenerated.
        * generated/cshift1_8.c:  Regenerated.
        * generated/eoshift1_4.c:  Regenerated.
        * generated/eoshift1_8.c:  Regenerated.
        * generated/eoshift3_4.c:  Regenerated.
        * generated/eoshift3_8.c:  Regenerated.

2005-06-25  Thomas Koenig <Thomas.Koenig@online.de>

        PR libfortran/21144
        * gfortran.dg/shift-alloc.f90:  New testcase.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@101318 138bc75d-0d04-0410-961f-82ee72b054a4

12 files changed:
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/shift-alloc.f90 [new file with mode: 0644]
libgfortran/ChangeLog
libgfortran/generated/cshift1_4.c
libgfortran/generated/cshift1_8.c
libgfortran/generated/eoshift1_4.c
libgfortran/generated/eoshift1_8.c
libgfortran/generated/eoshift3_4.c
libgfortran/generated/eoshift3_8.c
libgfortran/m4/cshift1.m4
libgfortran/m4/eoshift1.m4
libgfortran/m4/eoshift3.m4

index 70b830b..419e012 100644 (file)
@@ -1,3 +1,8 @@
+2005-06-25  Thomas Koenig <Thomas.Koenig@online.de>
+
+       PR libfortran/21144
+       * gfortran.dg/shift-alloc.f90:  New testcase.
+
 2005-06-25  Kelley Cook  <kcook@gcc.gnu.org>
 
        * all files: Update FSF address in copyright headers.
diff --git a/gcc/testsuite/gfortran.dg/shift-alloc.f90 b/gcc/testsuite/gfortran.dg/shift-alloc.f90
new file mode 100644 (file)
index 0000000..2d66031
--- /dev/null
@@ -0,0 +1,18 @@
+! { dg do-run }
+! PR 22144: eoshift1, eoshift3 and cshift1 used to lack memory
+! allocation, which caused the writes to segfault.
+program main
+  implicit none
+  integer, dimension (:,:),allocatable :: a
+  integer, dimension (3) :: sh, bo
+  character(len=80) line1, line2
+  integer :: i
+  
+  allocate (a(3,3))
+  a = reshape((/(i,i=1,9)/),shape(a))
+  sh = (/ 2, -1, -2 /)
+  bo = (/ -3, -2, -1 /)
+  write(unit=line1,fmt='(10I5)') cshift(a, shift=sh)
+  write(unit=line1,fmt='(10I5)') eoshift(a, shift=sh)
+  write(unit=line1,fmt='(10I5)') eoshift(a, shift=sh, boundary=bo)
+end program main
index 06c3e4b..9b2ddec 100644 (file)
@@ -1,3 +1,17 @@
+2005-06-25  Thomas Koenig  <Thomas.Koenig@online.de>
+
+        PR libfortran/22144
+        * m4/cshift1.m4: Remove const from argument ret.
+        Populate return array descriptor if ret->data is NULL.
+        * m4/eoshift1.m4: Likewise.
+        * m4/eoshift3.m4: Likewise.
+        * generated/cshift1_4.c:  Regenerated.
+        * generated/cshift1_8.c:  Regenerated.
+        * generated/eoshift1_4.c:  Regenerated.
+        * generated/eoshift1_8.c:  Regenerated.
+        * generated/eoshift3_4.c:  Regenerated.
+        * generated/eoshift3_8.c:  Regenerated.
+
 2005-06-24  Jerry DeLisle <jvdelisle@verizon.net>
 
        PR libfortran/21915
index 683ce70..b86f9e5 100644 (file)
@@ -34,13 +34,13 @@ Boston, MA 02111-1307, USA.  */
 #include <string.h>
 #include "libgfortran.h"
 
-void cshift1_4 (const gfc_array_char * ret,
+void cshift1_4 (gfc_array_char * ret,
                           const gfc_array_char * array,
                           const gfc_array_i4 * h, const GFC_INTEGER_4 * pwhich);
 export_proto(cshift1_4);
 
 void
-cshift1_4 (const gfc_array_char * ret,
+cshift1_4 (gfc_array_char * ret,
                      const gfc_array_char * array,
                      const gfc_array_i4 * h, const GFC_INTEGER_4 * pwhich)
 {
@@ -80,6 +80,25 @@ cshift1_4 (const gfc_array_char * ret,
 
   size = GFC_DESCRIPTOR_SIZE (ret);
 
+  if (ret->data == NULL)
+    {
+      int i;
+
+      ret->data = internal_malloc_size (size * size0 ((array_t *)array));
+      ret->base = 0;
+      ret->dtype = array->dtype;
+      for (i = 0; i < GFC_DESCRIPTOR_RANK (array); i++)
+        {
+          ret->dim[i].lbound = 0;
+          ret->dim[i].ubound = array->dim[i].ubound - array->dim[i].lbound;
+
+          if (i == 0)
+            ret->dim[i].stride = 1;
+          else
+            ret->dim[i].stride = (ret->dim[i-1].ubound + 1) * ret->dim[i-1].stride;
+        }
+    }
+
   extent[0] = 1;
   count[0] = 0;
   size = GFC_DESCRIPTOR_SIZE (array);
index 6513b91..24c1b6e 100644 (file)
@@ -34,13 +34,13 @@ Boston, MA 02111-1307, USA.  */
 #include <string.h>
 #include "libgfortran.h"
 
-void cshift1_8 (const gfc_array_char * ret,
+void cshift1_8 (gfc_array_char * ret,
                           const gfc_array_char * array,
                           const gfc_array_i8 * h, const GFC_INTEGER_8 * pwhich);
 export_proto(cshift1_8);
 
 void
-cshift1_8 (const gfc_array_char * ret,
+cshift1_8 (gfc_array_char * ret,
                      const gfc_array_char * array,
                      const gfc_array_i8 * h, const GFC_INTEGER_8 * pwhich)
 {
@@ -80,6 +80,25 @@ cshift1_8 (const gfc_array_char * ret,
 
   size = GFC_DESCRIPTOR_SIZE (ret);
 
+  if (ret->data == NULL)
+    {
+      int i;
+
+      ret->data = internal_malloc_size (size * size0 ((array_t *)array));
+      ret->base = 0;
+      ret->dtype = array->dtype;
+      for (i = 0; i < GFC_DESCRIPTOR_RANK (array); i++)
+        {
+          ret->dim[i].lbound = 0;
+          ret->dim[i].ubound = array->dim[i].ubound - array->dim[i].lbound;
+
+          if (i == 0)
+            ret->dim[i].stride = 1;
+          else
+            ret->dim[i].stride = (ret->dim[i-1].ubound + 1) * ret->dim[i-1].stride;
+        }
+    }
+
   extent[0] = 1;
   count[0] = 0;
   size = GFC_DESCRIPTOR_SIZE (array);
index 3503f82..833efa2 100644 (file)
@@ -37,14 +37,14 @@ Boston, MA 02111-1307, USA.  */
 static const char zeros[16] =
   {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
 
-extern void eoshift1_4 (const gfc_array_char *,
+extern void eoshift1_4 (gfc_array_char *,
                                     const gfc_array_char *,
                                     const gfc_array_i4 *, const char *,
                                     const GFC_INTEGER_4 *);
 export_proto(eoshift1_4);
 
 void
-eoshift1_4 (const gfc_array_char *ret,
+eoshift1_4 (gfc_array_char *ret,
                       const gfc_array_char *array,
                       const gfc_array_i4 *h, const char *pbound,
                       const GFC_INTEGER_4 *pwhich)
@@ -95,6 +95,26 @@ eoshift1_4 (const gfc_array_char *ret,
   extent[0] = 1;
   count[0] = 0;
   size = GFC_DESCRIPTOR_SIZE (array);
+
+  if (ret->data == NULL)
+    {
+      int i;
+
+      ret->data = internal_malloc_size (size * size0 ((array_t *)array));
+      ret->base = 0;
+      ret->dtype = array->dtype;
+      for (i = 0; i < GFC_DESCRIPTOR_RANK (array); i++)
+        {
+          ret->dim[i].lbound = 0;
+          ret->dim[i].ubound = array->dim[i].ubound - array->dim[i].lbound;
+
+          if (i == 0)
+            ret->dim[i].stride = 1;
+          else
+            ret->dim[i].stride = (ret->dim[i-1].ubound + 1) * ret->dim[i-1].stride;
+        }
+    }
+
   n = 0;
   for (dim = 0; dim < GFC_DESCRIPTOR_RANK (array); dim++)
     {
index bfa6088..75d0f1e 100644 (file)
@@ -37,14 +37,14 @@ Boston, MA 02111-1307, USA.  */
 static const char zeros[16] =
   {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
 
-extern void eoshift1_8 (const gfc_array_char *,
+extern void eoshift1_8 (gfc_array_char *,
                                     const gfc_array_char *,
                                     const gfc_array_i8 *, const char *,
                                     const GFC_INTEGER_8 *);
 export_proto(eoshift1_8);
 
 void
-eoshift1_8 (const gfc_array_char *ret,
+eoshift1_8 (gfc_array_char *ret,
                       const gfc_array_char *array,
                       const gfc_array_i8 *h, const char *pbound,
                       const GFC_INTEGER_8 *pwhich)
@@ -95,6 +95,26 @@ eoshift1_8 (const gfc_array_char *ret,
   extent[0] = 1;
   count[0] = 0;
   size = GFC_DESCRIPTOR_SIZE (array);
+
+  if (ret->data == NULL)
+    {
+      int i;
+
+      ret->data = internal_malloc_size (size * size0 ((array_t *)array));
+      ret->base = 0;
+      ret->dtype = array->dtype;
+      for (i = 0; i < GFC_DESCRIPTOR_RANK (array); i++)
+        {
+          ret->dim[i].lbound = 0;
+          ret->dim[i].ubound = array->dim[i].ubound - array->dim[i].lbound;
+
+          if (i == 0)
+            ret->dim[i].stride = 1;
+          else
+            ret->dim[i].stride = (ret->dim[i-1].ubound + 1) * ret->dim[i-1].stride;
+        }
+    }
+
   n = 0;
   for (dim = 0; dim < GFC_DESCRIPTOR_RANK (array); dim++)
     {
index 964d98b..14c38b7 100644 (file)
@@ -90,6 +90,25 @@ eoshift3_4 (gfc_array_char *ret, gfc_array_char *array,
     which = 0;
 
   size = GFC_DESCRIPTOR_SIZE (ret);
+  if (ret->data == NULL)
+    {
+      int i;
+
+      ret->data = internal_malloc_size (size * size0 ((array_t *)array));
+      ret->base = 0;
+      ret->dtype = array->dtype;
+      for (i = 0; i < GFC_DESCRIPTOR_RANK (array); i++)
+        {
+          ret->dim[i].lbound = 0;
+          ret->dim[i].ubound = array->dim[i].ubound - array->dim[i].lbound;
+
+          if (i == 0)
+            ret->dim[i].stride = 1;
+          else
+            ret->dim[i].stride = (ret->dim[i-1].ubound + 1) * ret->dim[i-1].stride;
+        }
+    }
+
 
   extent[0] = 1;
   count[0] = 0;
index c17b588..77617b0 100644 (file)
@@ -90,6 +90,25 @@ eoshift3_8 (gfc_array_char *ret, gfc_array_char *array,
     which = 0;
 
   size = GFC_DESCRIPTOR_SIZE (ret);
+  if (ret->data == NULL)
+    {
+      int i;
+
+      ret->data = internal_malloc_size (size * size0 ((array_t *)array));
+      ret->base = 0;
+      ret->dtype = array->dtype;
+      for (i = 0; i < GFC_DESCRIPTOR_RANK (array); i++)
+        {
+          ret->dim[i].lbound = 0;
+          ret->dim[i].ubound = array->dim[i].ubound - array->dim[i].lbound;
+
+          if (i == 0)
+            ret->dim[i].stride = 1;
+          else
+            ret->dim[i].stride = (ret->dim[i-1].ubound + 1) * ret->dim[i-1].stride;
+        }
+    }
+
 
   extent[0] = 1;
   count[0] = 0;
index 308c3dc..dd7653a 100644 (file)
@@ -35,13 +35,13 @@ Boston, MA 02111-1307, USA.  */
 #include "libgfortran.h"'
 include(iparm.m4)dnl
 
-void cshift1_`'atype_kind (const gfc_array_char * ret,
+void cshift1_`'atype_kind (gfc_array_char * ret,
                           const gfc_array_char * array,
                           const atype * h, const atype_name * pwhich);
 export_proto(cshift1_`'atype_kind);
 
 void
-cshift1_`'atype_kind (const gfc_array_char * ret,
+cshift1_`'atype_kind (gfc_array_char * ret,
                      const gfc_array_char * array,
                      const atype * h, const atype_name * pwhich)
 {
@@ -81,6 +81,25 @@ cshift1_`'atype_kind (const gfc_array_char * ret,
 
   size = GFC_DESCRIPTOR_SIZE (ret);
 
+  if (ret->data == NULL)
+    {
+      int i;
+
+      ret->data = internal_malloc_size (size * size0 ((array_t *)array));
+      ret->base = 0;
+      ret->dtype = array->dtype;
+      for (i = 0; i < GFC_DESCRIPTOR_RANK (array); i++)
+        {
+          ret->dim[i].lbound = 0;
+          ret->dim[i].ubound = array->dim[i].ubound - array->dim[i].lbound;
+
+          if (i == 0)
+            ret->dim[i].stride = 1;
+          else
+            ret->dim[i].stride = (ret->dim[i-1].ubound + 1) * ret->dim[i-1].stride;
+        }
+    }
+
   extent[0] = 1;
   count[0] = 0;
   size = GFC_DESCRIPTOR_SIZE (array);
index b21c6d3..1d13f48 100644 (file)
@@ -38,14 +38,14 @@ include(iparm.m4)dnl
 static const char zeros[16] =
   {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
 
-extern void eoshift1_`'atype_kind (const gfc_array_char *,
+extern void eoshift1_`'atype_kind (gfc_array_char *,
                                     const gfc_array_char *,
                                     const atype *, const char *,
                                     const atype_name *);
 export_proto(eoshift1_`'atype_kind);
 
 void
-eoshift1_`'atype_kind (const gfc_array_char *ret,
+eoshift1_`'atype_kind (gfc_array_char *ret,
                       const gfc_array_char *array,
                       const atype *h, const char *pbound,
                       const atype_name *pwhich)
@@ -96,6 +96,26 @@ eoshift1_`'atype_kind (const gfc_array_char *ret,
   extent[0] = 1;
   count[0] = 0;
   size = GFC_DESCRIPTOR_SIZE (array);
+
+  if (ret->data == NULL)
+    {
+      int i;
+
+      ret->data = internal_malloc_size (size * size0 ((array_t *)array));
+      ret->base = 0;
+      ret->dtype = array->dtype;
+      for (i = 0; i < GFC_DESCRIPTOR_RANK (array); i++)
+        {
+          ret->dim[i].lbound = 0;
+          ret->dim[i].ubound = array->dim[i].ubound - array->dim[i].lbound;
+
+          if (i == 0)
+            ret->dim[i].stride = 1;
+          else
+            ret->dim[i].stride = (ret->dim[i-1].ubound + 1) * ret->dim[i-1].stride;
+        }
+    }
+
   n = 0;
   for (dim = 0; dim < GFC_DESCRIPTOR_RANK (array); dim++)
     {
index 6cbb87c..5001756 100644 (file)
@@ -91,6 +91,25 @@ eoshift3_`'atype_kind (gfc_array_char *ret, gfc_array_char *array,
     which = 0;
 
   size = GFC_DESCRIPTOR_SIZE (ret);
+  if (ret->data == NULL)
+    {
+      int i;
+
+      ret->data = internal_malloc_size (size * size0 ((array_t *)array));
+      ret->base = 0;
+      ret->dtype = array->dtype;
+      for (i = 0; i < GFC_DESCRIPTOR_RANK (array); i++)
+        {
+          ret->dim[i].lbound = 0;
+          ret->dim[i].ubound = array->dim[i].ubound - array->dim[i].lbound;
+
+          if (i == 0)
+            ret->dim[i].stride = 1;
+          else
+            ret->dim[i].stride = (ret->dim[i-1].ubound + 1) * ret->dim[i-1].stride;
+        }
+    }
+
 
   extent[0] = 1;
   count[0] = 0;