OSDN Git Service

2005-07-07 Thomas Koenig <Thomas.Koenig@online.de>
[pf3gnuchains/gcc-fork.git] / libgfortran / generated / eoshift1_4.c
index 3503f82..6012c3f 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++)
     {
@@ -115,7 +135,7 @@ eoshift1_4 (const gfc_array_char *ret,
           rstride[n] = ret->dim[dim].stride * size;
           sstride[n] = array->dim[dim].stride * size;
 
-          hstride[n] = h->dim[n].stride;
+          hstride[n] = h->dim[n].stride * size;
           n++;
         }
     }
@@ -138,7 +158,14 @@ eoshift1_4 (const gfc_array_char *ret,
     {
       /* Do the shift for this dimension.  */
       sh = *hptr;
-      delta = (sh >= 0) ? sh: -sh;
+      if (( sh >= 0 ? sh : -sh ) > len)
+       {
+         delta = len;
+         sh = len;
+       }
+      else
+       delta = (sh >= 0) ? sh: -sh;
+
       if (sh > 0)
         {
           src = &sptr[delta * soffset];