https://gcc.gnu.org/g:8f8f5d80838c03b7b1cb5a30f8267cafa905cb13

commit 8f8f5d80838c03b7b1cb5a30f8267cafa905cb13
Author: Mikael Morin <mik...@gcc.gnu.org>
Date:   Mon Sep 8 14:04:26 2025 +0200

    Introduction macro PTR_INCREMENT_BYTES
    
    Correction m4/minloc1
    
    Correction matmul_logical
    
    Introduction macro PTR_DECREMENT_BYTES
    
    Correction ; manquant ifindloc1.m4
    
    Correction matmul
    
    Correction matmul
    
    Correction m4/maxloc2s.m4
    
    Correction m4/minloc2s.m4
    
    Correction m4/ifunction.m4
    
    Correction gmtime
    
    Correction findloc2s.m4, ifindloc2.m4
    
    Correction in_pack.m4 et in_unpack.m4
    
    Correction matmul.m4
    
    Correction matmul.m4
    
    Correction cshift0.m4
    
    Correction ifindloc1.m4
    
    Correction ifindloc1.m4
    
    Correction pack.m4
    
    Correction spread.m4
    
    Correction spread.m4
    
    Correction ifunction-s.m4
    
    Correction cshift1a.m4
    
    Correction maxval.m4
    
    Correction minloc1.m4
    
    Correction minloc1.m4
    
    Correction minloc1.m4
    
    Correction ifindloc0.m4
    
    Correction ifindloc0.m4
    
    Correction iforeach-s2.m4
    
    Correction ifunction-s2.m4
    
    Correction iforeach-s.m4
    
    Correction ifunction-s.m4
    
    Correction ifindloc0.m4
    
    Correction ifindloc0.m4
    
    Correction ifindloc1.m4
    
    Correction maxloc1.m4
    
    Revert partiel

Diff:
---
 libgfortran/intrinsics/date_and_time.c | 108 +++++++++++++++++++++------------
 libgfortran/intrinsics/dtime.c         |   2 +-
 libgfortran/intrinsics/etime.c         |   2 +-
 libgfortran/intrinsics/random.c        |  72 +++++++++++-----------
 libgfortran/io/read.c                  |   2 +-
 libgfortran/io/transfer.c              |  12 ++--
 libgfortran/libgfortran.h              |   5 ++
 libgfortran/m4/cshift0.m4              |  52 ++++++++--------
 libgfortran/m4/cshift1.m4              |  10 +--
 libgfortran/m4/cshift1a.m4             |  50 +++++++--------
 libgfortran/m4/eoshift1.m4             |  10 +--
 libgfortran/m4/eoshift3.m4             |  10 +--
 libgfortran/m4/findloc2s.m4            |   1 -
 libgfortran/m4/ifindloc0.m4            |  28 ++++-----
 libgfortran/m4/ifindloc1.m4            |  66 +++++++++++---------
 libgfortran/m4/ifindloc2.m4            |  14 ++---
 libgfortran/m4/iforeach-s.m4           |  18 +++---
 libgfortran/m4/iforeach-s2.m4          |  16 ++---
 libgfortran/m4/iforeach.m4             |  16 ++---
 libgfortran/m4/ifunction-s.m4          |  63 ++++++++++---------
 libgfortran/m4/ifunction-s2.m4         |  63 ++++++++++---------
 libgfortran/m4/ifunction.m4            |  63 ++++++++++---------
 libgfortran/m4/ifunction_logical.m4    |  17 +++---
 libgfortran/m4/in_pack.m4              |  10 +--
 libgfortran/m4/in_unpack.m4            |  12 ++--
 libgfortran/m4/matmul_internal.m4      |  18 +++---
 libgfortran/m4/matmull.m4              |   4 +-
 libgfortran/m4/maxloc0.m4              |   8 +--
 libgfortran/m4/maxloc1.m4              |  29 +++++----
 libgfortran/m4/maxloc1s.m4             |   4 +-
 libgfortran/m4/maxloc2s.m4             |  10 +--
 libgfortran/m4/maxval.m4               |   7 ++-
 libgfortran/m4/maxval1s.m4             |   4 +-
 libgfortran/m4/minloc0.m4              |   8 +--
 libgfortran/m4/minloc1.m4              |  34 +++++++----
 libgfortran/m4/minloc1s.m4             |   4 +-
 libgfortran/m4/minloc2s.m4             |  10 +--
 libgfortran/m4/minval.m4               |   7 ++-
 libgfortran/m4/minval1s.m4             |   4 +-
 libgfortran/m4/pack.m4                 |  28 ++++-----
 libgfortran/m4/reshape.m4              |  26 ++++----
 libgfortran/m4/spread.m4               |  38 ++++++------
 libgfortran/m4/unpack.m4               |  44 +++++++-------
 43 files changed, 546 insertions(+), 463 deletions(-)

diff --git a/libgfortran/intrinsics/date_and_time.c 
b/libgfortran/intrinsics/date_and_time.c
index a5042cb2bcf8..47f1946f8e47 100644
--- a/libgfortran/intrinsics/date_and_time.c
+++ b/libgfortran/intrinsics/date_and_time.c
@@ -202,11 +202,11 @@ date_and_time (char *__date, char *__time, char *__zone,
     {
       index_type len, delta, elt_size;
 
-      elt_size = GFC_DESCRIPTOR_SIZE (__values);
+      elt_size = GFC_DESCRIPTOR_SIZE(__values);
       len = GFC_DESCRIPTOR_EXTENT(__values,0);
-      delta = GFC_DESCRIPTOR_STRIDE(__values,0);
+      delta = GFC_DESCRIPTOR_STRIDE_BYTES(__values,0);
       if (delta == 0)
-       delta = 1;
+       delta = GFC_DESCRIPTOR_SIZE (__values);
       
       if (unlikely (len < VALUES_SIZE))
          runtime_error ("Incorrect extent in VALUES argument to"
@@ -218,31 +218,36 @@ date_and_time (char *__date, char *__time, char *__zone,
        {
          GFC_INTEGER_4 *vptr4 = __values->base_addr;
 
-         for (i = 0; i < VALUES_SIZE; i++, vptr4 += delta)
-           *vptr4 = values[i];
+         for (i = 0; i < VALUES_SIZE; i++)
+           {
+             *vptr4 = values[i];
+             PTR_INCREMENT_BYTES (vptr4, delta);
+           }
        }
       else if (elt_size == 8)
        {
          GFC_INTEGER_8 *vptr8 = (GFC_INTEGER_8 *)__values->base_addr;
 
-         for (i = 0; i < VALUES_SIZE; i++, vptr8 += delta)
+         for (i = 0; i < VALUES_SIZE; i++)
            {
              if (values[i] == - GFC_INTEGER_4_HUGE)
                *vptr8 = - GFC_INTEGER_8_HUGE;
              else
                *vptr8 = values[i];
+             PTR_INCREMENT_BYTES (vptr8, delta);
            }
        }
       else if (elt_size == 2)
        {
          GFC_INTEGER_2 *vptr2 = (GFC_INTEGER_2 *)__values->base_addr;
 
-         for (i = 0; i < VALUES_SIZE; i++, vptr2 += delta)
+         for (i = 0; i < VALUES_SIZE; i++)
            {
              if (values[i] == - GFC_INTEGER_4_HUGE)
                *vptr2 = - GFC_INTEGER_2_HUGE;
              else
                *vptr2 = (GFC_INTEGER_2) values[i];
+             PTR_INCREMENT_BYTES (vptr2, delta);
            }
        }
 #if defined (HAVE_GFC_INTEGER_16)
@@ -250,12 +255,13 @@ date_and_time (char *__date, char *__time, char *__zone,
        {
          GFC_INTEGER_16 *vptr16 = (GFC_INTEGER_16 *)__values->base_addr;
 
-         for (i = 0; i < VALUES_SIZE; i++, vptr16 += delta)
+         for (i = 0; i < VALUES_SIZE; i++)
            {
              if (values[i] == - GFC_INTEGER_4_HUGE)
                *vptr16 = - GFC_INTEGER_16_HUGE;
              else
                *vptr16 = values[i];
+             PTR_INCREMENT_BYTES (vptr16, delta);
            }
        }
 #endif
@@ -367,13 +373,16 @@ itime_i4 (gfc_array_i4 *__values)
   /* Copy the value into the array.  */
   len = GFC_DESCRIPTOR_EXTENT(__values,0);
   assert (len >= 3);
-  delta = GFC_DESCRIPTOR_STRIDE(__values,0);
+  delta = GFC_DESCRIPTOR_STRIDE_BYTES(__values,0);
   if (delta == 0)
-    delta = 1;
+    delta = GFC_DESCRIPTOR_SIZE(__values);
 
   vptr = __values->base_addr;
-  for (i = 0; i < 3; i++, vptr += delta)
-    *vptr = x[i];
+  for (i = 0; i < 3; i++)
+    {
+      *vptr = x[i];
+      PTR_INCREMENT_BYTES (vptr, delta);
+    }
 }
 
 
@@ -393,13 +402,16 @@ itime_i8 (gfc_array_i8 *__values)
   /* Copy the value into the array.  */
   len = GFC_DESCRIPTOR_EXTENT(__values,0);
   assert (len >= 3);
-  delta = GFC_DESCRIPTOR_STRIDE(__values,0);
+  delta = GFC_DESCRIPTOR_STRIDE_BYTES(__values,0);
   if (delta == 0)
-    delta = 1;
+    delta = GFC_DESCRIPTOR_SIZE(__values);
 
   vptr = __values->base_addr;
-  for (i = 0; i < 3; i++, vptr += delta)
-    *vptr = x[i];
+  for (i = 0; i < 3; i++)
+    {
+      *vptr = x[i];
+      PTR_INCREMENT_BYTES (vptr, delta);
+    }
 }
 
 
@@ -445,13 +457,16 @@ idate_i4 (gfc_array_i4 *__values)
   /* Copy the value into the array.  */
   len = GFC_DESCRIPTOR_EXTENT(__values,0);
   assert (len >= 3);
-  delta = GFC_DESCRIPTOR_STRIDE(__values,0);
+  delta = GFC_DESCRIPTOR_STRIDE_BYTES(__values,0);
   if (delta == 0)
-    delta = 1;
+    delta = GFC_DESCRIPTOR_SIZE(__values);
 
   vptr = __values->base_addr;
-  for (i = 0; i < 3; i++, vptr += delta)
-    *vptr = x[i];
+  for (i = 0; i < 3; i++)
+    {
+      *vptr = x[i];
+      PTR_INCREMENT_BYTES (vptr, delta);
+    }
 }
 
 
@@ -471,13 +486,16 @@ idate_i8 (gfc_array_i8 *__values)
   /* Copy the value into the array.  */
   len = GFC_DESCRIPTOR_EXTENT(__values,0);
   assert (len >= 3);
-  delta = GFC_DESCRIPTOR_STRIDE(__values,0);
+  delta = GFC_DESCRIPTOR_STRIDE_BYTES(__values,0);
   if (delta == 0)
-    delta = 1;
+    delta = GFC_DESCRIPTOR_SIZE(__values);
 
   vptr = __values->base_addr;
-  for (i = 0; i < 3; i++, vptr += delta)
-    *vptr = x[i];
+  for (i = 0; i < 3; i++)
+    {
+      *vptr = x[i];
+      PTR_INCREMENT_BYTES (vptr, delta);
+    }
 }
 
 
@@ -535,13 +553,16 @@ gmtime_i4 (GFC_INTEGER_4 * t, gfc_array_i4 * tarray)
   /* Copy the values into the array.  */
   len = GFC_DESCRIPTOR_EXTENT(tarray,0);
   assert (len >= 9);
-  delta = GFC_DESCRIPTOR_STRIDE(tarray,0);
+  delta = GFC_DESCRIPTOR_STRIDE_BYTES(tarray,0);
   if (delta == 0)
-    delta = 1;
+    delta = GFC_DESCRIPTOR_SIZE(tarray);
 
   vptr = tarray->base_addr;
-  for (i = 0; i < 9; i++, vptr += delta)
-    *vptr = x[i];
+  for (i = 0; i < 9; i++)
+    {
+      *vptr = x[i];
+      PTR_INCREMENT_BYTES (vptr, delta);
+    }
 }
 
 extern void gmtime_i8 (GFC_INTEGER_8 *, gfc_array_i8 *);
@@ -562,13 +583,16 @@ gmtime_i8 (GFC_INTEGER_8 * t, gfc_array_i8 * tarray)
   /* Copy the values into the array.  */
   len = GFC_DESCRIPTOR_EXTENT(tarray,0);
   assert (len >= 9);
-  delta = GFC_DESCRIPTOR_STRIDE(tarray,0);
+  delta = GFC_DESCRIPTOR_STRIDE_BYTES(tarray,0);
   if (delta == 0)
     delta = 1;
 
   vptr = tarray->base_addr;
-  for (i = 0; i < 9; i++, vptr += delta)
-    *vptr = x[i];
+  for (i = 0; i < 9; i++)
+    {
+      *vptr = x[i];
+      PTR_INCREMENT_BYTES (vptr, delta);
+    }
 }
 
 
@@ -627,13 +651,16 @@ ltime_i4 (GFC_INTEGER_4 * t, gfc_array_i4 * tarray)
   /* Copy the values into the array.  */
   len = GFC_DESCRIPTOR_EXTENT(tarray,0);
   assert (len >= 9);
-  delta = GFC_DESCRIPTOR_STRIDE(tarray,0);
+  delta = GFC_DESCRIPTOR_STRIDE_BYTES(tarray,0);
   if (delta == 0)
-    delta = 1;
+    delta = GFC_DESCRIPTOR_SIZE(tarray);
 
   vptr = tarray->base_addr;
-  for (i = 0; i < 9; i++, vptr += delta)
-    *vptr = x[i];
+  for (i = 0; i < 9; i++)
+    {
+      *vptr = x[i];
+      PTR_INCREMENT_BYTES (vptr, delta);
+    }
 }
 
 extern void ltime_i8 (GFC_INTEGER_8 *, gfc_array_i8 *);
@@ -654,13 +681,16 @@ ltime_i8 (GFC_INTEGER_8 * t, gfc_array_i8 * tarray)
   /* Copy the values into the array.  */
   len = GFC_DESCRIPTOR_EXTENT(tarray,0);
   assert (len >= 9);
-  delta = GFC_DESCRIPTOR_STRIDE(tarray,0);
+  delta = GFC_DESCRIPTOR_STRIDE_BYTES(tarray,0);
   if (delta == 0)
-    delta = 1;
+    delta = GFC_DESCRIPTOR_SIZE(tarray);
 
   vptr = tarray->base_addr;
-  for (i = 0; i < 9; i++, vptr += delta)
-    *vptr = x[i];
+  for (i = 0; i < 9; i++)
+    {
+      *vptr = x[i];
+      PTR_INCREMENT_BYTES (vptr, delta);
+    }
 }
 
 
diff --git a/libgfortran/intrinsics/dtime.c b/libgfortran/intrinsics/dtime.c
index c33373cf1f22..1599201fa493 100644
--- a/libgfortran/intrinsics/dtime.c
+++ b/libgfortran/intrinsics/dtime.c
@@ -67,7 +67,7 @@ dtime_sub (gfc_array_r4 *t, GFC_REAL_4 *result)
   tp = t->base_addr;
 
   *tp = tu;
-  tp += GFC_DESCRIPTOR_STRIDE(t,0);
+  PTR_INCREMENT_BYTES (tp, GFC_DESCRIPTOR_STRIDE_BYTES(t,0));
   *tp = ts;
   *result = tt;
   __gthread_mutex_unlock (&dtime_update_lock);
diff --git a/libgfortran/intrinsics/etime.c b/libgfortran/intrinsics/etime.c
index a608ad2c9556..fa3f64fb4e26 100644
--- a/libgfortran/intrinsics/etime.c
+++ b/libgfortran/intrinsics/etime.c
@@ -54,7 +54,7 @@ etime_sub (gfc_array_r4 *t, GFC_REAL_4 *result)
   tp = t->base_addr;
 
   *tp = tu;
-  tp += GFC_DESCRIPTOR_STRIDE(t,0);
+  PTR_INCREMENT_BYTES (tp, GFC_DESCRIPTOR_STRIDE_BYTES(t,0));
   *tp = ts;
   *result = tt;
 }
diff --git a/libgfortran/intrinsics/random.c b/libgfortran/intrinsics/random.c
index 225eb60239ac..b0b08638f8b4 100644
--- a/libgfortran/intrinsics/random.c
+++ b/libgfortran/intrinsics/random.c
@@ -631,7 +631,7 @@ arandom_r4 (gfc_array_r4 *x)
   for (index_type n = 0; n < dim; n++)
     {
       count[n] = 0;
-      stride[n] = GFC_DESCRIPTOR_STRIDE(x,n);
+      stride[n] = GFC_DESCRIPTOR_STRIDE_BYTES(x,n);
       extent[n] = GFC_DESCRIPTOR_EXTENT(x,n);
       if (extent[n] <= 0)
         return;
@@ -650,7 +650,7 @@ arandom_r4 (gfc_array_r4 *x)
       rnumber_4 (dest, high);
 
       /* Advance to the next element.  */
-      dest += stride0;
+      PTR_INCREMENT_BYTES (dest, stride0);
       count[0]++;
       /* Advance to the next source element.  */
       index_type n = 0;
@@ -661,7 +661,7 @@ arandom_r4 (gfc_array_r4 *x)
           count[n] = 0;
           /* We could precalculate these products, but this is a less
              frequently used path so probably not worth it.  */
-          dest -= stride[n] * extent[n];
+         PTR_DECREMENT_BYTES (dest, stride[n] * extent[n]);
           n++;
           if (n == dim)
             {
@@ -671,7 +671,7 @@ arandom_r4 (gfc_array_r4 *x)
           else
             {
               count[n]++;
-              dest += stride[n];
+              PTR_INCREMENT_BYTES (dest, stride[n]);
             }
         }
     }
@@ -698,7 +698,7 @@ arandom_r8 (gfc_array_r8 *x)
   for (index_type n = 0; n < dim; n++)
     {
       count[n] = 0;
-      stride[n] = GFC_DESCRIPTOR_STRIDE(x,n);
+      stride[n] = GFC_DESCRIPTOR_STRIDE_BYTES(x,n);
       extent[n] = GFC_DESCRIPTOR_EXTENT(x,n);
       if (extent[n] <= 0)
         return;
@@ -716,7 +716,7 @@ arandom_r8 (gfc_array_r8 *x)
       rnumber_8 (dest, r);
 
       /* Advance to the next element.  */
-      dest += stride0;
+      PTR_INCREMENT_BYTES (dest, stride0);
       count[0]++;
       /* Advance to the next source element.  */
       index_type n = 0;
@@ -727,7 +727,7 @@ arandom_r8 (gfc_array_r8 *x)
           count[n] = 0;
           /* We could precalculate these products, but this is a less
              frequently used path so probably not worth it.  */
-          dest -= stride[n] * extent[n];
+         PTR_DECREMENT_BYTES (dest, stride[n] * extent[n]);
           n++;
           if (n == dim)
             {
@@ -737,7 +737,7 @@ arandom_r8 (gfc_array_r8 *x)
           else
             {
               count[n]++;
-              dest += stride[n];
+              PTR_INCREMENT_BYTES (dest, stride[n]);
             }
         }
     }
@@ -766,7 +766,7 @@ arandom_r10 (gfc_array_r10 *x)
   for (index_type n = 0; n < dim; n++)
     {
       count[n] = 0;
-      stride[n] = GFC_DESCRIPTOR_STRIDE(x,n);
+      stride[n] = GFC_DESCRIPTOR_STRIDE_BYTES(x,n);
       extent[n] = GFC_DESCRIPTOR_EXTENT(x,n);
       if (extent[n] <= 0)
         return;
@@ -784,7 +784,7 @@ arandom_r10 (gfc_array_r10 *x)
       rnumber_10 (dest, r);
 
       /* Advance to the next element.  */
-      dest += stride0;
+      PTR_INCREMENT_BYTES (dest, stride0);
       count[0]++;
       /* Advance to the next source element.  */
       index_type n = 0;
@@ -795,7 +795,7 @@ arandom_r10 (gfc_array_r10 *x)
           count[n] = 0;
           /* We could precalculate these products, but this is a less
              frequently used path so probably not worth it.  */
-          dest -= stride[n] * extent[n];
+         PTR_DECREMENT_BYTES (dest, stride[n] * extent[n]);
           n++;
           if (n == dim)
             {
@@ -805,7 +805,7 @@ arandom_r10 (gfc_array_r10 *x)
           else
             {
               count[n]++;
-              dest += stride[n];
+              PTR_INCREMENT_BYTES (dest, stride[n]);
             }
         }
     }
@@ -836,7 +836,7 @@ arandom_r16 (gfc_array_r16 *x)
   for (index_type n = 0; n < dim; n++)
     {
       count[n] = 0;
-      stride[n] = GFC_DESCRIPTOR_STRIDE(x,n);
+      stride[n] = GFC_DESCRIPTOR_STRIDE_BYTES(x,n);
       extent[n] = GFC_DESCRIPTOR_EXTENT(x,n);
       if (extent[n] <= 0)
         return;
@@ -855,7 +855,7 @@ arandom_r16 (gfc_array_r16 *x)
       rnumber_16 (dest, r1, r2);
 
       /* Advance to the next element.  */
-      dest += stride0;
+      PTR_INCREMENT_BYTES (dest, stride0);
       count[0]++;
       /* Advance to the next source element.  */
       index_type n = 0;
@@ -866,7 +866,7 @@ arandom_r16 (gfc_array_r16 *x)
           count[n] = 0;
           /* We could precalculate these products, but this is a less
              frequently used path so probably not worth it.  */
-          dest -= stride[n] * extent[n];
+         PTR_DECREMENT_BYTES (dest, stride[n] * extent[n]);
           n++;
           if (n == dim)
             {
@@ -876,7 +876,7 @@ arandom_r16 (gfc_array_r16 *x)
           else
             {
               count[n]++;
-              dest += stride[n];
+              PTR_INCREMENT_BYTES (dest, stride[n]);
             }
         }
     }
@@ -907,7 +907,7 @@ arandom_r17 (gfc_array_r17 *x)
   for (index_type n = 0; n < dim; n++)
     {
       count[n] = 0;
-      stride[n] = GFC_DESCRIPTOR_STRIDE(x,n);
+      stride[n] = GFC_DESCRIPTOR_STRIDE_BYTES(x,n);
       extent[n] = GFC_DESCRIPTOR_EXTENT(x,n);
       if (extent[n] <= 0)
         return;
@@ -926,7 +926,7 @@ arandom_r17 (gfc_array_r17 *x)
       rnumber_17 (dest, r1, r2);
 
       /* Advance to the next element.  */
-      dest += stride0;
+      PTR_INCREMENT_BYTES (dest, stride0);
       count[0]++;
       /* Advance to the next source element.  */
       index_type n = 0;
@@ -937,7 +937,7 @@ arandom_r17 (gfc_array_r17 *x)
           count[n] = 0;
           /* We could precalculate these products, but this is a less
              frequently used path so probably not worth it.  */
-          dest -= stride[n] * extent[n];
+         PTR_DECREMENT_BYTES (dest, stride[n] * extent[n]);
           n++;
           if (n == dim)
             {
@@ -947,7 +947,7 @@ arandom_r17 (gfc_array_r17 *x)
           else
             {
               count[n]++;
-              dest += stride[n];
+              PTR_INCREMENT_BYTES (dest, stride[n]);
             }
         }
     }
@@ -1040,7 +1040,7 @@ arandom_m2 (gfc_array_m2 *x)
   for (index_type n = 0; n < dim; n++)
     {
       count[n] = 0;
-      stride[n] = GFC_DESCRIPTOR_STRIDE(x,n);
+      stride[n] = GFC_DESCRIPTOR_STRIDE_BYTES(x,n);
       extent[n] = GFC_DESCRIPTOR_EXTENT(x,n);
       if (extent[n] <= 0)
        return;
@@ -1058,7 +1058,7 @@ arandom_m2 (gfc_array_m2 *x)
       *dest = r >> 48;
 
       /* Advance to the next element.  */
-      dest += stride0;
+      PTR_INCREMENT_BYTES (dest, stride0);
       count[0]++;
       /* Advance to the next source element.  */
       index_type n = 0;
@@ -1069,7 +1069,7 @@ arandom_m2 (gfc_array_m2 *x)
          count[n] = 0;
          /* We could precalculate these products, but this is a less
             frequently used path so probably not worth it.  */
-         dest -= stride[n] * extent[n];
+         PTR_DECREMENT_BYTES (dest, stride[n] * extent[n]);
          n++;
          if (n == dim)
            {
@@ -1079,7 +1079,7 @@ arandom_m2 (gfc_array_m2 *x)
          else
            {
              count[n]++;
-             dest += stride[n];
+             PTR_INCREMENT_BYTES (dest, stride[n]);
            }
        }
     }
@@ -1105,7 +1105,7 @@ arandom_m4 (gfc_array_m4 *x)
   for (index_type n = 0; n < dim; n++)
     {
       count[n] = 0;
-      stride[n] = GFC_DESCRIPTOR_STRIDE(x,n);
+      stride[n] = GFC_DESCRIPTOR_STRIDE_BYTES(x,n);
       extent[n] = GFC_DESCRIPTOR_EXTENT(x,n);
       if (extent[n] <= 0)
        return;
@@ -1123,7 +1123,7 @@ arandom_m4 (gfc_array_m4 *x)
       *dest = r >> 32;
 
       /* Advance to the next element.  */
-      dest += stride0;
+      PTR_INCREMENT_BYTES (dest, stride0);
       count[0]++;
       /* Advance to the next source element.  */
       index_type n = 0;
@@ -1134,7 +1134,7 @@ arandom_m4 (gfc_array_m4 *x)
          count[n] = 0;
          /* We could precalculate these products, but this is a less
             frequently used path so probably not worth it.  */
-         dest -= stride[n] * extent[n];
+         PTR_DECREMENT_BYTES (dest, stride[n] * extent[n]);
          n++;
          if (n == dim)
            {
@@ -1144,7 +1144,7 @@ arandom_m4 (gfc_array_m4 *x)
          else
            {
              count[n]++;
-             dest += stride[n];
+             PTR_INCREMENT_BYTES(dest, stride[n]);
            }
        }
     }
@@ -1170,7 +1170,7 @@ arandom_m8 (gfc_array_m8 *x)
   for (index_type n = 0; n < dim; n++)
     {
       count[n] = 0;
-      stride[n] = GFC_DESCRIPTOR_STRIDE(x,n);
+      stride[n] = GFC_DESCRIPTOR_STRIDE_BYTES(x,n);
       extent[n] = GFC_DESCRIPTOR_EXTENT(x,n);
       if (extent[n] <= 0)
        return;
@@ -1188,7 +1188,7 @@ arandom_m8 (gfc_array_m8 *x)
       *dest = r;
 
       /* Advance to the next element.  */
-      dest += stride0;
+      PTR_INCREMENT_BYTES (dest, stride0);
       count[0]++;
       /* Advance to the next source element.  */
       index_type n = 0;
@@ -1199,7 +1199,7 @@ arandom_m8 (gfc_array_m8 *x)
          count[n] = 0;
          /* We could precalculate these products, but this is a less
             frequently used path so probably not worth it.  */
-         dest -= stride[n] * extent[n];
+         PTR_DECREMENT_BYTES (dest, stride[n] * extent[n]);
          n++;
          if (n == dim)
            {
@@ -1209,7 +1209,7 @@ arandom_m8 (gfc_array_m8 *x)
          else
            {
              count[n]++;
-             dest += stride[n];
+             PTR_INCREMENT_BYTES (dest, stride[n]);
            }
        }
     }
@@ -1237,7 +1237,7 @@ arandom_m16 (gfc_array_m16 *x)
   for (index_type n = 0; n < dim; n++)
     {
       count[n] = 0;
-      stride[n] = GFC_DESCRIPTOR_STRIDE(x,n);
+      stride[n] = GFC_DESCRIPTOR_STRIDE_BYTES(x,n);
       extent[n] = GFC_DESCRIPTOR_EXTENT(x,n);
       if (extent[n] <= 0)
        return;
@@ -1255,7 +1255,7 @@ arandom_m16 (gfc_array_m16 *x)
       *dest = (((GFC_UINTEGER_16) r1) << 64) | (GFC_UINTEGER_16) r2;
 
       /* Advance to the next element.  */
-      dest += stride0;
+      PTR_INCREMENT_BYTES (dest, stride0);
       count[0]++;
       /* Advance to the next source element.  */
       index_type n = 0;
@@ -1266,7 +1266,7 @@ arandom_m16 (gfc_array_m16 *x)
          count[n] = 0;
          /* We could precalculate these products, but this is a less
             frequently used path so probably not worth it.  */
-         dest -= stride[n] * extent[n];
+         PTR_DECREMENT_BYTES (dest, stride[n] * extent[n]);
          n++;
          if (n == dim)
            {
@@ -1276,7 +1276,7 @@ arandom_m16 (gfc_array_m16 *x)
          else
            {
              count[n]++;
-             dest += stride[n];
+             PTR_INCREMENT_BYTES (dest, stride[n]);
            }
        }
     }
diff --git a/libgfortran/io/read.c b/libgfortran/io/read.c
index e34d31b02e90..79b45be4e924 100644
--- a/libgfortran/io/read.c
+++ b/libgfortran/io/read.c
@@ -600,7 +600,7 @@ read_default_char4 (st_parameter_dt *dtp, char *p, size_t 
len, size_t width)
       if (s4 == NULL)
        return;
       if (width > len)
-        s4 += (width - len);
+       s4 += (width - len);
 
       m = (width > len) ? len : width;
 
diff --git a/libgfortran/io/transfer.c b/libgfortran/io/transfer.c
index 7f4941271836..a3573d0dad88 100644
--- a/libgfortran/io/transfer.c
+++ b/libgfortran/io/transfer.c
@@ -2843,13 +2843,13 @@ transfer_array_inner (st_parameter_dt *dtp, 
gfc_array_char *desc, int kind,
            return;
 
          dtp->u.p.transfer (dtp, iotype, data, kind, size, tsize);
-         data += stride0 * tsize;
+         PTR_INCREMENT_BYTES (data, stride0 * tsize);
          count[0] += tsize;
          n = 0;
          while (count[n] == extent[n])
            {
              count[n] = 0;
-             data -= stride[n] * extent[n];
+             PTR_DECREMENT_BYTES (data, stride[n] * extent[n]);
              n++;
              if (n == rank)
                {
@@ -2859,7 +2859,7 @@ transfer_array_inner (st_parameter_dt *dtp, 
gfc_array_char *desc, int kind,
              else
                {
                  count[n]++;
-                 data += stride[n];
+                 PTR_INCREMENT_BYTES (data, stride[n]);
                }
            }
        }
@@ -2869,13 +2869,13 @@ transfer_array_inner (st_parameter_dt *dtp, 
gfc_array_char *desc, int kind,
       while (data)
        {
          dtp->u.p.transfer (dtp, iotype, data, kind, size, tsize);
-         data += stride0 * tsize;
+         PTR_INCREMENT_BYTES (data, stride0 * tsize);
          count[0] += tsize;
          n = 0;
          while (count[n] == extent[n])
            {
              count[n] = 0;
-             data -= stride[n] * extent[n];
+             PTR_DECREMENT_BYTES (data, stride[n] * extent[n]);
              n++;
              if (n == rank)
                {
@@ -2885,7 +2885,7 @@ transfer_array_inner (st_parameter_dt *dtp, 
gfc_array_char *desc, int kind,
              else
                {
                  count[n]++;
-                 data += stride[n];
+                 PTR_INCREMENT_BYTES (data, stride[n]);
                }
            }
        }
diff --git a/libgfortran/libgfortran.h b/libgfortran/libgfortran.h
index afa2cc43ecd6..d7100fd5b7c4 100644
--- a/libgfortran/libgfortran.h
+++ b/libgfortran/libgfortran.h
@@ -585,6 +585,11 @@ typedef GFC_FULL_ARRAY_DESCRIPTOR (GFC_MAX_DIMENSIONS, 
GFC_INTEGER_4) gfc_full_a
 #define GFC_UNALIGNED_C8(x) (((uintptr_t)(x)) & \
                             (__alignof__(GFC_COMPLEX_8) - 1))
 
+
+#define PTR_INCREMENT_BYTES(ptr,bytes) ptr = (typeof (ptr)) (((char*) ptr) + 
(bytes))
+#define PTR_DECREMENT_BYTES(ptr,bytes) ptr = (typeof (ptr)) (((char*) ptr) - 
(bytes))
+
+
 /* Generic vtab structure.  */
 typedef struct
 {
diff --git a/libgfortran/m4/cshift0.m4 b/libgfortran/m4/cshift0.m4
index 6ca3db403ce1..650703cf1253 100644
--- a/libgfortran/m4/cshift0.m4
+++ b/libgfortran/m4/cshift0.m4
@@ -112,10 +112,10 @@ cshift0_'rtype_code` ('rtype` *ret, const 'rtype` *array, 
ptrdiff_t shift,
         bn = cshift(a,sh*n1*n2,1)
 
         we can used a more blocked algorithm for dim>1.  */
-      sstride[0] = 1;
-      rstride[0] = 1;
-      roffset = 1;
-      soffset = 1;
+      sstride[0] = sizeof ('rtype_name`);
+      rstride[0] = sizeof ('rtype_name`);
+      roffset = sizeof ('rtype_name`);
+      soffset = sizeof ('rtype_name`);
       len = GFC_DESCRIPTOR_STRIDE(array, which)
        * GFC_DESCRIPTOR_EXTENT(array, which);      
       shift *= GFC_DESCRIPTOR_STRIDE(array, which);
@@ -123,8 +123,8 @@ cshift0_'rtype_code` ('rtype` *ret, const 'rtype` *array, 
ptrdiff_t shift,
        {
          count[n] = 0;
          extent[n] = GFC_DESCRIPTOR_EXTENT(array,dim);
-         rstride[n] = GFC_DESCRIPTOR_STRIDE(ret,dim);
-         sstride[n] = GFC_DESCRIPTOR_STRIDE(array,dim);
+         rstride[n] = GFC_DESCRIPTOR_STRIDE_BYTES(ret,dim);
+         sstride[n] = GFC_DESCRIPTOR_STRIDE_BYTES(array,dim);
          n++;
        }
       dim = GFC_DESCRIPTOR_RANK (array) - which;
@@ -135,27 +135,27 @@ cshift0_'rtype_code` ('rtype` *ret, const 'rtype` *array, 
ptrdiff_t shift,
        {
          if (dim == which)
            {
-             roffset = GFC_DESCRIPTOR_STRIDE(ret,dim);
+             roffset = GFC_DESCRIPTOR_STRIDE_BYTES(ret,dim);
              if (roffset == 0)
-               roffset = 1;
-             soffset = GFC_DESCRIPTOR_STRIDE(array,dim);
+               roffset = sizeof ('rtype_name`);
+             soffset = GFC_DESCRIPTOR_STRIDE_BYTES(array,dim);
              if (soffset == 0)
-               soffset = 1;
+               soffset = sizeof ('rtype_name`);
              len = GFC_DESCRIPTOR_EXTENT(array,dim);
            }
          else
            {
              count[n] = 0;
              extent[n] = GFC_DESCRIPTOR_EXTENT(array,dim);
-             rstride[n] = GFC_DESCRIPTOR_STRIDE(ret,dim);
-             sstride[n] = GFC_DESCRIPTOR_STRIDE(array,dim);
+             rstride[n] = GFC_DESCRIPTOR_STRIDE_BYTES(ret,dim);
+             sstride[n] = GFC_DESCRIPTOR_STRIDE_BYTES(array,dim);
              n++;
            }
        }
       if (sstride[0] == 0)
-       sstride[0] = 1;
+       sstride[0] = sizeof ('rtype_name`);
       if (rstride[0] == 0)
-       rstride[0] = 1;
+       rstride[0] = sizeof ('rtype_name`);
 
       dim = GFC_DESCRIPTOR_RANK (array);
     }
@@ -179,7 +179,7 @@ cshift0_'rtype_code` ('rtype` *ret, const 'rtype` *array, 
ptrdiff_t shift,
 
       /* If elements are contiguous, perform the operation
         in two block moves.  */
-      if (soffset == 1 && roffset == 1)
+      if (soffset == sizeof ('rtype_name`) && roffset == sizeof ('rtype_name`))
        {
          size_t len1 = shift * sizeof ('rtype_name`);
          size_t len2 = (len - shift) * sizeof ('rtype_name`);
@@ -191,25 +191,25 @@ cshift0_'rtype_code` ('rtype` *ret, const 'rtype` *array, 
ptrdiff_t shift,
          /* Otherwise, we will have to perform the copy one element at
             a time.  */
          'rtype_name` *dest = rptr;
-         const 'rtype_name` *src = &sptr[shift * soffset];
+         const 'rtype_name` *src = (const 'rtype_name` *) (((char*)sptr) + 
shift * soffset);
 
          for (n = 0; n < len - shift; n++)
            {
              *dest = *src;
-             dest += roffset;
-             src += soffset;
+             PTR_INCREMENT_BYTES (dest, roffset);
+             PTR_INCREMENT_BYTES (src, soffset);
            }
          for (src = sptr, n = 0; n < shift; n++)
            {
              *dest = *src;
-             dest += roffset;
-             src += soffset;
+             PTR_INCREMENT_BYTES (dest, roffset);
+             PTR_INCREMENT_BYTES (src, soffset);
            }
        }
 
       /* Advance to the next section.  */
-      rptr += rstride0;
-      sptr += sstride0;
+      PTR_INCREMENT_BYTES (rptr, rstride0);
+      PTR_INCREMENT_BYTES (sptr, sstride0);
       count[0]++;
       n = 0;
       while (count[n] == extent[n])
@@ -219,8 +219,8 @@ cshift0_'rtype_code` ('rtype` *ret, const 'rtype` *array, 
ptrdiff_t shift,
           count[n] = 0;
           /* We could precalculate these products, but this is a less
              frequently used path so probably not worth it.  */
-          rptr -= rstride[n] * extent[n];
-          sptr -= sstride[n] * extent[n];
+          PTR_DECREMENT_BYTES (rptr, rstride[n] * extent[n]);
+          PTR_DECREMENT_BYTES (sptr, sstride[n] * extent[n]);
           n++;
           if (n >= dim - 1)
             {
@@ -231,8 +231,8 @@ cshift0_'rtype_code` ('rtype` *ret, const 'rtype` *array, 
ptrdiff_t shift,
           else
             {
               count[n]++;
-              rptr += rstride[n];
-              sptr += sstride[n];
+              PTR_INCREMENT_BYTES (rptr, rstride[n]);
+              PTR_INCREMENT_BYTES (sptr, sstride[n]);
             }
         }
     }
diff --git a/libgfortran/m4/cshift1.m4 b/libgfortran/m4/cshift1.m4
index d954b6ca70b1..bbb521c3a240 100644
--- a/libgfortran/m4/cshift1.m4
+++ b/libgfortran/m4/cshift1.m4
@@ -230,7 +230,7 @@ cshift1 (gfc_array_char * const restrict ret,
           rstride[n] = GFC_DESCRIPTOR_STRIDE_BYTES(ret,dim);
           sstride[n] = GFC_DESCRIPTOR_STRIDE_BYTES(array,dim);
 
-          hstride[n] = GFC_DESCRIPTOR_STRIDE(h,n);
+          hstride[n] = GFC_DESCRIPTOR_STRIDE_BYTES(h,n);
           n++;
         }
     }
@@ -239,7 +239,7 @@ cshift1 (gfc_array_char * const restrict ret,
   if (rstride[0] == 0)
     rstride[0] = size;
   if (hstride[0] == 0)
-    hstride[0] = 1;
+    hstride[0] = sizeof ('atype_name`);
 
   dim = GFC_DESCRIPTOR_RANK (array);
   rstride0 = rstride[0];
@@ -292,7 +292,7 @@ cshift1 (gfc_array_char * const restrict ret,
       /* Advance to the next section.  */
       rptr += rstride0;
       sptr += sstride0;
-      hptr += hstride0;
+      PTR_INCREMENT_BYTES (hptr, hstride0);
       count[0]++;
       n = 0;
       while (count[n] == extent[n])
@@ -302,9 +302,9 @@ cshift1 (gfc_array_char * const restrict ret,
           count[n] = 0;
           /* We could precalculate these products, but this is a less
              frequently used path so probably not worth it.  */
+         PTR_DECREMENT_BYTES (hptr, hstride[n] * extent[n]);
           rptr -= rstride[n] * extent[n];
           sptr -= sstride[n] * extent[n];
-         hptr -= hstride[n] * extent[n];
           n++;
           if (n >= dim - 1)
             {
@@ -317,7 +317,7 @@ cshift1 (gfc_array_char * const restrict ret,
               count[n]++;
               rptr += rstride[n];
               sptr += sstride[n];
-             hptr += hstride[n];
+             PTR_INCREMENT_BYTES (hptr, hstride[n]);
             }
         }
     }
diff --git a/libgfortran/m4/cshift1a.m4 b/libgfortran/m4/cshift1a.m4
index b78d16aaa72d..1b5f983a2404 100644
--- a/libgfortran/m4/cshift1a.m4
+++ b/libgfortran/m4/cshift1a.m4
@@ -84,21 +84,21 @@ cshift1'rtype_qual`_'atype_code` ('atype` * const restrict 
ret,
     {
       if (dim == which)
         {
-          roffset = GFC_DESCRIPTOR_STRIDE(ret,dim);
+          roffset = GFC_DESCRIPTOR_STRIDE_BYTES(ret,dim);
           if (roffset == 0)
-            roffset = 1;
-          soffset = GFC_DESCRIPTOR_STRIDE(array,dim);
+            roffset = sizeof ('atype_name`);
+          soffset = GFC_DESCRIPTOR_STRIDE_BYTES(array,dim);
           if (soffset == 0)
-            soffset = 1;
+            soffset = sizeof ('atype_name`);
           len = GFC_DESCRIPTOR_EXTENT(array,dim);
         }
       else
         {
           count[n] = 0;
           extent[n] = GFC_DESCRIPTOR_EXTENT(array,dim);
-          rstride[n] = GFC_DESCRIPTOR_STRIDE(ret,dim);
-          sstride[n] = GFC_DESCRIPTOR_STRIDE(array,dim);
-          hstride[n] = GFC_DESCRIPTOR_STRIDE(h,n);
+          rstride[n] = GFC_DESCRIPTOR_STRIDE_BYTES(ret,dim);
+          sstride[n] = GFC_DESCRIPTOR_STRIDE_BYTES(array,dim);
+          hstride[n] = GFC_DESCRIPTOR_STRIDE_BYTES(h,n);
          rs_ex[n] = rstride[n] * extent[n];
          ss_ex[n] = sstride[n] * extent[n];
          hs_ex[n] = hstride[n] * extent[n];
@@ -106,11 +106,11 @@ cshift1'rtype_qual`_'atype_code` ('atype` * const 
restrict ret,
         }
     }
   if (sstride[0] == 0)
-    sstride[0] = 1;
+    sstride[0] = sizeof ('atype_name`);
   if (rstride[0] == 0)
-    rstride[0] = 1;
+    rstride[0] = sizeof ('atype_name`);
   if (hstride[0] == 0)
-    hstride[0] = 1;
+    hstride[0] = sizeof ('rtype_name`);
 
   dim = GFC_DESCRIPTOR_RANK (array);
   rstride0 = rstride[0];
@@ -134,9 +134,9 @@ cshift1'rtype_qual`_'atype_code` ('atype` * const restrict 
ret,
          if (sh < 0)
             sh += len;
        }
-      src = &sptr[sh * soffset];
+      src = (const 'atype_name` *) (((char*)sptr) + sh * soffset);
       dest = rptr;
-      if (soffset == 1 && roffset == 1)
+      if (soffset == sizeof ('atype_name`) && roffset == sizeof ('atype_name`))
        {
          size_t len1 = sh * sizeof ('atype_name`);
          size_t len2 = (len - sh) * sizeof ('atype_name`);
@@ -148,21 +148,21 @@ cshift1'rtype_qual`_'atype_code` ('atype` * const 
restrict ret,
          for (n = 0; n < len - sh; n++)
            {
              *dest = *src;
-             dest += roffset;
-             src += soffset;
+             PTR_INCREMENT_BYTES (dest, roffset);
+             PTR_INCREMENT_BYTES (src, soffset);
            }
          for (src = sptr, n = 0; n < sh; n++)
            {
              *dest = *src;
-             dest += roffset;
-             src += soffset;
+             PTR_INCREMENT_BYTES (dest, roffset);
+             PTR_INCREMENT_BYTES (src, soffset);
            }
        }
 
       /* Advance to the next section.  */
-      rptr += rstride0;
-      sptr += sstride0;
-      hptr += hstride0;
+      PTR_INCREMENT_BYTES (rptr, rstride0);
+      PTR_INCREMENT_BYTES (sptr, sstride0);
+      PTR_INCREMENT_BYTES (hptr, hstride0);
       count[0]++;
       n = 0;
       while (count[n] == extent[n])
@@ -170,9 +170,9 @@ cshift1'rtype_qual`_'atype_code` ('atype` * const restrict 
ret,
           /* When we get to the end of a dimension, reset it and increment
              the next dimension.  */
           count[n] = 0;
-          rptr -= rs_ex[n];
-          sptr -= ss_ex[n];
-         hptr -= hs_ex[n];
+          PTR_DECREMENT_BYTES (rptr, rs_ex[n]);
+          PTR_DECREMENT_BYTES (sptr, ss_ex[n]);
+         PTR_DECREMENT_BYTES (hptr, hs_ex[n]);
           n++;
           if (n >= dim - 1)
             {
@@ -183,9 +183,9 @@ cshift1'rtype_qual`_'atype_code` ('atype` * const restrict 
ret,
           else
             {
               count[n]++;
-              rptr += rstride[n];
-              sptr += sstride[n];
-             hptr += hstride[n];
+              PTR_INCREMENT_BYTES (rptr, rstride[n]);
+              PTR_INCREMENT_BYTES (sptr, sstride[n]);
+             PTR_INCREMENT_BYTES (hptr, hstride[n]);
             }
         }
     }
diff --git a/libgfortran/m4/eoshift1.m4 b/libgfortran/m4/eoshift1.m4
index f878894c6240..7de92f2054e2 100644
--- a/libgfortran/m4/eoshift1.m4
+++ b/libgfortran/m4/eoshift1.m4
@@ -140,7 +140,7 @@ eoshift1 (gfc_array_char * const restrict ret,
           rstride[n] = GFC_DESCRIPTOR_STRIDE_BYTES(ret,dim);
           sstride[n] = GFC_DESCRIPTOR_STRIDE_BYTES(array,dim);
 
-          hstride[n] = GFC_DESCRIPTOR_STRIDE(h,n);
+          hstride[n] = GFC_DESCRIPTOR_STRIDE_BYTES(h,n);
           n++;
         }
     }
@@ -149,7 +149,7 @@ eoshift1 (gfc_array_char * const restrict ret,
   if (rstride[0] == 0)
     rstride[0] = size;
   if (hstride[0] == 0)
-    hstride[0] = 1;
+    hstride[0] = GFC_DESCRIPTOR_SIZE(h);
 
   dim = GFC_DESCRIPTOR_RANK (array);
   rstride0 = rstride[0];
@@ -225,7 +225,7 @@ eoshift1 (gfc_array_char * const restrict ret,
       /* Advance to the next section.  */
       rptr += rstride0;
       sptr += sstride0;
-      hptr += hstride0;
+      PTR_INCREMENT_BYTES (hptr, hstride0);
       count[0]++;
       n = 0;
       while (count[n] == extent[n])
@@ -235,9 +235,9 @@ eoshift1 (gfc_array_char * const restrict ret,
           count[n] = 0;
           /* We could precalculate these products, but this is a less
              frequently used path so probably not worth it.  */
+         PTR_DECREMENT_BYTES (hptr, hstride[n] * extent[n]);
           rptr -= rstride[n] * extent[n];
           sptr -= sstride[n] * extent[n];
-         hptr -= hstride[n] * extent[n];
           n++;
           if (n >= dim - 1)
             {
@@ -250,7 +250,7 @@ eoshift1 (gfc_array_char * const restrict ret,
               count[n]++;
               rptr += rstride[n];
               sptr += sstride[n];
-             hptr += hstride[n];
+             PTR_INCREMENT_BYTES (hptr, hstride[n]);
             }
         }
     }
diff --git a/libgfortran/m4/eoshift3.m4 b/libgfortran/m4/eoshift3.m4
index 6e877e82f910..28706a998194 100644
--- a/libgfortran/m4/eoshift3.m4
+++ b/libgfortran/m4/eoshift3.m4
@@ -144,7 +144,7 @@ eoshift3 (gfc_array_char * const restrict ret,
           rstride[n] = GFC_DESCRIPTOR_STRIDE_BYTES(ret,dim);
           sstride[n] = GFC_DESCRIPTOR_STRIDE_BYTES(array,dim);
 
-          hstride[n] = GFC_DESCRIPTOR_STRIDE(h,n);
+          hstride[n] = GFC_DESCRIPTOR_STRIDE_BYTES(h,n);
           if (bound)
             bstride[n] = GFC_DESCRIPTOR_STRIDE_BYTES(bound,n);
           else
@@ -157,7 +157,7 @@ eoshift3 (gfc_array_char * const restrict ret,
   if (rstride[0] == 0)
     rstride[0] = size;
   if (hstride[0] == 0)
-    hstride[0] = 1;
+    hstride[0] = GFC_DESCRIPTOR_SIZE(h);
   if (bound && bstride[0] == 0)
     bstride[0] = size;
 
@@ -239,9 +239,9 @@ eoshift3 (gfc_array_char * const restrict ret,
          }
 
       /* Advance to the next section.  */
+      PTR_INCREMENT_BYTES (hptr, hstride0);
       rptr += rstride0;
       sptr += sstride0;
-      hptr += hstride0;
       bptr += bstride0;
       count[0]++;
       n = 0;
@@ -252,9 +252,9 @@ eoshift3 (gfc_array_char * const restrict ret,
           count[n] = 0;
           /* We could precalculate these products, but this is a less
              frequently used path so probably not worth it.  */
+         PTR_DECREMENT_BYTES (hptr, hstride[n] * extent[n]);
           rptr -= rstride[n] * extent[n];
           sptr -= sstride[n] * extent[n];
-         hptr -= hstride[n] * extent[n];
           bptr -= bstride[n] * extent[n];
           n++;
           if (n >= dim - 1)
@@ -266,9 +266,9 @@ eoshift3 (gfc_array_char * const restrict ret,
           else
             {
               count[n]++;
+             PTR_INCREMENT_BYTES (hptr, hstride[n]);
               rptr += rstride[n];
               sptr += sstride[n];
-             hptr += hstride[n];
               bptr += bstride[n];
             }
         }
diff --git a/libgfortran/m4/findloc2s.m4 b/libgfortran/m4/findloc2s.m4
index a0f13f8cadb2..1508355c1512 100644
--- a/libgfortran/m4/findloc2s.m4
+++ b/libgfortran/m4/findloc2s.m4
@@ -40,5 +40,4 @@ define(comparison,ifelse(atype_kind,4,dnl
 `compare_string_char4 (len_array, src, len_value, value) == 0',dnl
 `compare_string (len_array, (char *) src, len_value, (char *) value) == 0'))dnl
 define(len_arg,`len_array, len_value')dnl
-define(base_mult,`len_array')dnl
 include(ifindloc2.m4)dnl
diff --git a/libgfortran/m4/ifindloc0.m4 b/libgfortran/m4/ifindloc0.m4
index c484342f3cb9..a6e50299ccd0 100644
--- a/libgfortran/m4/ifindloc0.m4
+++ b/libgfortran/m4/ifindloc0.m4
@@ -67,7 +67,7 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If 
not, see
   sz = 1;
   for (n = 0; n < rank; n++)
     {
-      sstride[n] = GFC_DESCRIPTOR_STRIDE(array,n);
+      sstride[n] = GFC_DESCRIPTOR_STRIDE_BYTES(array,n);
       extent[n] = GFC_DESCRIPTOR_EXTENT(array,n);
       sz *= extent[n];
       if (extent[n] <= 0)
@@ -92,7 +92,7 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If 
not, see
 
                  return;
                }
-             base -= sstride[0] * 'base_mult`;
+             PTR_DECREMENT_BYTES (base, sstride[0]);
            } while(++count[0] != extent[0]);
 
          n = 0;
@@ -103,14 +103,14 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  
If not, see
              count[n] = 0;
              /* We could precalculate these products, but this is a less
                 frequently used path so probably not worth it.  */
-             base += sstride[n] * extent[n] * 'base_mult`;
+             PTR_INCREMENT_BYTES (base, sstride[n] * extent[n]);
              n++;
              if (n >= rank)
                return;
              else
                {
                  count[n]++;
-                 base -= sstride[n] * 'base_mult`;
+                 PTR_DECREMENT_BYTES (base, sstride[n]);
                }
            } while (count[n] == extent[n]);      
        }
@@ -129,7 +129,7 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  
If not, see
 
                  return;
                }
-             base += sstride[0] * 'base_mult`;
+             PTR_INCREMENT_BYTES (base, sstride[0]);
            } while(++count[0] != extent[0]);
 
          n = 0;
@@ -140,14 +140,14 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  
If not, see
              count[n] = 0;
              /* We could precalculate these products, but this is a less
                 frequently used path so probably not worth it.  */
-             base -= sstride[n] * extent[n] * 'base_mult`;
+             PTR_DECREMENT_BYTES (base, sstride[n] * extent[n]);
              n++;
              if (n >= rank)
                return;
              else
                {
                  count[n]++;
-                 base += sstride[n] * 'base_mult`;
+                 PTR_INCREMENT_BYTES (base, sstride[n]);
                }
            } while (count[n] == extent[n]);
        }
@@ -215,7 +215,7 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  
If not, see
   sz = 1;
   for (n = 0; n < rank; n++)
     {
-      sstride[n] = GFC_DESCRIPTOR_STRIDE(array,n);
+      sstride[n] = GFC_DESCRIPTOR_STRIDE_BYTES(array,n);
       mstride[n] = GFC_DESCRIPTOR_STRIDE_BYTES(mask,n);
       extent[n] = GFC_DESCRIPTOR_EXTENT(array,n);
       sz *= extent[n];
@@ -241,7 +241,7 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  
If not, see
 
                  return;
                }
-             base -= sstride[0] * 'base_mult`;
+             PTR_DECREMENT_BYTES (base, sstride[0]);
              mbase -= mstride[0];
            } while(++count[0] != extent[0]);
 
@@ -253,7 +253,7 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  
If not, see
              count[n] = 0;
              /* We could precalculate these products, but this is a less
                 frequently used path so probably not worth it.  */
-             base += sstride[n] * extent[n] * 'base_mult`;
+             PTR_INCREMENT_BYTES (base, sstride[n] * extent[n]);
              mbase -= mstride[n] * extent[n];
              n++;
              if (n >= rank)
@@ -261,7 +261,7 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  
If not, see
              else
                {
                  count[n]++;
-                 base -= sstride[n] * 'base_mult`;
+                 PTR_DECREMENT_BYTES (base, sstride[n]);
                  mbase += mstride[n];
                }
            } while (count[n] == extent[n]);      
@@ -281,7 +281,7 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  
If not, see
 
                  return;
                }
-             base += sstride[0] * 'base_mult`;
+             PTR_INCREMENT_BYTES (base, sstride[0]);
              mbase += mstride[0];
            } while(++count[0] != extent[0]);
 
@@ -293,7 +293,7 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  
If not, see
              count[n] = 0;
              /* We could precalculate these products, but this is a less
                 frequently used path so probably not worth it.  */
-             base -= sstride[n] * extent[n] * 'base_mult`;
+             PTR_DECREMENT_BYTES (base, sstride[n] * extent[n]);
              mbase -= mstride[n] * extent[n];
              n++;
              if (n >= rank)
@@ -301,7 +301,7 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  
If not, see
              else
                {
                  count[n]++;
-                 base += sstride[n]* 'base_mult`;
+                 PTR_INCREMENT_BYTES (base, sstride[n]);
                  mbase += mstride[n];
                }
            } while (count[n] == extent[n]);
diff --git a/libgfortran/m4/ifindloc1.m4 b/libgfortran/m4/ifindloc1.m4
index 7b2c2d2a6557..8e2eb95df7f4 100644
--- a/libgfortran/m4/ifindloc1.m4
+++ b/libgfortran/m4/ifindloc1.m4
@@ -56,11 +56,11 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  
If not, see
   len = GFC_DESCRIPTOR_EXTENT(array,dim);
   if (len < 0)
     len = 0;
-  delta = GFC_DESCRIPTOR_STRIDE(array,dim);
+  delta = GFC_DESCRIPTOR_STRIDE_BYTES(array,dim);
 
   for (n = 0; n < dim; n++)
     {
-      sstride[n] = GFC_DESCRIPTOR_STRIDE(array,n);
+      sstride[n] = GFC_DESCRIPTOR_STRIDE_BYTES(array,n);
       extent[n] = GFC_DESCRIPTOR_EXTENT(array,n);
 
       if (extent[n] < 0)
@@ -68,7 +68,7 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If 
not, see
     }
   for (n = dim; n < rank; n++)
     {
-      sstride[n] = GFC_DESCRIPTOR_STRIDE(array, n + 1);
+      sstride[n] = GFC_DESCRIPTOR_STRIDE_BYTES(array, n + 1);
       extent[n] = GFC_DESCRIPTOR_EXTENT(array, n + 1);
 
       if (extent[n] < 0)
@@ -114,7 +114,7 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  
If not, see
   for (n = 0; n < rank; n++)
     {
       count[n] = 0;
-      dstride[n] = GFC_DESCRIPTOR_STRIDE(retarray,n);
+      dstride[n] = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,n);
       if (extent[n] <= 0)
        return;
     }
@@ -131,39 +131,41 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  
If not, see
       result = 0;
       if (back)
        {
-         src = base + (len - 1) * delta * 'base_mult`;
-         for (n = len; n > 0; n--, src -= delta * 'base_mult`)
+         src = (const 'atype_name` * restrict) (((char*) base) + (len - 1) * 
delta);
+         for (n = len; n > 0; n--)
            {
              if ('comparison`)
                {
                  result = n;
                  break;
                }
+             PTR_DECREMENT_BYTES (src, delta);
            }
        }
       else
        {
          src = base;
-         for (n = 1; n <= len; n++, src += delta * 'base_mult`)
+         for (n = 1; n <= len; n++)
            {
              if ('comparison`)
                {
                  result = n;
                  break;
                }
+             PTR_INCREMENT_BYTES (src, delta);
            }
        }
       *dest = result;
 
       count[0]++;
-      base += sstride[0] * 'base_mult`;
-      dest += dstride[0];
+      PTR_INCREMENT_BYTES (base, sstride[0]);
+      PTR_INCREMENT_BYTES (dest, dstride[0]);
       n = 0;
       while (count[n] == extent[n])
        {
          count[n] = 0;
-         base -= sstride[n] * extent[n] * 'base_mult`;
-         dest -= dstride[n] * extent[n];
+         PTR_DECREMENT_BYTES (base, sstride[n] * extent[n]);
+         PTR_DECREMENT_BYTES (dest, dstride[n] * extent[n]);
          n++;
          if (n >= rank)
            {
@@ -173,8 +175,8 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  
If not, see
          else
            {
              count[n]++;
-             base += sstride[n] * 'base_mult`;
-             dest += dstride[n];
+             PTR_INCREMENT_BYTES (base, sstride[n]);
+             PTR_INCREMENT_BYTES (dest, dstride[n]);
            }
        }
     }
@@ -213,7 +215,7 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  
If not, see
   if (len < 0)
     len = 0;
 
-  delta = GFC_DESCRIPTOR_STRIDE(array,dim);
+  delta = GFC_DESCRIPTOR_STRIDE_BYTES(array,dim);
   mdelta = GFC_DESCRIPTOR_STRIDE_BYTES(mask,dim);
 
   mbase = mask->base_addr;
@@ -231,7 +233,7 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  
If not, see
 
   for (n = 0; n < dim; n++)
     {
-      sstride[n] = GFC_DESCRIPTOR_STRIDE(array,n);
+      sstride[n] = GFC_DESCRIPTOR_STRIDE_BYTES(array,n);
       mstride[n] = GFC_DESCRIPTOR_STRIDE_BYTES(mask,n);
       extent[n] = GFC_DESCRIPTOR_EXTENT(array,n);
 
@@ -240,7 +242,7 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  
If not, see
     }
   for (n = dim; n < rank; n++)
     {
-      sstride[n] = GFC_DESCRIPTOR_STRIDE(array, n + 1);
+      sstride[n] = GFC_DESCRIPTOR_STRIDE_BYTES(array, n + 1);
       mstride[n] = GFC_DESCRIPTOR_STRIDE_BYTES(mask, n + 1);
       extent[n] = GFC_DESCRIPTOR_EXTENT(array, n + 1);
 
@@ -287,7 +289,7 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  
If not, see
   for (n = 0; n < rank; n++)
     {
       count[n] = 0;
-      dstride[n] = GFC_DESCRIPTOR_STRIDE(retarray,n);
+      dstride[n] = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,n);
       if (extent[n] <= 0)
        return;
     }
@@ -305,43 +307,47 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  
If not, see
       result = 0;
       if (back)
        {
-         src = base + (len - 1) * delta * 'base_mult`;
+         src = (const 'atype_name` * restrict) (((char*)base) + (len - 1) * 
delta);
          msrc = mbase + (len - 1) * mdelta; 
-         for (n = len; n > 0; n--, src -= delta * 'base_mult`, msrc -= mdelta)
+         for (n = len; n > 0; n--)
            {
              if (*msrc && 'comparison`)
                {
                  result = n;
                  break;
                }
+             PTR_DECREMENT_BYTES (src, delta);
+             msrc -= mdelta;
            }
        }
       else
        {
          src = base;
          msrc = mbase;
-         for (n = 1; n <= len; n++, src += delta * 'base_mult`, msrc += mdelta)
+         for (n = 1; n <= len; n++)
            {
              if (*msrc && 'comparison`)
                {
                  result = n;
                  break;
                }
+             PTR_INCREMENT_BYTES (src, delta);
+             msrc += mdelta;
            }
        }
       *dest = result;
 
       count[0]++;
-      base += sstride[0] * 'base_mult`;
+      PTR_INCREMENT_BYTES (base, sstride[0]);
+      PTR_INCREMENT_BYTES (dest, dstride[0]);
       mbase += mstride[0];
-      dest += dstride[0];
       n = 0;
       while (count[n] == extent[n])
        {
          count[n] = 0;
-         base -= sstride[n] * extent[n] * 'base_mult`;
+         PTR_DECREMENT_BYTES (base, sstride[n] * extent[n]);
+         PTR_DECREMENT_BYTES (dest, dstride[n] * extent[n]);
          mbase -= mstride[n] * extent[n];
-         dest -= dstride[n] * extent[n];
          n++;
          if (n >= rank)
            {
@@ -351,8 +357,8 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  
If not, see
          else
            {
              count[n]++;
-             base += sstride[n] * 'base_mult`;
-             dest += dstride[n];
+             PTR_INCREMENT_BYTES (base, sstride[n]);
+             PTR_INCREMENT_BYTES (dest, dstride[n]);
            }
        }
     }
@@ -446,7 +452,7 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  
If not, see
   for (n = 0; n < rank; n++)
     {
       count[n] = 0;
-      dstride[n] = GFC_DESCRIPTOR_STRIDE(retarray,n);
+      dstride[n] = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,n);
       if (extent[n] <= 0)
        return;
     }
@@ -458,12 +464,12 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  
If not, see
       *dest = 0;
 
       count[0]++;
-      dest += dstride[0];
+      PTR_INCREMENT_BYTES (dest, dstride[0]);
       n = 0;
       while (count[n] == extent[n])
        {
          count[n] = 0;
-         dest -= dstride[n] * extent[n];
+         PTR_DECREMENT_BYTES (dest, dstride[n] * extent[n]);
          n++;
          if (n >= rank)
            {
@@ -473,7 +479,7 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  
If not, see
          else
            {
              count[n]++;
-             dest += dstride[n];
+             PTR_INCREMENT_BYTES (dest, dstride[n]);
            }
        }
     }
diff --git a/libgfortran/m4/ifindloc2.m4 b/libgfortran/m4/ifindloc2.m4
index c90474503b3d..14062a1a67f0 100644
--- a/libgfortran/m4/ifindloc2.m4
+++ b/libgfortran/m4/ifindloc2.m4
@@ -37,15 +37,15 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  
If not, see
   if (extent <= 0)
     return 0;
 
-  sstride = GFC_DESCRIPTOR_STRIDE(array,0) * 'base_mult`;
+  sstride = GFC_DESCRIPTOR_STRIDE_BYTES(array,0);
   if (back)
     {
-      src = array->base_addr + (extent - 1) * sstride;
+      src = (const 'atype_name` * restrict) (((char*)array->base_addr) + 
(extent - 1) * sstride);
       for (i = extent; i > 0; i--)
        {
          if ('comparison`)
            return i;
-         src -= sstride;
+         PTR_DECREMENT_BYTES (src, sstride);
        }
     }
   else
@@ -55,7 +55,7 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If 
not, see
        {
          if ('comparison`)
            return i;
-         src += sstride;
+         PTR_INCREMENT_BYTES (src, sstride);
        }
     }
   return 0;
@@ -87,18 +87,18 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  
If not, see
   else
     internal_error (NULL, "Funny sized logical array");
 
-  sstride = GFC_DESCRIPTOR_STRIDE(array,0) * 'base_mult`;
+  sstride = GFC_DESCRIPTOR_STRIDE_BYTES(array,0);
   mstride = GFC_DESCRIPTOR_STRIDE_BYTES(mask,0);
 
   if (back)
     {
-      src = array->base_addr + (extent - 1) * sstride;
+      src = (const 'atype_name` * restrict) (((char*)array->base_addr) + 
(extent - 1) * sstride);
       mbase += (extent - 1) * mstride;
       for (i = extent; i > 0; i--)
        {
          if (*mbase && ('comparison`))
            return i;
-         src -= sstride;
+         PTR_DECREMENT_BYTES (src, sstride);
          mbase -= mstride;
        }
     }
diff --git a/libgfortran/m4/iforeach-s.m4 b/libgfortran/m4/iforeach-s.m4
index b00f900a5fd7..88101c53d6c7 100644
--- a/libgfortran/m4/iforeach-s.m4
+++ b/libgfortran/m4/iforeach-s.m4
@@ -52,7 +52,7 @@ void
   dest = retarray->base_addr;
   for (n = 0; n < rank; n++)
     {
-      sstride[n] = GFC_DESCRIPTOR_STRIDE(array,n) * len;
+      sstride[n] = GFC_DESCRIPTOR_STRIDE_BYTES(array,n);
       extent[n] = GFC_DESCRIPTOR_EXTENT(array,n);
       count[n] = 0;
       if (extent[n] <= 0)
@@ -81,7 +81,7 @@ define(START_FOREACH_BLOCK,
 define(FINISH_FOREACH_FUNCTION,
 `        /* Implementation end.  */
          /* Advance to the next element.  */
-         base += sstride[0];
+         PTR_INCREMENT_BYTES (base, sstride[0]);
        }
       while (++count[0] != extent[0]);
       n = 0;
@@ -92,7 +92,7 @@ define(FINISH_FOREACH_FUNCTION,
          count[n] = 0;
          /* We could precalculate these products, but this is a less
             frequently used path so probably not worth it.  */
-         base -= sstride[n] * extent[n];
+         PTR_DECREMENT_BYTES (base, sstride[n] * extent[n]);
          n++;
          if (n >= rank)
            {
@@ -103,7 +103,7 @@ define(FINISH_FOREACH_FUNCTION,
          else
            {
              count[n]++;
-             base += sstride[n];
+             PTR_INCREMENT_BYTES (base, sstride[n]);
            }
        }
       while (count[n] == extent[n]);
@@ -185,7 +185,7 @@ m'name`'rtype_qual`_'atype_code` ('rtype` * const restrict 
retarray,
   dest = retarray->base_addr;
   for (n = 0; n < rank; n++)
     {
-      sstride[n] = GFC_DESCRIPTOR_STRIDE(array,n) * len;
+      sstride[n] = GFC_DESCRIPTOR_STRIDE_BYTES(array,n);
       mstride[n] = GFC_DESCRIPTOR_STRIDE_BYTES(mask,n);
       extent[n] = GFC_DESCRIPTOR_EXTENT(array,n);
       count[n] = 0;
@@ -209,7 +209,7 @@ define(START_MASKED_FOREACH_BLOCK, `START_FOREACH_BLOCK')dnl
 define(FINISH_MASKED_FOREACH_FUNCTION,
 `        /* Implementation end.  */
          /* Advance to the next element.  */
-         base += sstride[0];
+         PTR_INCREMENT_BYTES (base, sstride[0]);
          mbase += mstride[0];
        }
       while (++count[0] != extent[0]);
@@ -221,7 +221,7 @@ define(FINISH_MASKED_FOREACH_FUNCTION,
          count[n] = 0;
          /* We could precalculate these products, but this is a less
             frequently used path so probably not worth it.  */
-         base -= sstride[n] * extent[n];
+         PTR_DECREMENT_BYTES (base, sstride[n] * extent[n]);
          mbase -= mstride[n] * extent[n];
          n++;
          if (n >= rank)
@@ -233,7 +233,7 @@ define(FINISH_MASKED_FOREACH_FUNCTION,
          else
            {
              count[n]++;
-             base += sstride[n];
+             PTR_INCREMENT_BYTES (base, sstride[n]);
              mbase += mstride[n];
            }
        }
@@ -291,7 +291,7 @@ void
       GFC_DESCRIPTOR_DIMENSION_SET(retarray, 0, 0, rank-1, 1);
       retarray->dtype.rank = 1;
       retarray->offset = 0;
-      retarray->base_addr = xmallocarray (rank, sizeof (rtype_name));
+      retarray->base_addr = xmallocarray (rank, sizeof ('rtype_name`));
     }
   else if (unlikely (compile_options.bounds_check))
     {
diff --git a/libgfortran/m4/iforeach-s2.m4 b/libgfortran/m4/iforeach-s2.m4
index c2248f312754..3c3236c3a425 100644
--- a/libgfortran/m4/iforeach-s2.m4
+++ b/libgfortran/m4/iforeach-s2.m4
@@ -43,7 +43,7 @@ void
 
   for (n = 0; n < rank; n++)
     {
-      sstride[n] = GFC_DESCRIPTOR_STRIDE(array,n) * len;
+      sstride[n] = GFC_DESCRIPTOR_STRIDE_BYTES(array,n);
       extent[n] = GFC_DESCRIPTOR_EXTENT(array,n);
       count[n] = 0;
       if (extent[n] <= 0)
@@ -64,7 +64,7 @@ define(START_FOREACH_BLOCK,
 define(FINISH_FOREACH_FUNCTION,
 `        /* Implementation end.  */
          /* Advance to the next element.  */
-         base += sstride[0];
+         PTR_INCREMENT_BYTES (base, sstride[0]);
        }
       while (++count[0] != extent[0]);
       n = 0;
@@ -75,7 +75,7 @@ define(FINISH_FOREACH_FUNCTION,
          count[n] = 0;
          /* We could precalculate these products, but this is a less
             frequently used path so probably not worth it.  */
-         base -= sstride[n] * extent[n];
+         PTR_DECREMENT_BYTES (base, sstride[n] * extent[n]);
          n++;
          if (n >= rank)
            {
@@ -86,7 +86,7 @@ define(FINISH_FOREACH_FUNCTION,
          else
            {
              count[n]++;
-             base += sstride[n];
+             PTR_INCREMENT_BYTES (base, sstride[n]);
            }
        }
       while (count[n] == extent[n]);
@@ -146,7 +146,7 @@ m'name`'rtype_qual`_'atype_code` ('atype_name` * const 
restrict ret,
 
   for (n = 0; n < rank; n++)
     {
-      sstride[n] = GFC_DESCRIPTOR_STRIDE(array,n) * len;
+      sstride[n] = GFC_DESCRIPTOR_STRIDE_BYTES(array,n);
       mstride[n] = GFC_DESCRIPTOR_STRIDE_BYTES(mask,n);
       extent[n] = GFC_DESCRIPTOR_EXTENT(array,n);
       count[n] = 0;
@@ -161,7 +161,7 @@ define(START_MASKED_FOREACH_BLOCK, `START_FOREACH_BLOCK')dnl
 define(FINISH_MASKED_FOREACH_FUNCTION,
 `        /* Implementation end.  */
          /* Advance to the next element.  */
-         base += sstride[0];
+         PTR_INCREMENT_BYTES (base, sstride[0]);
          mbase += mstride[0];
        }
       while (++count[0] != extent[0]);
@@ -173,7 +173,7 @@ define(FINISH_MASKED_FOREACH_FUNCTION,
          count[n] = 0;
          /* We could precalculate these products, but this is a less
             frequently used path so probably not worth it.  */
-         base -= sstride[n] * extent[n];
+         PTR_DECREMENT_BYTES (base, sstride[n] * extent[n]);
          mbase -= mstride[n] * extent[n];
          n++;
          if (n >= rank)
@@ -185,7 +185,7 @@ define(FINISH_MASKED_FOREACH_FUNCTION,
          else
            {
              count[n]++;
-             base += sstride[n];
+             PTR_INCREMENT_BYTES (base, sstride[n]);
              mbase += mstride[n];
            }
        }
diff --git a/libgfortran/m4/iforeach.m4 b/libgfortran/m4/iforeach.m4
index 04ca0302e5f4..ca5664e537cb 100644
--- a/libgfortran/m4/iforeach.m4
+++ b/libgfortran/m4/iforeach.m4
@@ -43,7 +43,7 @@ void
   dest = retarray->base_addr;
   for (n = 0; n < rank; n++)
     {
-      sstride[n] = GFC_DESCRIPTOR_STRIDE(array,n);
+      sstride[n] = GFC_DESCRIPTOR_STRIDE_BYTES(array,n);
       extent[n] = GFC_DESCRIPTOR_EXTENT(array,n);
       count[n] = 0;
       if (extent[n] <= 0)
@@ -70,7 +70,7 @@ define(START_FOREACH_BLOCK,
 define(FINISH_FOREACH_FUNCTION,
 `        /* Implementation end.  */
          /* Advance to the next element.  */
-         base += sstride[0];
+         PTR_INCREMENT_BYTES (base, sstride[0]);
        }
       while (++count[0] != extent[0]);
       n = 0;
@@ -81,7 +81,7 @@ define(FINISH_FOREACH_FUNCTION,
          count[n] = 0;
          /* We could precalculate these products, but this is a less
             frequently used path so probably not worth it.  */
-         base -= sstride[n] * extent[n];
+         PTR_DECREMENT_BYTES (base, sstride[n] * extent[n]);
          n++;
          if (n >= rank)
            {
@@ -92,7 +92,7 @@ define(FINISH_FOREACH_FUNCTION,
          else
            {
              count[n]++;
-             base += sstride[n];
+             PTR_INCREMENT_BYTES (base, sstride[n]);
            }
        }
       while (count[n] == extent[n]);
@@ -170,7 +170,7 @@ m'name`'rtype_qual`_'atype_code` ('rtype` * const restrict 
retarray,
   dest = retarray->base_addr;
   for (n = 0; n < rank; n++)
     {
-      sstride[n] = GFC_DESCRIPTOR_STRIDE(array,n);
+      sstride[n] = GFC_DESCRIPTOR_STRIDE_BYTES(array,n);
       mstride[n] = GFC_DESCRIPTOR_STRIDE_BYTES(mask,n);
       extent[n] = GFC_DESCRIPTOR_EXTENT(array,n);
       count[n] = 0;
@@ -194,7 +194,7 @@ define(START_MASKED_FOREACH_BLOCK, `START_FOREACH_BLOCK')dnl
 define(FINISH_MASKED_FOREACH_FUNCTION,
 `        /* Implementation end.  */
          /* Advance to the next element.  */
-         base += sstride[0];
+         PTR_INCREMENT_BYTES (base, sstride[0]);
          mbase += mstride[0];
        }
       while (++count[0] != extent[0]);
@@ -206,7 +206,7 @@ define(FINISH_MASKED_FOREACH_FUNCTION,
          count[n] = 0;
          /* We could precalculate these products, but this is a less
             frequently used path so probably not worth it.  */
-         base -= sstride[n] * extent[n];
+         PTR_DECREMENT_BYTES (base, sstride[n] * extent[n]);
          mbase -= mstride[n] * extent[n];
          n++;
          if (n >= rank)
@@ -218,7 +218,7 @@ define(FINISH_MASKED_FOREACH_FUNCTION,
          else
            {
              count[n]++;
-             base += sstride[n];
+             PTR_INCREMENT_BYTES (base, sstride[n]);
              mbase += mstride[n];
            }
        }
diff --git a/libgfortran/m4/ifunction-s.m4 b/libgfortran/m4/ifunction-s.m4
index 61cc898c3e5d..e5a4d6e3a829 100644
--- a/libgfortran/m4/ifunction-s.m4
+++ b/libgfortran/m4/ifunction-s.m4
@@ -68,11 +68,11 @@ void
   len = GFC_DESCRIPTOR_EXTENT(array,dim);
   if (len < 0)
     len = 0;
-  delta = GFC_DESCRIPTOR_STRIDE(array,dim) * string_len;
+  delta = GFC_DESCRIPTOR_STRIDE_BYTES(array,dim);
 
   for (n = 0; n < dim; n++)
     {
-      sstride[n] = GFC_DESCRIPTOR_STRIDE(array,n) * string_len;
+      sstride[n] = GFC_DESCRIPTOR_STRIDE_BYTES(array,n);
       extent[n] = GFC_DESCRIPTOR_EXTENT(array,n);
 
       if (extent[n] < 0)
@@ -80,7 +80,7 @@ void
     }
   for (n = dim; n < rank; n++)
     {
-      sstride[n] = GFC_DESCRIPTOR_STRIDE(array, n + 1) * string_len;
+      sstride[n] = GFC_DESCRIPTOR_STRIDE_BYTES(array, n + 1);
       extent[n] = GFC_DESCRIPTOR_EXTENT(array, n + 1);
 
       if (extent[n] < 0)
@@ -106,7 +106,7 @@ void
 
       alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
 
-      retarray->base_addr = xmallocarray (alloc_size, sizeof (rtype_name));
+      retarray->base_addr = xmallocarray (alloc_size, sizeof ('rtype_name`));
       if (alloc_size == 0)
        return;
     }
@@ -126,7 +126,7 @@ void
   for (n = 0; n < rank; n++)
     {
       count[n] = 0;
-      dstride[n] = GFC_DESCRIPTOR_STRIDE(retarray,n);
+      dstride[n] = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,n);
       if (extent[n] <= 0)
        return;
     }
@@ -147,10 +147,11 @@ define(START_ARRAY_BLOCK,
          *dest = '$1`;
        else
          {
-           for (n = 0; n < len; n++, src += delta)
+           for (n = 0; n < len; n++)
              {
 ')dnl
 define(FINISH_ARRAY_FUNCTION,
+               PTR_INCREMENT_BYTES (src, delta);
 `            }
            '$1`
            *dest = result;
@@ -158,8 +159,8 @@ define(FINISH_ARRAY_FUNCTION,
       }
       /* Advance to the next element.  */
       count[0]++;
-      base += sstride[0];
-      dest += dstride[0];
+      PTR_INCREMENT_BYTES (base, sstride[0]);
+      PTR_INCREMENT_BYTES (dest, dstride[0]);
       n = 0;
       while (count[n] == extent[n])
        {
@@ -168,8 +169,8 @@ define(FINISH_ARRAY_FUNCTION,
          count[n] = 0;
          /* We could precalculate these products, but this is a less
             frequently used path so probably not worth it.  */
-         base -= sstride[n] * extent[n];
-         dest -= dstride[n] * extent[n];
+         PTR_DECREMENT_BYTES (base, sstride[n] * extent[n]);
+         PTR_DECREMENT_BYTES (dest, dstride[n] * extent[n]);
          n++;
          if (n >= rank)
            {
@@ -180,8 +181,8 @@ define(FINISH_ARRAY_FUNCTION,
          else
            {
              count[n]++;
-             base += sstride[n];
-             dest += dstride[n];
+             PTR_INCREMENT_BYTES (base, sstride[n]);
+             PTR_INCREMENT_BYTES (dest, dstride[n]);
            }
        }
     }
@@ -254,12 +255,12 @@ m'name`'rtype_qual`_'atype_code` ('rtype` * const 
restrict retarray,
   else
     runtime_error ("Funny sized logical array");
 
-  delta = GFC_DESCRIPTOR_STRIDE(array,dim) * string_len;
+  delta = GFC_DESCRIPTOR_STRIDE_BYTES(array,dim);
   mdelta = GFC_DESCRIPTOR_STRIDE_BYTES(mask,dim);
 
   for (n = 0; n < dim; n++)
     {
-      sstride[n] = GFC_DESCRIPTOR_STRIDE(array,n) * string_len;
+      sstride[n] = GFC_DESCRIPTOR_STRIDE_BYTES(array,n);
       mstride[n] = GFC_DESCRIPTOR_STRIDE_BYTES(mask,n);
       extent[n] = GFC_DESCRIPTOR_EXTENT(array,n);
 
@@ -269,7 +270,7 @@ m'name`'rtype_qual`_'atype_code` ('rtype` * const restrict 
retarray,
     }
   for (n = dim; n < rank; n++)
     {
-      sstride[n] = GFC_DESCRIPTOR_STRIDE(array,n + 1) * string_len;
+      sstride[n] = GFC_DESCRIPTOR_STRIDE_BYTES(array,n + 1);
       mstride[n] = GFC_DESCRIPTOR_STRIDE_BYTES(mask, n + 1);
       extent[n] = GFC_DESCRIPTOR_EXTENT(array, n + 1);
 
@@ -296,7 +297,7 @@ m'name`'rtype_qual`_'atype_code` ('rtype` * const restrict 
retarray,
       retarray->offset = 0;
       retarray->dtype.rank = rank;
 
-      retarray->base_addr = xmallocarray (alloc_size, sizeof (rtype_name));
+      retarray->base_addr = xmallocarray (alloc_size, sizeof ('rtype_name`));
       if (alloc_size == 0)
        return;
     }
@@ -317,7 +318,7 @@ m'name`'rtype_qual`_'atype_code` ('rtype` * const restrict 
retarray,
   for (n = 0; n < rank; n++)
     {
       count[n] = 0;
-      dstride[n] = GFC_DESCRIPTOR_STRIDE(retarray,n);
+      dstride[n] = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,n);
       if (extent[n] <= 0)
        return;
     }
@@ -335,18 +336,20 @@ m'name`'rtype_qual`_'atype_code` ('rtype` * const 
restrict retarray,
       {
 ')dnl
 define(START_MASKED_ARRAY_BLOCK,
-`      for (n = 0; n < len; n++, src += delta, msrc += mdelta)
+`      for (n = 0; n < len; n++)
          {
 ')dnl
 define(FINISH_MASKED_ARRAY_FUNCTION,
-`        }
+`          PTR_INCREMENT_BYTES (src, delta);
+           msrc += mdelta;
+         }
        *dest = result;
       }
       /* Advance to the next element.  */
       count[0]++;
-      base += sstride[0];
+      PTR_INCREMENT_BYTES (base, sstride[0]);
+      PTR_INCREMENT_BYTES (dest, dstride[0]);
       mbase += mstride[0];
-      dest += dstride[0];
       n = 0;
       while (count[n] == extent[n])
        {
@@ -355,9 +358,9 @@ define(FINISH_MASKED_ARRAY_FUNCTION,
          count[n] = 0;
          /* We could precalculate these products, but this is a less
             frequently used path so probably not worth it.  */
-         base -= sstride[n] * extent[n];
+         PTR_DECREMENT_BYTES (base, sstride[n] * extent[n]);
+         PTR_DECREMENT_BYTES (dest, dstride[n] * extent[n]);
          mbase -= mstride[n] * extent[n];
-         dest -= dstride[n] * extent[n];
          n++;
          if (n >= rank)
            {
@@ -368,9 +371,9 @@ define(FINISH_MASKED_ARRAY_FUNCTION,
          else
            {
              count[n]++;
-             base += sstride[n];
+             PTR_INCREMENT_BYTES (base, sstride[n]);
+             PTR_INCREMENT_BYTES (dest, dstride[n]);
              mbase += mstride[n];
-             dest += dstride[n];
            }
        }
     }
@@ -452,7 +455,7 @@ s'name`'rtype_qual`_'atype_code` ('rtype` * const restrict 
retarray,
 
       alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
 
-      retarray->base_addr = xmallocarray (alloc_size, sizeof (rtype_name));
+      retarray->base_addr = xmallocarray (alloc_size, sizeof ('rtype_name`));
       if (alloc_size == 0)
        return;
     }
@@ -483,7 +486,7 @@ s'name`'rtype_qual`_'atype_code` ('rtype` * const restrict 
retarray,
   for (n = 0; n < rank; n++)
     {
       count[n] = 0;
-      dstride[n] = GFC_DESCRIPTOR_STRIDE(retarray,n);
+      dstride[n] = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,n);
     }
 
   dest = retarray->base_addr;
@@ -492,7 +495,7 @@ s'name`'rtype_qual`_'atype_code` ('rtype` * const restrict 
retarray,
     {
       *dest = '$1`;
       count[0]++;
-      dest += dstride[0];
+      PTR_INCREMENT_BYTES (dest, dstride[0]);
       n = 0;
       while (count[n] == extent[n])
        {
@@ -501,14 +504,14 @@ s'name`'rtype_qual`_'atype_code` ('rtype` * const 
restrict retarray,
          count[n] = 0;
          /* We could precalculate these products, but this is a less
             frequently used path so probably not worth it.  */
-         dest -= dstride[n] * extent[n];
+         PTR_DECREMENT_BYTES (dest, dstride[n] * extent[n]);
          n++;
          if (n >= rank)
            return;
          else
            {
              count[n]++;
-             dest += dstride[n];
+             PTR_INCREMENT_BYTES (dest, dstride[n]);
            }
        }
     }
diff --git a/libgfortran/m4/ifunction-s2.m4 b/libgfortran/m4/ifunction-s2.m4
index a41f54d8513d..c5bc2ef590e7 100644
--- a/libgfortran/m4/ifunction-s2.m4
+++ b/libgfortran/m4/ifunction-s2.m4
@@ -69,11 +69,11 @@ void
   if (len < 0)
     len = 0;
 
-  delta = GFC_DESCRIPTOR_STRIDE(array,dim) * string_len;
+  delta = GFC_DESCRIPTOR_STRIDE_BYTES(array,dim);
 
   for (n = 0; n < dim; n++)
     {
-      sstride[n] = GFC_DESCRIPTOR_STRIDE(array,n) * string_len;
+      sstride[n] = GFC_DESCRIPTOR_STRIDE_BYTES(array,n);
       extent[n] = GFC_DESCRIPTOR_EXTENT(array,n);
 
       if (extent[n] < 0)
@@ -81,7 +81,7 @@ void
     }
   for (n = dim; n < rank; n++)
     {
-      sstride[n] = GFC_DESCRIPTOR_STRIDE(array, n + 1) * string_len;
+      sstride[n] = GFC_DESCRIPTOR_STRIDE_BYTES(array, n + 1);
       extent[n] = GFC_DESCRIPTOR_EXTENT(array, n + 1);
 
       if (extent[n] < 0)
@@ -128,7 +128,7 @@ void
   for (n = 0; n < rank; n++)
     {
       count[n] = 0;
-      dstride[n] = GFC_DESCRIPTOR_STRIDE(retarray,n) * string_len;
+      dstride[n] = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,n);
       if (extent[n] <= 0)
        return;
     }
@@ -148,10 +148,11 @@ define(START_ARRAY_BLOCK,
          memset (dest, '$1`, sizeof (*dest) * string_len);
        else
          {
-           for (n = 0; n < len; n++, src += delta)
+           for (n = 0; n < len; n++)
              {
 ')dnl
 define(FINISH_ARRAY_FUNCTION,
+               PTR_INCREMENT_BYTES (src, delta);
 `            }
            '$1`
            memcpy (dest, retval, sizeof (*dest) * string_len);
@@ -159,8 +160,8 @@ define(FINISH_ARRAY_FUNCTION,
       }
       /* Advance to the next element.  */
       count[0]++;
-      base += sstride[0];
-      dest += dstride[0];
+      PTR_INCREMENT_BYTES (base, sstride[0]);
+      PTR_INCREMENT_BYTES (dest, dstride[0]);
       n = 0;
       while (count[n] == extent[n])
        {
@@ -169,8 +170,8 @@ define(FINISH_ARRAY_FUNCTION,
          count[n] = 0;
          /* We could precalculate these products, but this is a less
             frequently used path so probably not worth it.  */
-         base -= sstride[n] * extent[n];
-         dest -= dstride[n] * extent[n];
+         PTR_DECREMENT_BYTES (base, sstride[n] * extent[n]);
+         PTR_DECREMENT_BYTES (dest, dstride[n] * extent[n]);
          n++;
          if (n >= rank)
            {
@@ -181,8 +182,8 @@ define(FINISH_ARRAY_FUNCTION,
          else
            {
              count[n]++;
-             base += sstride[n];
-             dest += dstride[n];
+             PTR_INCREMENT_BYTES (base, sstride[n]);
+             PTR_INCREMENT_BYTES (dest, dstride[n]);
            }
        }
     }
@@ -254,12 +255,12 @@ m'name`'rtype_qual`_'atype_code` ('rtype` * const 
restrict retarray,
   else
     runtime_error ("Funny sized logical array");
 
-  delta = GFC_DESCRIPTOR_STRIDE(array,dim) * string_len;
+  delta = GFC_DESCRIPTOR_STRIDE_BYTES(array,dim);
   mdelta = GFC_DESCRIPTOR_STRIDE_BYTES(mask,dim);
 
   for (n = 0; n < dim; n++)
     {
-      sstride[n] = GFC_DESCRIPTOR_STRIDE(array,n) * string_len;
+      sstride[n] = GFC_DESCRIPTOR_STRIDE_BYTES(array,n);
       mstride[n] = GFC_DESCRIPTOR_STRIDE_BYTES(mask,n);
       extent[n] = GFC_DESCRIPTOR_EXTENT(array,n);
 
@@ -269,7 +270,7 @@ m'name`'rtype_qual`_'atype_code` ('rtype` * const restrict 
retarray,
     }
   for (n = dim; n < rank; n++)
     {
-      sstride[n] = GFC_DESCRIPTOR_STRIDE(array,n + 1) * string_len;
+      sstride[n] = GFC_DESCRIPTOR_STRIDE_BYTES(array,n + 1);
       mstride[n] = GFC_DESCRIPTOR_STRIDE_BYTES(mask, n + 1);
       extent[n] = GFC_DESCRIPTOR_EXTENT(array, n + 1);
 
@@ -297,7 +298,7 @@ m'name`'rtype_qual`_'atype_code` ('rtype` * const restrict 
retarray,
       retarray->offset = 0;
       retarray->dtype.rank = rank;
 
-      retarray->base_addr = xmallocarray (alloc_size, sizeof (rtype_name));
+      retarray->base_addr = xmallocarray (alloc_size, sizeof ('rtype_name`));
       if (alloc_size == 0)
        return;
     }
@@ -318,7 +319,7 @@ m'name`'rtype_qual`_'atype_code` ('rtype` * const restrict 
retarray,
   for (n = 0; n < rank; n++)
     {
       count[n] = 0;
-      dstride[n] = GFC_DESCRIPTOR_STRIDE(retarray,n) * string_len;
+      dstride[n] = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,n);
       if (extent[n] <= 0)
        return;
     }
@@ -328,7 +329,7 @@ m'name`'rtype_qual`_'atype_code` ('rtype` * const restrict 
retarray,
 
   while (base)
     {
-      const atype_name * restrict src;
+      const 'atype_name` * restrict src;
       const GFC_LOGICAL_1 * restrict msrc;
 
       src = base;
@@ -336,18 +337,20 @@ m'name`'rtype_qual`_'atype_code` ('rtype` * const 
restrict retarray,
       {
 ')dnl
 define(START_MASKED_ARRAY_BLOCK,
-`      for (n = 0; n < len; n++, src += delta, msrc += mdelta)
+`      for (n = 0; n < len; n++)
          {
 ')dnl
 define(FINISH_MASKED_ARRAY_FUNCTION,
-`        }
+`          PTR_INCREMENT_BYTES (src, delta);
+           msrc += mdelta;
+         }
        memcpy (dest, retval, sizeof (*dest) * string_len);
       }
       /* Advance to the next element.  */
       count[0]++;
-      base += sstride[0];
+      PTR_INCREMENT_BYTES (base, sstride[0]);
+      PTR_INCREMENT_BYTES (dest, dstride[0]);
       mbase += mstride[0];
-      dest += dstride[0];
       n = 0;
       while (count[n] == extent[n])
        {
@@ -356,9 +359,9 @@ define(FINISH_MASKED_ARRAY_FUNCTION,
          count[n] = 0;
          /* We could precalculate these products, but this is a less
             frequently used path so probably not worth it.  */
-         base -= sstride[n] * extent[n];
+         PTR_DECREMENT_BYTES (base, sstride[n] * extent[n]);
+         PTR_DECREMENT_BYTES (dest, dstride[n] * extent[n]);
          mbase -= mstride[n] * extent[n];
-         dest -= dstride[n] * extent[n];
          n++;
          if (n >= rank)
            {
@@ -369,9 +372,9 @@ define(FINISH_MASKED_ARRAY_FUNCTION,
          else
            {
              count[n]++;
-             base += sstride[n];
+             PTR_INCREMENT_BYTES (base, sstride[n]);
+             PTR_INCREMENT_BYTES (dest, dstride[n]);
              mbase += mstride[n];
-             dest += dstride[n];
            }
        }
     }
@@ -454,7 +457,7 @@ s'name`'rtype_qual`_'atype_code` ('rtype` * const restrict 
retarray,
       alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1]
                 * string_len;
 
-      retarray->base_addr = xmallocarray (alloc_size, sizeof (rtype_name));
+      retarray->base_addr = xmallocarray (alloc_size, sizeof ('rtype_name`));
       if (alloc_size == 0)
        return;
     }
@@ -485,7 +488,7 @@ s'name`'rtype_qual`_'atype_code` ('rtype` * const restrict 
retarray,
   for (n = 0; n < rank; n++)
     {
       count[n] = 0;
-      dstride[n] = GFC_DESCRIPTOR_STRIDE(retarray,n) * string_len;
+      dstride[n] = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,n);
     }
 
   dest = retarray->base_addr;
@@ -494,7 +497,7 @@ s'name`'rtype_qual`_'atype_code` ('rtype` * const restrict 
retarray,
     {
       memset (dest, '$1`, sizeof (*dest) * string_len);
       count[0]++;
-      dest += dstride[0];
+      PTR_INCREMENT_BYTES (dest, dstride[0]);
       n = 0;
       while (count[n] == extent[n])
        {
@@ -503,14 +506,14 @@ s'name`'rtype_qual`_'atype_code` ('rtype` * const 
restrict retarray,
          count[n] = 0;
          /* We could precalculate these products, but this is a less
             frequently used path so probably not worth it.  */
-         dest -= dstride[n] * extent[n];
+         PTR_DECREMENT_BYTES (dest, dstride[n] * extent[n]);
          n++;
          if (n >= rank)
            return;
          else
            {
              count[n]++;
-             dest += dstride[n];
+             PTR_INCREMENT_BYTES (dest, dstride[n]);
            }
        }
     }
diff --git a/libgfortran/m4/ifunction.m4 b/libgfortran/m4/ifunction.m4
index 39963bf2dfc1..079e3f1ef99e 100644
--- a/libgfortran/m4/ifunction.m4
+++ b/libgfortran/m4/ifunction.m4
@@ -55,11 +55,11 @@ void
   len = GFC_DESCRIPTOR_EXTENT(array,dim);
   if (len < 0)
     len = 0;
-  delta = GFC_DESCRIPTOR_STRIDE(array,dim);
+  delta = GFC_DESCRIPTOR_STRIDE_BYTES(array,dim);
 
   for (n = 0; n < dim; n++)
     {
-      sstride[n] = GFC_DESCRIPTOR_STRIDE(array,n);
+      sstride[n] = GFC_DESCRIPTOR_STRIDE_BYTES(array,n);
       extent[n] = GFC_DESCRIPTOR_EXTENT(array,n);
 
       if (extent[n] < 0)
@@ -67,7 +67,7 @@ void
     }
   for (n = dim; n < rank; n++)
     {
-      sstride[n] = GFC_DESCRIPTOR_STRIDE(array, n + 1);
+      sstride[n] = GFC_DESCRIPTOR_STRIDE_BYTES(array, n + 1);
       extent[n] = GFC_DESCRIPTOR_EXTENT(array, n + 1);
 
       if (extent[n] < 0)
@@ -90,6 +90,8 @@ void
 
       retarray->offset = 0;
       retarray->dtype.rank = rank;
+      retarray->dtype.elem_len = sizeof ('rtype_name`);
+      retarray->span = sizeof ('rtype_name`);
 
       alloc_size = GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[rank-1];
 
@@ -113,7 +115,7 @@ void
   for (n = 0; n < rank; n++)
     {
       count[n] = 0;
-      dstride[n] = GFC_DESCRIPTOR_STRIDE(retarray,n);
+      dstride[n] = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,n);
       if (extent[n] <= 0)
        return;
     }
@@ -135,20 +137,21 @@ define(START_ARRAY_BLOCK,
        else
          {
 #if ! defined HAVE_BACK_ARG
-           for (n = 0; n < len; n++, src += delta)
+           for (n = 0; n < len; n++)
              {
 #endif
 ')dnl
 define(FINISH_ARRAY_FUNCTION,
-`            }
+`              PTR_INCREMENT_BYTES (src, delta);
+             }
            '$1`
            *dest = result;
          }
       }
       /* Advance to the next element.  */
       count[0]++;
-      base += sstride[0];
-      dest += dstride[0];
+      PTR_INCREMENT_BYTES (base, sstride[0]);
+      PTR_INCREMENT_BYTES (dest, dstride[0]);
       n = 0;
       while (count[n] == extent[n])
        {
@@ -157,8 +160,8 @@ define(FINISH_ARRAY_FUNCTION,
          count[n] = 0;
          /* We could precalculate these products, but this is a less
             frequently used path so probably not worth it.  */
-         base -= sstride[n] * extent[n];
-         dest -= dstride[n] * extent[n];
+         PTR_DECREMENT_BYTES (base, sstride[n] * extent[n]);
+         PTR_DECREMENT_BYTES (dest, dstride[n] * extent[n]);
          n++;
          if (n >= rank)
            {
@@ -169,8 +172,8 @@ define(FINISH_ARRAY_FUNCTION,
          else
            {
              count[n]++;
-             base += sstride[n];
-             dest += dstride[n];
+             PTR_INCREMENT_BYTES (base, sstride[n]);
+             PTR_INCREMENT_BYTES (dest, dstride[n]);
            }
        }
     }
@@ -242,12 +245,12 @@ m'name`'rtype_qual`_'atype_code` ('rtype` * const 
restrict retarray,
   else
     runtime_error ("Funny sized logical array");
 
-  delta = GFC_DESCRIPTOR_STRIDE(array,dim);
+  delta = GFC_DESCRIPTOR_STRIDE_BYTES(array,dim);
   mdelta = GFC_DESCRIPTOR_STRIDE_BYTES(mask,dim);
 
   for (n = 0; n < dim; n++)
     {
-      sstride[n] = GFC_DESCRIPTOR_STRIDE(array,n);
+      sstride[n] = GFC_DESCRIPTOR_STRIDE_BYTES(array,n);
       mstride[n] = GFC_DESCRIPTOR_STRIDE_BYTES(mask,n);
       extent[n] = GFC_DESCRIPTOR_EXTENT(array,n);
 
@@ -257,7 +260,7 @@ m'name`'rtype_qual`_'atype_code` ('rtype` * const restrict 
retarray,
     }
   for (n = dim; n < rank; n++)
     {
-      sstride[n] = GFC_DESCRIPTOR_STRIDE(array,n + 1);
+      sstride[n] = GFC_DESCRIPTOR_STRIDE_BYTES(array,n + 1);
       mstride[n] = GFC_DESCRIPTOR_STRIDE_BYTES(mask, n + 1);
       extent[n] = GFC_DESCRIPTOR_EXTENT(array, n + 1);
 
@@ -283,6 +286,8 @@ m'name`'rtype_qual`_'atype_code` ('rtype` * const restrict 
retarray,
 
       retarray->offset = 0;
       retarray->dtype.rank = rank;
+      retarray->dtype.elem_len = sizeof ('rtype_name`);
+      retarray->span = sizeof ('rtype_name`);
 
       retarray->base_addr = xmallocarray (alloc_size, sizeof (rtype_name));
       if (alloc_size == 0)
@@ -305,7 +310,7 @@ m'name`'rtype_qual`_'atype_code` ('rtype` * const restrict 
retarray,
   for (n = 0; n < rank; n++)
     {
       count[n] = 0;
-      dstride[n] = GFC_DESCRIPTOR_STRIDE(retarray,n);
+      dstride[n] = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,n);
       if (extent[n] <= 0)
        return;
     }
@@ -323,18 +328,20 @@ m'name`'rtype_qual`_'atype_code` ('rtype` * const 
restrict retarray,
       {
 ')dnl
 define(START_MASKED_ARRAY_BLOCK,
-`      for (n = 0; n < len; n++, src += delta, msrc += mdelta)
+`      for (n = 0; n < len; n++)
          {
 ')dnl
 define(FINISH_MASKED_ARRAY_FUNCTION,
-`        }
+`          PTR_INCREMENT_BYTES (src, delta);
+           msrc += mdelta;
+         }
        *dest = result;
       }
       /* Advance to the next element.  */
       count[0]++;
-      base += sstride[0];
+      PTR_INCREMENT_BYTES (base, sstride[0]);
+      PTR_INCREMENT_BYTES (dest, dstride[0]);
       mbase += mstride[0];
-      dest += dstride[0];
       n = 0;
       while (count[n] == extent[n])
        {
@@ -343,9 +350,9 @@ define(FINISH_MASKED_ARRAY_FUNCTION,
          count[n] = 0;
          /* We could precalculate these products, but this is a less
             frequently used path so probably not worth it.  */
-         base -= sstride[n] * extent[n];
+         PTR_DECREMENT_BYTES (base, sstride[n] * extent[n]);
+         PTR_DECREMENT_BYTES (dest, dstride[n] * extent[n]);
          mbase -= mstride[n] * extent[n];
-         dest -= dstride[n] * extent[n];
          n++;
          if (n >= rank)
            {
@@ -356,9 +363,9 @@ define(FINISH_MASKED_ARRAY_FUNCTION,
          else
            {
              count[n]++;
-             base += sstride[n];
+             PTR_INCREMENT_BYTES (base, sstride[n]);
+             PTR_INCREMENT_BYTES (dest, dstride[n]);
              mbase += mstride[n];
-             dest += dstride[n];
            }
        }
     }
@@ -472,7 +479,7 @@ s'name`'rtype_qual`_'atype_code` ('rtype` * const restrict 
retarray,
   for (n = 0; n < rank; n++)
     {
       count[n] = 0;
-      dstride[n] = GFC_DESCRIPTOR_STRIDE(retarray,n);
+      dstride[n] = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,n);
     }
 
   dest = retarray->base_addr;
@@ -481,7 +488,7 @@ s'name`'rtype_qual`_'atype_code` ('rtype` * const restrict 
retarray,
     {
       *dest = '$1`;
       count[0]++;
-      dest += dstride[0];
+      PTR_INCREMENT_BYTES (dest, dstride[0]);
       n = 0;
       while (count[n] == extent[n])
        {
@@ -490,14 +497,14 @@ s'name`'rtype_qual`_'atype_code` ('rtype` * const 
restrict retarray,
          count[n] = 0;
          /* We could precalculate these products, but this is a less
             frequently used path so probably not worth it.  */
-         dest -= dstride[n] * extent[n];
+         PTR_DECREMENT_BYTES (dest, dstride[n] * extent[n]);
          n++;
          if (n >= rank)
            return;
          else
            {
              count[n]++;
-             dest += dstride[n];
+             PTR_INCREMENT_BYTES (dest, dstride[n]);
            }
        }
     }
diff --git a/libgfortran/m4/ifunction_logical.m4 
b/libgfortran/m4/ifunction_logical.m4
index ebf6520ea532..b6d7e616d546 100644
--- a/libgfortran/m4/ifunction_logical.m4
+++ b/libgfortran/m4/ifunction_logical.m4
@@ -121,7 +121,7 @@ void
   for (n = 0; n < rank; n++)
     {
       count[n] = 0;
-      dstride[n] = GFC_DESCRIPTOR_STRIDE(retarray,n);
+      dstride[n] = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,n);
       if (extent[n] <= 0)
        return;
     }
@@ -155,18 +155,19 @@ define(START_ARRAY_BLOCK,
          *dest = '$1`;
        else
          {
-           for (n = 0; n < len; n++, src += delta)
+           for (n = 0; n < len; n++)
              {
 ')dnl
 define(FINISH_ARRAY_FUNCTION,
-    `          }
+`              PTR_INCREMENT_BYTES (src, delta);
+             }
            *dest = result;
          }
       }
       /* Advance to the next element.  */
       count[0]++;
-      base += sstride[0];
-      dest += dstride[0];
+      PTR_INCREMENT_BYTES (base, sstride[0]);
+      PTR_INCREMENT_BYTES (dest, dstride[0]);
       n = 0;
       while (count[n] == extent[n])
         {
@@ -175,8 +176,8 @@ define(FINISH_ARRAY_FUNCTION,
           count[n] = 0;
           /* We could precalculate these products, but this is a less
              frequently used path so probably not worth it.  */
+          PTR_DECREMENT_BYTES (dest, dstride[n] * extent[n]);
           base -= sstride[n] * extent[n];
-          dest -= dstride[n] * extent[n];
           n++;
           if (n >= rank)
             {
@@ -187,8 +188,8 @@ define(FINISH_ARRAY_FUNCTION,
           else
             {
               count[n]++;
-              base += sstride[n];
-              dest += dstride[n];
+              PTR_INCREMENT_BYTES (base, sstride[n]);
+              PTR_INCREMENT_BYTES (dest, dstride[n]);
             }
         }
     }
diff --git a/libgfortran/m4/in_pack.m4 b/libgfortran/m4/in_pack.m4
index 5e35d3301516..b6c7c3562f5f 100644
--- a/libgfortran/m4/in_pack.m4
+++ b/libgfortran/m4/in_pack.m4
@@ -52,12 +52,12 @@ internal_pack_'rtype_ccode` ('rtype` * source)
      since the stride=0 thing has been removed from the frontend.  */
 
   dim = GFC_DESCRIPTOR_RANK (source);
-  ssize = 1;
+  ssize = sizeof ('rtype_name`);
   packed = 1;
   for (index_type n = 0; n < dim; n++)
     {
       count[n] = 0;
-      stride[n] = GFC_DESCRIPTOR_STRIDE(source,n);
+      stride[n] = GFC_DESCRIPTOR_STRIDE_BYTES(source,n);
       extent[n] = GFC_DESCRIPTOR_EXTENT(source,n);
       if (extent[n] <= 0)
         {
@@ -87,7 +87,7 @@ internal_pack_'rtype_ccode` ('rtype` * source)
       /* Copy the data.  */
       *(dest++) = *src;
       /* Advance to the next element.  */
-      src += stride0;
+      PTR_INCREMENT_BYTES (src, stride0);
       count[0]++;
       /* Advance to the next source element.  */
       index_type n = 0;
@@ -98,7 +98,7 @@ internal_pack_'rtype_ccode` ('rtype` * source)
           count[n] = 0;
           /* We could precalculate these products, but this is a less
              frequently used path so probably not worth it.  */
-          src -= stride[n] * extent[n];
+          PTR_DECREMENT_BYTES (src, stride[n] * extent[n]);
           n++;
           if (n == dim)
             {
@@ -108,7 +108,7 @@ internal_pack_'rtype_ccode` ('rtype` * source)
           else
             {
               count[n]++;
-              src += stride[n];
+              PTR_INCREMENT_BYTES (src, stride[n]);
             }
         }
     }
diff --git a/libgfortran/m4/in_unpack.m4 b/libgfortran/m4/in_unpack.m4
index d71371c4d880..ff1d86dbb582 100644
--- a/libgfortran/m4/in_unpack.m4
+++ b/libgfortran/m4/in_unpack.m4
@@ -48,11 +48,11 @@ internal_unpack_'rtype_ccode` ('rtype` * d, const 
'rtype_name` * src)
     return;
 
   dim = GFC_DESCRIPTOR_RANK (d);
-  dsize = 1;
+  dsize = sizeof ('rtype_name`);
   for (index_type n = 0; n < dim; n++)
     {
       count[n] = 0;
-      stride[n] = GFC_DESCRIPTOR_STRIDE(d,n);
+      stride[n] = GFC_DESCRIPTOR_STRIDE_BYTES(d,n);
       extent[n] = GFC_DESCRIPTOR_EXTENT(d,n);
       if (extent[n] <= 0)
        return;
@@ -65,7 +65,7 @@ internal_unpack_'rtype_ccode` ('rtype` * d, const 
'rtype_name` * src)
 
   if (dsize != 0)
     {
-      memcpy (dest, src, dsize * sizeof ('rtype_name`));
+      memcpy (dest, src, dsize);
       return;
     }
 
@@ -76,7 +76,7 @@ internal_unpack_'rtype_ccode` ('rtype` * d, const 
'rtype_name` * src)
       /* Copy the data.  */
       *dest = *(src++);
       /* Advance to the next element.  */
-      dest += stride0;
+      PTR_INCREMENT_BYTES (dest, stride0);
       count[0]++;
       /* Advance to the next source element.  */
       index_type n = 0;
@@ -87,7 +87,7 @@ internal_unpack_'rtype_ccode` ('rtype` * d, const 
'rtype_name` * src)
           count[n] = 0;
           /* We could precalculate these products, but this is a less
              frequently used path so probably not worth it.  */
-          dest -= stride[n] * extent[n];
+          PTR_DECREMENT_BYTES (dest, stride[n] * extent[n]);
           n++;
           if (n == dim)
             {
@@ -97,7 +97,7 @@ internal_unpack_'rtype_ccode` ('rtype` * d, const 
'rtype_name` * src)
           else
             {
               count[n]++;
-              dest += stride[n];
+              PTR_INCREMENT_BYTES (dest, stride[n]);
             }
         }
     }
diff --git a/libgfortran/m4/matmul_internal.m4 
b/libgfortran/m4/matmul_internal.m4
index d1ab0e06ce6c..870b392e77d6 100644
--- a/libgfortran/m4/matmul_internal.m4
+++ b/libgfortran/m4/matmul_internal.m4
@@ -9,6 +9,7 @@
 
   index_type rxstride, rystride, axstride, aystride, bxstride, bystride;
   index_type x, y, n, count, xcount, ycount;
+  index_type aystride_bytes, bystride_bytes, rystride_bytes;
 
   assert (GFC_DESCRIPTOR_RANK (a) == 2
           || GFC_DESCRIPTOR_RANK (b) == 2);
@@ -98,19 +99,21 @@ sinclude(`matmul_asm_'rtype_code`.m4')dnl
         either as a row or a column matrix. We want both cases to
         work. */
       rxstride = rystride = GFC_DESCRIPTOR_STRIDE(retarray,0);
+      rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
     }
   else
     {
       rxstride = GFC_DESCRIPTOR_STRIDE(retarray,0);
       rystride = GFC_DESCRIPTOR_STRIDE(retarray,1);
+      rystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,1);
     }
 
-
   if (GFC_DESCRIPTOR_RANK (a) == 1)
     {
       /* Treat it as a a row matrix A[1,count]. */
       axstride = GFC_DESCRIPTOR_STRIDE(a,0);
       aystride = 1;
+      aystride_bytes = sizeof ('rtype_name`);
 
       xcount = 1;
       count = GFC_DESCRIPTOR_EXTENT(a,0);
@@ -119,6 +122,7 @@ sinclude(`matmul_asm_'rtype_code`.m4')dnl
     {
       axstride = GFC_DESCRIPTOR_STRIDE(a,0);
       aystride = GFC_DESCRIPTOR_STRIDE(a,1);
+      aystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(a,1);
 
       count = GFC_DESCRIPTOR_EXTENT(a,1);
       xcount = GFC_DESCRIPTOR_EXTENT(a,0);
@@ -147,6 +151,7 @@ sinclude(`matmul_asm_'rtype_code`.m4')dnl
     {
       bxstride = GFC_DESCRIPTOR_STRIDE(b,0);
       bystride = GFC_DESCRIPTOR_STRIDE(b,1);
+      bystride_bytes = GFC_DESCRIPTOR_STRIDE_BYTES(b,1);
       ycount = GFC_DESCRIPTOR_EXTENT(b,1);
     }
 
@@ -210,7 +215,7 @@ sinclude(`matmul_asm_'rtype_code`.m4')dnl
       const index_type m = xcount, n = ycount, k = count;
 
       /* System generated locals */
-      index_type a_dim1, a_offset, b_dim1, b_offset, c_dim1, c_offset,
+      index_type a_dim1, b_dim1, c_dim1,
                 i1, i2, i3, i4, i5, i6;
 
       /* Local variables */
@@ -226,14 +231,11 @@ sinclude(`matmul_asm_'rtype_code`.m4')dnl
 
       /* Parameter adjustments */
       c_dim1 = rystride;
-      c_offset = 1 + c_dim1;
-      c -= c_offset;
+      PTR_DECREMENT_BYTES (c, sizeof('rtype_name`) + rystride_bytes);
       a_dim1 = aystride;
-      a_offset = 1 + a_dim1;
-      a -= a_offset;
+      PTR_DECREMENT_BYTES (a, sizeof('rtype_name`) + aystride_bytes);
       b_dim1 = bystride;
-      b_offset = 1 + b_dim1;
-      b -= b_offset;
+      PTR_DECREMENT_BYTES (b, sizeof('rtype_name`) + bystride_bytes);
 
       /* Empty c first.  */
       for (j=1; j<=n; j++)
diff --git a/libgfortran/m4/matmull.m4 b/libgfortran/m4/matmull.m4
index 52134a347479..8470742bccd5 100644
--- a/libgfortran/m4/matmull.m4
+++ b/libgfortran/m4/matmull.m4
@@ -232,7 +232,9 @@ sinclude(`matmul_asm_'rtype_code`.m4')dnl
         }
       abase -= xstride * xcount;
       bbase += ystride;
-      dest += rystride - (rxstride * xcount);
+      PTR_INCREMENT_BYTES (dest,
+                          (rystride - (rxstride * xcount))
+                          * GFC_DESCRIPTOR_SIZE(retarray));
     }
 }
 
diff --git a/libgfortran/m4/maxloc0.m4 b/libgfortran/m4/maxloc0.m4
index f60580f063e2..041965e2ef21 100644
--- a/libgfortran/m4/maxloc0.m4
+++ b/libgfortran/m4/maxloc0.m4
@@ -55,7 +55,7 @@ FOREACH_FUNCTION(
                    dest[n * dstride] = count[n] + 1;
                  break;
                }
-             base += sstride[0];
+             PTR_INCREMENT_BYTES (base, sstride[0]);
            }
          while (++count[0] != extent[0]);
          if (likely (fast))
@@ -72,7 +72,7 @@ FOREACH_FUNCTION(
                 for (n = 0; n < rank; n++)
                   dest[n * dstride] = count[n] + 1;
               }
-            base += sstride[0];
+            PTR_INCREMENT_BYTES (base, sstride[0]);
           }
          while (++count[0] != extent[0]);
        else
@@ -113,7 +113,7 @@ MASKED_FOREACH_FUNCTION(
                      break;
                    }
                }
-             base += sstride[0];
+             PTR_INCREMENT_BYTES (base, sstride[0]);
              mbase += mstride[0];
            }
          while (++count[0] != extent[0]);
@@ -130,7 +130,7 @@ MASKED_FOREACH_FUNCTION(
                  for (n = 0; n < rank; n++)
                    dest[n * dstride] = count[n] + 1;
                }
-             base += sstride[0];
+             PTR_INCREMENT_BYTES (base, sstride[0]);
            }
          while (++count[0] != extent[0]);
        else
diff --git a/libgfortran/m4/maxloc1.m4 b/libgfortran/m4/maxloc1.m4
index 924b6d61b81c..f5f66cd1a119 100644
--- a/libgfortran/m4/maxloc1.m4
+++ b/libgfortran/m4/maxloc1.m4
@@ -42,19 +42,20 @@ ARRAY_FUNCTION(0,
 #endif
        result = 1;',
 `#if defined ('atype_nan`)
-            for (n = 0; n < len; n++, src += delta)
-              {
-               if (*src >= maxval)
-                 {
-                   maxval = *src;
-                   result = (rtype_name)n + 1;
-                   break;
-                 }
-             }
+             for (n = 0; n < len; n++)
+               {
+                 if (*src >= maxval)
+                   {
+                     maxval = *src;
+                     result = (rtype_name)n + 1;
+                     break;
+                   }
+                 PTR_INCREMENT_BYTES (src, delta);
+               }
 #else
            n = 0;
 #endif
-           for (; n < len; n++, src += delta)
+           for (; n < len; n++)
              {
                if (back ? *src >= maxval : *src > maxval)
                  {
@@ -86,6 +87,8 @@ MASKED_ARRAY_FUNCTION(0,
                        break;
                      }
                  }
+               PTR_INCREMENT_BYTES (src, delta);
+               msrc += mdelta;
              }
 #if defined ('atype_nan`)
            if (unlikely (n >= len))
@@ -93,16 +96,18 @@ MASKED_ARRAY_FUNCTION(0,
            else
 #endif
            if (back)
-             for (; n < len; n++, src += delta, msrc += mdelta)
+             for (; n < len; n++)
                {
                  if (*msrc && unlikely (*src >= maxval))
                    {
                      maxval = *src;
                      result = (rtype_name)n + 1;
                    }
+                 PTR_INCREMENT_BYTES (src, delta);
+                 msrc += mdelta;
                }
            else
-             for (; n < len; n++, src += delta, msrc += mdelta)
+             for (; n < len; n++)
                {
                  if (*msrc && unlikely (*src > maxval))
                    {
diff --git a/libgfortran/m4/maxloc1s.m4 b/libgfortran/m4/maxloc1s.m4
index 762862280120..c5760a3eee36 100644
--- a/libgfortran/m4/maxloc1s.m4
+++ b/libgfortran/m4/maxloc1s.m4
@@ -53,8 +53,10 @@ MASKED_ARRAY_FUNCTION(0,
                        result = (rtype_name)n + 1;
                        break;
                      }
+             PTR_INCREMENT_BYTES (src, delta);
+             msrc += mdelta;
            }
-           for (; n < len; n++, src += delta, msrc += mdelta)
+           for (; n < len; n++)
              {
                if (*msrc && (back ? compare_fcn (src, maxval, string_len) >= 0 
:
                                     compare_fcn (src, maxval, string_len) > 0))
diff --git a/libgfortran/m4/maxloc2s.m4 b/libgfortran/m4/maxloc2s.m4
index b6070b41d26f..20f8f989f046 100644
--- a/libgfortran/m4/maxloc2s.m4
+++ b/libgfortran/m4/maxloc2s.m4
@@ -58,7 +58,7 @@ export_proto('name`'rtype_qual`_'atype_code`);
   if (extent <= 0)
     return 0;
 
-  sstride = GFC_DESCRIPTOR_STRIDE(array,0) * len;
+  sstride = GFC_DESCRIPTOR_STRIDE_BYTES(array,0);
 
   ret = 1;
   src = array->base_addr;
@@ -71,7 +71,7 @@ export_proto('name`'rtype_qual`_'atype_code`);
         ret = i;
         maxval = src;
       }
-      src += sstride;
+      PTR_INCREMENT_BYTES (src, sstride);
     }
   return ret;
 }
@@ -100,7 +100,7 @@ m'name`'rtype_qual`_'atype_code` ('atype` * const restrict 
array,
   if (extent <= 0)
     return 0;
 
-  sstride = GFC_DESCRIPTOR_STRIDE(array,0) * len;
+  sstride = GFC_DESCRIPTOR_STRIDE_BYTES(array,0);
 
   mask_kind = GFC_DESCRIPTOR_SIZE (mask);
   mbase = mask->base_addr;
@@ -128,7 +128,7 @@ m'name`'rtype_qual`_'atype_code` ('atype` * const restrict 
array,
     return 0;
 
   ret = j + 1;
-  src = array->base_addr + j * sstride;
+  src = ('atype_name`*) (((char*)array->base_addr) + j * sstride);
   maxval = src;
 
   for (i=j+1; i<=extent; i++)
@@ -139,7 +139,7 @@ m'name`'rtype_qual`_'atype_code` ('atype` * const restrict 
array,
         ret = i;
         maxval = src;
       }
-      src += sstride;
+      PTR_INCREMENT_BYTES (src, sstride);
       mbase += mstride;
     }
   return ret;
diff --git a/libgfortran/m4/maxval.m4 b/libgfortran/m4/maxval.m4
index a60a21ac31b6..db0316301672 100644
--- a/libgfortran/m4/maxval.m4
+++ b/libgfortran/m4/maxval.m4
@@ -39,10 +39,11 @@ ARRAY_FUNCTION(atype_min,
 `#if defined ('atype_nan`)
                if (*src >= result)
                  break;
+               PTR_INCREMENT_BYTES (src, delta);
              }
            if (unlikely (n >= len))
              result = 'atype_nan`;
-           else for (; n < len; n++, src += delta)
+           else for (; n < len; n++)
              {
 #endif
                if (*src > result)
@@ -66,6 +67,8 @@ MASKED_ARRAY_FUNCTION(atype_min,
 #endif
                      break;
                  }
+               PTR_INCREMENT_BYTES (src, delta);
+               msrc += mdelta;
              }
            if (unlikely (n >= len))
              {
@@ -75,7 +78,7 @@ MASKED_ARRAY_FUNCTION(atype_min,
                result = 'atype_min`;
 #endif
              }
-           else for (; n < len; n++, src += delta, msrc += mdelta)
+           else for (; n < len; n++)
              {
 #endif
                if (*msrc && *src > result)
diff --git a/libgfortran/m4/maxval1s.m4 b/libgfortran/m4/maxval1s.m4
index 3759754dc0d5..a6126eb985c7 100644
--- a/libgfortran/m4/maxval1s.m4
+++ b/libgfortran/m4/maxval1s.m4
@@ -47,8 +47,10 @@ MASKED_ARRAY_FUNCTION(0,
                        retval = src;
                        break;
                      }
+             PTR_INCREMENT_BYTES (src, delta);
+             msrc += mdelta;
            }
-           for (; n < len; n++, src += delta, msrc += mdelta)
+           for (; n < len; n++)
              {
                if (*msrc && compare_fcn (src, retval, string_len) > 0)
                  {
diff --git a/libgfortran/m4/minloc0.m4 b/libgfortran/m4/minloc0.m4
index 0e1bb3b2f86c..6dd99a519c90 100644
--- a/libgfortran/m4/minloc0.m4
+++ b/libgfortran/m4/minloc0.m4
@@ -55,7 +55,7 @@ FOREACH_FUNCTION(
                    dest[n * dstride] = count[n] + 1;
                  break;
                }
-             base += sstride[0];
+             PTR_INCREMENT_BYTES (base, sstride[0]);
            }
          while (++count[0] != extent[0]);
          if (likely (fast))
@@ -72,7 +72,7 @@ FOREACH_FUNCTION(
                for (n = 0; n < rank; n++)
                  dest[n * dstride] = count[n] + 1;
              }
-           base += sstride[0];
+           PTR_INCREMENT_BYTES (base, sstride[0]);
          }
        while (++count[0] != extent[0]);
       else
@@ -113,7 +113,7 @@ MASKED_FOREACH_FUNCTION(
                      break;
                    }
                }
-             base += sstride[0];
+             PTR_INCREMENT_BYTES (base, sstride[0]);
              mbase += mstride[0];
            }
          while (++count[0] != extent[0]);
@@ -130,7 +130,7 @@ MASKED_FOREACH_FUNCTION(
                  for (n = 0; n < rank; n++)
                    dest[n * dstride] = count[n] + 1;
                }
-               base += sstride[0];
+               PTR_INCREMENT_BYTES (base, sstride[0]);
            }
            while (++count[0] != extent[0]);
        else
diff --git a/libgfortran/m4/minloc1.m4 b/libgfortran/m4/minloc1.m4
index b678145b51c4..3e4359c113b4 100644
--- a/libgfortran/m4/minloc1.m4
+++ b/libgfortran/m4/minloc1.m4
@@ -42,7 +42,7 @@ ARRAY_FUNCTION(0,
 #endif
        result = 1;',
 `#if defined ('atype_nan`)
-          for (n = 0; n < len; n++, src += delta)
+          for (n = 0; n < len; n++)
             {
                if (*src <= minval)
                  {
@@ -50,21 +50,25 @@ ARRAY_FUNCTION(0,
                    result = (rtype_name)n + 1;
                    break;
                  }
-             }
+              PTR_INCREMENT_BYTES (src, delta);
+            }
 #else
            n = 0;
 #endif
            if (back)
-             for (; n < len; n++, src += delta)
-               {
-                 if (unlikely (*src <= minval))
-                   {
-                     minval = *src;
-                     result = ('rtype_name`)n + 1;
-                   }
-               }
+             {
+               for (; n < len; n++)
+                 {
+                   if (unlikely (*src <= minval))
+                     {
+                       minval = *src;
+                       result = ('rtype_name`)n + 1;
+                     }
+                   PTR_INCREMENT_BYTES (src, delta);
+                 }
+             }
            else
-             for (; n < len; n++, src += delta)
+             for (; n < len; n++)
                {
                  if (unlikely (*src < minval))
                    {
@@ -96,6 +100,8 @@ MASKED_ARRAY_FUNCTION(0,
                        break;
                      }
                  }
+               PTR_INCREMENT_BYTES (src, delta);
+               msrc += mdelta;
              }
 #if defined ('atype_nan`)
            if (unlikely (n >= len))
@@ -103,16 +109,18 @@ MASKED_ARRAY_FUNCTION(0,
            else
 #endif
            if (back)
-             for (; n < len; n++, src += delta, msrc += mdelta)
+             for (; n < len; n++)
                {
                  if (*msrc && unlikely (*src <= minval))
                    {
                      minval = *src;
                      result = (rtype_name)n + 1;
                    }
+                 PTR_INCREMENT_BYTES (src, delta);
+                 msrc += mdelta;
                }
              else
-               for (; n < len; n++, src += delta, msrc += mdelta)
+               for (; n < len; n++)
                  {
                    if (*msrc && unlikely (*src < minval))
                      {
diff --git a/libgfortran/m4/minloc1s.m4 b/libgfortran/m4/minloc1s.m4
index f24318e4c56e..caa39b5c05db 100644
--- a/libgfortran/m4/minloc1s.m4
+++ b/libgfortran/m4/minloc1s.m4
@@ -53,8 +53,10 @@ MASKED_ARRAY_FUNCTION(0,
                        result = (rtype_name)n + 1;
                        break;
                      }
+             PTR_INCREMENT_BYTES (src, delta);
+             msrc += mdelta;
             }
-           for (; n < len; n++, src += delta, msrc += mdelta)
+           for (; n < len; n++)
              {
                if (*msrc && (back ? compare_fcn (src, minval, string_len) <= 0 
:
                                     compare_fcn (src, minval, string_len) < 0))
diff --git a/libgfortran/m4/minloc2s.m4 b/libgfortran/m4/minloc2s.m4
index 9524fc4c62a7..2d1a14814648 100644
--- a/libgfortran/m4/minloc2s.m4
+++ b/libgfortran/m4/minloc2s.m4
@@ -59,7 +59,7 @@ export_proto('name`'rtype_qual`_'atype_code`);
   if (extent <= 0)
     return 0;
 
-  sstride = GFC_DESCRIPTOR_STRIDE(array,0) * len;
+  sstride = GFC_DESCRIPTOR_STRIDE_BYTES(array,0);
 
   ret = 1;
   src = array->base_addr;
@@ -72,7 +72,7 @@ export_proto('name`'rtype_qual`_'atype_code`);
         ret = i;
         minval = src;
       }
-      src += sstride;
+      PTR_INCREMENT_BYTES (src, sstride);
     }
   return ret;
 }
@@ -101,7 +101,7 @@ m'name`'rtype_qual`_'atype_code` ('atype` * const restrict 
array,
   if (extent <= 0)
     return 0;
 
-  sstride = GFC_DESCRIPTOR_STRIDE(array,0) * len;
+  sstride = GFC_DESCRIPTOR_STRIDE_BYTES(array,0);
 
   mask_kind = GFC_DESCRIPTOR_SIZE (mask);
   mbase = mask->base_addr;
@@ -122,7 +122,7 @@ m'name`'rtype_qual`_'atype_code` ('atype` * const restrict 
array,
     {
       if (*mbase)
         break;
-      mbase += mstride;
+      PTR_INCREMENT_BYTES (mbase, mstride);
     }
 
   if (j == extent)
@@ -141,7 +141,7 @@ m'name`'rtype_qual`_'atype_code` ('atype` * const restrict 
array,
         ret = i;
         maxval = src;
       }
-      src += sstride;
+      PTR_INCREMENT_BYTES (src, sstride);
       mbase += mstride;
     }
   return ret;
diff --git a/libgfortran/m4/minval.m4 b/libgfortran/m4/minval.m4
index ec6ad8d93b24..855f21bbc2ae 100644
--- a/libgfortran/m4/minval.m4
+++ b/libgfortran/m4/minval.m4
@@ -39,10 +39,11 @@ ARRAY_FUNCTION(atype_max,
 `#if defined ('atype_nan`)
                if (*src <= result)
                  break;
+               PTR_INCREMENT_BYTES (src, delta);
              }
            if (unlikely (n >= len))
              result = 'atype_nan`;
-           else for (; n < len; n++, src += delta)
+           else for (; n < len; n++)
              {
 #endif
                if (*src < result)
@@ -66,6 +67,8 @@ MASKED_ARRAY_FUNCTION(atype_max,
 #endif
                      break;
                  }
+               PTR_INCREMENT_BYTES (src, delta);
+               msrc += mdelta;
              }
            if (unlikely (n >= len))
              {
@@ -75,7 +78,7 @@ MASKED_ARRAY_FUNCTION(atype_max,
                result = 'atype_max`;
 #endif
              }
-           else for (; n < len; n++, src += delta, msrc += mdelta)
+           else for (; n < len; n++)
              {
 #endif
                if (*msrc && *src < result)
diff --git a/libgfortran/m4/minval1s.m4 b/libgfortran/m4/minval1s.m4
index 30ac98674a55..b50b9decdaa5 100644
--- a/libgfortran/m4/minval1s.m4
+++ b/libgfortran/m4/minval1s.m4
@@ -47,8 +47,10 @@ MASKED_ARRAY_FUNCTION(255,
                        retval = src;
                        break;
                      }
+             PTR_INCREMENT_BYTES (src, delta);
+             msrc += mdelta;
            }
-           for (; n < len; n++, src += delta, msrc += mdelta)
+           for (; n < len; n++)
              {
                if (*msrc && compare_fcn (src, retval, string_len) < 0)
                  {
diff --git a/libgfortran/m4/pack.m4 b/libgfortran/m4/pack.m4
index 1e94fc8416b6..accbbfcd4b98 100644
--- a/libgfortran/m4/pack.m4
+++ b/libgfortran/m4/pack.m4
@@ -127,11 +127,11 @@ pack_'rtype_code` ('rtype` *ret, const 'rtype` *array,
       extent[n] = GFC_DESCRIPTOR_EXTENT(array,n);
       if (extent[n] <= 0)
        zero_sized = 1;
-      sstride[n] = GFC_DESCRIPTOR_STRIDE(array,n);
+      sstride[n] = GFC_DESCRIPTOR_STRIDE_BYTES(array,n);
       mstride[n] = GFC_DESCRIPTOR_STRIDE_BYTES(mask,n);
     }
   if (sstride[0] == 0)
-    sstride[0] = 1;
+    sstride[0] = sizeof ('rtype_name`);
   if (mstride[0] == 0)
     mstride[0] = mask_kind;
 
@@ -188,9 +188,9 @@ pack_'rtype_code` ('rtype` *ret, const 'rtype` *array,
        }
     }
 
-  rstride0 = GFC_DESCRIPTOR_STRIDE(ret,0);
+  rstride0 = GFC_DESCRIPTOR_STRIDE_BYTES(ret,0);
   if (rstride0 == 0)
-    rstride0 = 1;
+    rstride0 = sizeof ('rtype_name`);
   sstride0 = sstride[0];
   mstride0 = mstride[0];
   rptr = ret->base_addr;
@@ -202,10 +202,10 @@ pack_'rtype_code` ('rtype` *ret, const 'rtype` *array,
         {
           /* Add it.  */
          *rptr = *sptr;
-          rptr += rstride0;
+          PTR_INCREMENT_BYTES (rptr, rstride0);
         }
       /* Advance to the next element.  */
-      sptr += sstride0;
+      PTR_INCREMENT_BYTES (sptr, sstride0);
       mptr += mstride0;
       count[0]++;
       n = 0;
@@ -216,7 +216,7 @@ pack_'rtype_code` ('rtype` *ret, const 'rtype` *array,
           count[n] = 0;
           /* We could precalculate these products, but this is a less
              frequently used path so probably not worth it.  */
-          sptr -= sstride[n] * extent[n];
+          PTR_DECREMENT_BYTES (sptr, sstride[n] * extent[n]);
           mptr -= mstride[n] * extent[n];
           n++;
           if (n >= dim)
@@ -228,7 +228,7 @@ pack_'rtype_code` ('rtype` *ret, const 'rtype` *array,
           else
             {
               count[n]++;
-              sptr += sstride[n];
+              PTR_INCREMENT_BYTES (sptr, sstride[n]);
               mptr += mstride[n];
             }
         }
@@ -238,20 +238,20 @@ pack_'rtype_code` ('rtype` *ret, const 'rtype` *array,
   if (vector)
     {
       n = GFC_DESCRIPTOR_EXTENT(vector,0);
-      nelem = ((rptr - ret->base_addr) / rstride0);
+      nelem = ((char*)rptr - (char*)ret->base_addr) / rstride0;
       if (n > nelem)
         {
-          sstride0 = GFC_DESCRIPTOR_STRIDE(vector,0);
+          sstride0 = GFC_DESCRIPTOR_STRIDE_BYTES(vector,0);
           if (sstride0 == 0)
-            sstride0 = 1;
+            sstride0 = sizeof ('rtype_name`);
 
-          sptr = vector->base_addr + sstride0 * nelem;
+          sptr = (const 'rtype_name` *) (((char*)vector->base_addr) + sstride0 
* nelem);
           n -= nelem;
           while (n--)
             {
              *rptr = *sptr;
-              rptr += rstride0;
-              sptr += sstride0;
+              PTR_INCREMENT_BYTES (rptr, rstride0);
+              PTR_INCREMENT_BYTES (sptr, sstride0);
             }
         }
     }
diff --git a/libgfortran/m4/reshape.m4 b/libgfortran/m4/reshape.m4
index ee1547e91282..9519fc4d2e80 100644
--- a/libgfortran/m4/reshape.m4
+++ b/libgfortran/m4/reshape.m4
@@ -129,12 +129,12 @@ reshape_'rtype_ccode` ('rtype` * const restrict ret,
   if (pad)
     {
       pdim = GFC_DESCRIPTOR_RANK (pad);
-      psize = 1;
+      psize = GFC_DESCRIPTOR_SIZE(pad);
       pempty = 0;
       for (index_type n = 0; n < pdim; n++)
         {
           pcount[n] = 0;
-          pstride[n] = GFC_DESCRIPTOR_STRIDE(pad,n);
+          pstride[n] = GFC_DESCRIPTOR_STRIDE_BYTES(pad,n);
           pextent[n] = GFC_DESCRIPTOR_EXTENT(pad,n);
           if (pextent[n] <= 0)
            {
@@ -212,7 +212,7 @@ reshape_'rtype_ccode` ('rtype` * const restrict ret,
        }
     }
 
-  rsize = 1;
+  rsize = GFC_DESCRIPTOR_SIZE(ret);
   for (index_type n = 0; n < rdim; n++)
     {
       index_type dim;
@@ -222,7 +222,7 @@ reshape_'rtype_ccode` ('rtype` * const restrict ret,
         dim = n;
 
       rcount[n] = 0;
-      rstride[n] = GFC_DESCRIPTOR_STRIDE(ret,dim);
+      rstride[n] = GFC_DESCRIPTOR_STRIDE_BYTES(ret,dim);
       rextent[n] = GFC_DESCRIPTOR_EXTENT(ret,dim);
       if (rextent[n] < 0)
         rextent[n] = 0;
@@ -244,12 +244,12 @@ reshape_'rtype_ccode` ('rtype` * const restrict ret,
    avoids a warning.  */
   GFC_ASSERT(sdim>0);
 
-  ssize = 1;
+  ssize = GFC_DESCRIPTOR_SIZE(source);
   sempty = 0;
   for (index_type n = 0; n < sdim; n++)
     {
       scount[n] = 0;
-      sstride[n] = GFC_DESCRIPTOR_STRIDE(source,n);
+      sstride[n] = GFC_DESCRIPTOR_STRIDE_BYTES(source,n);
       sextent[n] = GFC_DESCRIPTOR_EXTENT(source,n);
       if (sextent[n] <= 0)
        {
@@ -265,8 +265,6 @@ reshape_'rtype_ccode` ('rtype` * const restrict ret,
 
   if (rsize != 0 && ssize != 0 && psize != 0)
     {
-      rsize *= sizeof ('rtype_name`);
-      ssize *= sizeof ('rtype_name`);
       psize *= sizeof ('rtype_name`);
       reshape_packed ((char *)ret->base_addr, rsize, (char *)source->base_addr,
                      ssize, pad ? (char *)pad->base_addr : NULL, psize);
@@ -300,8 +298,8 @@ reshape_'rtype_ccode` ('rtype` * const restrict ret,
       /* Select between the source and pad arrays.  */
       *rptr = *src;
       /* Advance to the next element.  */
-      rptr += rstride0;
-      src += sstride0;
+      PTR_INCREMENT_BYTES (rptr, rstride0);
+      PTR_INCREMENT_BYTES (src, sstride0);
       rcount[0]++;
       scount[0]++;
 
@@ -314,7 +312,7 @@ reshape_'rtype_ccode` ('rtype` * const restrict ret,
           rcount[n] = 0;
           /* We could precalculate these products, but this is a less
              frequently used path so probably not worth it.  */
-          rptr -= rstride[n] * rextent[n];
+          PTR_DECREMENT_BYTES (rptr, rstride[n] * rextent[n]);
           n++;
           if (n == rdim)
             {
@@ -325,7 +323,7 @@ reshape_'rtype_ccode` ('rtype` * const restrict ret,
           else
             {
               rcount[n]++;
-              rptr += rstride[n];
+              PTR_INCREMENT_BYTES (rptr, rstride[n]);
             }
         }
       /* Advance to the next source element.  */
@@ -337,7 +335,7 @@ reshape_'rtype_ccode` ('rtype` * const restrict ret,
           scount[n] = 0;
           /* We could precalculate these products, but this is a less
              frequently used path so probably not worth it.  */
-          src -= sstride[n] * sextent[n];
+          PTR_DECREMENT_BYTES (src, sstride[n] * sextent[n]);
           n++;
           if (n == sdim)
             {
@@ -361,7 +359,7 @@ reshape_'rtype_ccode` ('rtype` * const restrict ret,
           else
             {
               scount[n]++;
-              src += sstride[n];
+              PTR_INCREMENT_BYTES (src, sstride[n]);
             }
         }
     }
diff --git a/libgfortran/m4/spread.m4 b/libgfortran/m4/spread.m4
index d8ca85ed2894..fbf26958cae0 100644
--- a/libgfortran/m4/spread.m4
+++ b/libgfortran/m4/spread.m4
@@ -85,15 +85,15 @@ spread_'rtype_code` ('rtype` *ret, const 'rtype` *source,
          if (n == along - 1)
            {
              ub = ncopies - 1;
-             rdelta = rs;
+             rdelta = rs * sizeof ('rtype_name`);
              rs *= ncopies;
            }
          else
            {
              count[dim] = 0;
              extent[dim] = GFC_DESCRIPTOR_EXTENT(source,dim);
-             sstride[dim] = GFC_DESCRIPTOR_STRIDE(source,dim);
-             rstride[dim] = rs;
+             sstride[dim] = GFC_DESCRIPTOR_STRIDE_BYTES(source,dim);
+             rstride[dim] = rs * sizeof ('rtype_name`);
 
              ub = extent[dim] - 1;
              rs *= extent[dim];
@@ -127,7 +127,7 @@ spread_'rtype_code` ('rtype` *ret, const 'rtype` *source,
              ret_extent = GFC_DESCRIPTOR_EXTENT(ret,n);
              if (n == along - 1)
                {
-                 rdelta = GFC_DESCRIPTOR_STRIDE(ret,n);
+                 rdelta = GFC_DESCRIPTOR_STRIDE_BYTES(ret,n);
 
                  if (ret_extent != ncopies)
                    runtime_error("Incorrect extent in return value of SPREAD"
@@ -148,8 +148,8 @@ spread_'rtype_code` ('rtype` *ret, const 'rtype` *source,
                    
                  if (extent[dim] <= 0)
                    zero_sized = 1;
-                 sstride[dim] = GFC_DESCRIPTOR_STRIDE(source,dim);
-                 rstride[dim] = GFC_DESCRIPTOR_STRIDE(ret,n);
+                 sstride[dim] = GFC_DESCRIPTOR_STRIDE_BYTES(source,dim);
+                 rstride[dim] = GFC_DESCRIPTOR_STRIDE_BYTES(ret,n);
                  dim++;
                }
            }
@@ -160,7 +160,7 @@ spread_'rtype_code` ('rtype` *ret, const 'rtype` *source,
            {
              if (n == along - 1)
                {
-                 rdelta = GFC_DESCRIPTOR_STRIDE(ret,n);
+                 rdelta = GFC_DESCRIPTOR_STRIDE_BYTES(ret,n);
                }
              else
                {
@@ -168,8 +168,8 @@ spread_'rtype_code` ('rtype` *ret, const 'rtype` *source,
                  extent[dim] = GFC_DESCRIPTOR_EXTENT(source,dim);
                  if (extent[dim] <= 0)
                    zero_sized = 1;
-                 sstride[dim] = GFC_DESCRIPTOR_STRIDE(source,dim);
-                 rstride[dim] = GFC_DESCRIPTOR_STRIDE(ret,n);
+                 sstride[dim] = GFC_DESCRIPTOR_STRIDE_BYTES(source,dim);
+                 rstride[dim] = GFC_DESCRIPTOR_STRIDE_BYTES(ret,n);
                  dim++;
                }
            }
@@ -179,7 +179,7 @@ spread_'rtype_code` ('rtype` *ret, const 'rtype` *source,
        return;
 
       if (sstride[0] == 0)
-       sstride[0] = 1;
+       sstride[0] = GFC_DESCRIPTOR_SIZE(source);
     }
   sstride0 = sstride[0];
   rstride0 = rstride[0];
@@ -193,11 +193,11 @@ spread_'rtype_code` ('rtype` *ret, const 'rtype` *source,
       for (n = 0; n < ncopies; n++)
         {
          *dest = *sptr;
-          dest += rdelta;
+          PTR_INCREMENT_BYTES (dest, rdelta);
         }
       /* Advance to the next element.  */
-      sptr += sstride0;
-      rptr += rstride0;
+      PTR_INCREMENT_BYTES (sptr, sstride0);
+      PTR_INCREMENT_BYTES (rptr, rstride0);
       count[0]++;
       n = 0;
       while (count[n] == extent[n])
@@ -207,8 +207,8 @@ spread_'rtype_code` ('rtype` *ret, const 'rtype` *source,
           count[n] = 0;
           /* We could precalculate these products, but this is a less
              frequently used path so probably not worth it.  */
-          sptr -= sstride[n] * extent[n];
-          rptr -= rstride[n] * extent[n];
+          PTR_DECREMENT_BYTES (sptr, sstride[n] * extent[n]);
+          PTR_DECREMENT_BYTES (rptr, rstride[n] * extent[n]);
           n++;
           if (n >= srank)
             {
@@ -219,8 +219,8 @@ spread_'rtype_code` ('rtype` *ret, const 'rtype` *source,
           else
             {
               count[n]++;
-              sptr += sstride[n];
-              rptr += rstride[n];
+              PTR_INCREMENT_BYTES (sptr, sstride[n]);
+              PTR_INCREMENT_BYTES (rptr, rstride[n]);
             }
         }
     }
@@ -256,12 +256,12 @@ spread_scalar_'rtype_code` ('rtype` *ret, const 
'rtype_name` *source,
     }
 
   dest = ret->base_addr;
-  stride = GFC_DESCRIPTOR_STRIDE(ret,0);
+  stride = GFC_DESCRIPTOR_STRIDE_BYTES(ret,0);
 
   for (index_type n = 0; n < ncopies; n++)
     {
       *dest = *source;
-      dest += stride;
+      PTR_INCREMENT_BYTES (dest, stride);
     }
 }
 
diff --git a/libgfortran/m4/unpack.m4 b/libgfortran/m4/unpack.m4
index 16b0066e5200..5aa923abadd7 100644
--- a/libgfortran/m4/unpack.m4
+++ b/libgfortran/m4/unpack.m4
@@ -95,7 +95,7 @@ unpack0_'rtype_code` ('rtype` *ret, const 'rtype` *vector,
                                       GFC_DESCRIPTOR_EXTENT(mask,n) - 1, rs);
          extent[n] = GFC_DESCRIPTOR_EXTENT(ret,n);
          empty = empty || extent[n] <= 0;
-         rstride[n] = GFC_DESCRIPTOR_STRIDE(ret,n);
+         rstride[n] = GFC_DESCRIPTOR_STRIDE_BYTES(ret,n);
          mstride[n] = GFC_DESCRIPTOR_STRIDE_BYTES(mask,n);
          rs *= extent[n];
        }
@@ -110,7 +110,7 @@ unpack0_'rtype_code` ('rtype` *ret, const 'rtype` *vector,
          count[n] = 0;
          extent[n] = GFC_DESCRIPTOR_EXTENT(ret,n);
          empty = empty || extent[n] <= 0;
-         rstride[n] = GFC_DESCRIPTOR_STRIDE(ret,n);
+         rstride[n] = GFC_DESCRIPTOR_STRIDE_BYTES(ret,n);
          mstride[n] = GFC_DESCRIPTOR_STRIDE_BYTES(mask,n);
        }
       if (rstride[0] == 0)
@@ -123,9 +123,9 @@ unpack0_'rtype_code` ('rtype` *ret, const 'rtype` *vector,
   if (mstride[0] == 0)
     mstride[0] = 1;
 
-  vstride0 = GFC_DESCRIPTOR_STRIDE(vector,0);
+  vstride0 = GFC_DESCRIPTOR_STRIDE_BYTES(vector,0);
   if (vstride0 == 0)
-    vstride0 = 1;
+    vstride0 = GFC_DESCRIPTOR_SIZE(vector);
   rstride0 = rstride[0];
   mstride0 = mstride[0];
   rptr = ret->base_addr;
@@ -137,7 +137,7 @@ unpack0_'rtype_code` ('rtype` *ret, const 'rtype` *vector,
         {
          /* From vector.  */
          *rptr = *vptr;
-         vptr += vstride0;
+         PTR_INCREMENT_BYTES (vptr, vstride0);
         }
       else
         {
@@ -145,7 +145,7 @@ unpack0_'rtype_code` ('rtype` *ret, const 'rtype` *vector,
          *rptr = fval;
         }
       /* Advance to the next element.  */
-      rptr += rstride0;
+      PTR_INCREMENT_BYTES (rptr, rstride0);
       mptr += mstride0;
       count[0]++;
       n = 0;
@@ -156,7 +156,7 @@ unpack0_'rtype_code` ('rtype` *ret, const 'rtype` *vector,
           count[n] = 0;
           /* We could precalculate these products, but this is a less
              frequently used path so probably not worth it.  */
-          rptr -= rstride[n] * extent[n];
+          PTR_DECREMENT_BYTES (rptr, rstride[n] * extent[n]);
           mptr -= mstride[n] * extent[n];
           n++;
           if (n >= dim)
@@ -168,7 +168,7 @@ unpack0_'rtype_code` ('rtype` *ret, const 'rtype` *vector,
           else
             {
               count[n]++;
-              rptr += rstride[n];
+              PTR_INCREMENT_BYTES (rptr, rstride[n]);
               mptr += mstride[n];
             }
         }
@@ -241,8 +241,8 @@ unpack1_'rtype_code` ('rtype` *ret, const 'rtype` *vector,
                                       GFC_DESCRIPTOR_EXTENT(mask,n) - 1, rs);
          extent[n] = GFC_DESCRIPTOR_EXTENT(ret,n);
          empty = empty || extent[n] <= 0;
-         rstride[n] = GFC_DESCRIPTOR_STRIDE(ret,n);
-         fstride[n] = GFC_DESCRIPTOR_STRIDE(field,n);
+         rstride[n] = GFC_DESCRIPTOR_STRIDE_BYTES(ret,n);
+         fstride[n] = GFC_DESCRIPTOR_STRIDE_BYTES(field,n);
          mstride[n] = GFC_DESCRIPTOR_STRIDE_BYTES(mask,n);
          rs *= extent[n];
        }
@@ -257,8 +257,8 @@ unpack1_'rtype_code` ('rtype` *ret, const 'rtype` *vector,
          count[n] = 0;
          extent[n] = GFC_DESCRIPTOR_EXTENT(ret,n);
          empty = empty || extent[n] <= 0;
-         rstride[n] = GFC_DESCRIPTOR_STRIDE(ret,n);
-         fstride[n] = GFC_DESCRIPTOR_STRIDE(field,n);
+         rstride[n] = GFC_DESCRIPTOR_STRIDE_BYTES(ret,n);
+         fstride[n] = GFC_DESCRIPTOR_STRIDE_BYTES(field,n);
          mstride[n] = GFC_DESCRIPTOR_STRIDE_BYTES(mask,n);
        }
       if (rstride[0] == 0)
@@ -269,13 +269,13 @@ unpack1_'rtype_code` ('rtype` *ret, const 'rtype` *vector,
     return;
 
   if (fstride[0] == 0)
-    fstride[0] = 1;
+    fstride[0] = GFC_DESCRIPTOR_SIZE(field);
   if (mstride[0] == 0)
     mstride[0] = 1;
 
-  vstride0 = GFC_DESCRIPTOR_STRIDE(vector,0);
+  vstride0 = GFC_DESCRIPTOR_STRIDE_BYTES(vector,0);
   if (vstride0 == 0)
-    vstride0 = 1;
+    vstride0 = GFC_DESCRIPTOR_SIZE(vector);
   rstride0 = rstride[0];
   fstride0 = fstride[0];
   mstride0 = mstride[0];
@@ -289,7 +289,7 @@ unpack1_'rtype_code` ('rtype` *ret, const 'rtype` *vector,
         {
           /* From vector.  */
          *rptr = *vptr;
-          vptr += vstride0;
+          PTR_INCREMENT_BYTES (vptr, vstride0);
         }
       else
         {
@@ -297,8 +297,8 @@ unpack1_'rtype_code` ('rtype` *ret, const 'rtype` *vector,
          *rptr = *fptr;
         }
       /* Advance to the next element.  */
-      rptr += rstride0;
-      fptr += fstride0;
+      PTR_INCREMENT_BYTES (rptr, rstride0);
+      PTR_INCREMENT_BYTES (fptr, fstride0);
       mptr += mstride0;
       count[0]++;
       n = 0;
@@ -309,8 +309,8 @@ unpack1_'rtype_code` ('rtype` *ret, const 'rtype` *vector,
           count[n] = 0;
           /* We could precalculate these products, but this is a less
              frequently used path so probably not worth it.  */
-          rptr -= rstride[n] * extent[n];
-          fptr -= fstride[n] * extent[n];
+          PTR_DECREMENT_BYTES (rptr, rstride[n] * extent[n]);
+          PTR_DECREMENT_BYTES (fptr, fstride[n] * extent[n]);
           mptr -= mstride[n] * extent[n];
           n++;
           if (n >= dim)
@@ -322,8 +322,8 @@ unpack1_'rtype_code` ('rtype` *ret, const 'rtype` *vector,
           else
             {
               count[n]++;
-              rptr += rstride[n];
-              fptr += fstride[n];
+              PTR_INCREMENT_BYTES (rptr, rstride[n]);
+              PTR_INCREMENT_BYTES (fptr, fstride[n]);
               mptr += mstride[n];
             }
         }

Reply via email to