https://gcc.gnu.org/g:506f1f36e038f602227952fdce4a585a15893da4

commit 506f1f36e038f602227952fdce4a585a15893da4
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

Diff:
---
 libgfortran/intrinsics/date_and_time.c | 106 +++++++++++++++++++++------------
 libgfortran/intrinsics/dtime.c         |   2 +-
 libgfortran/intrinsics/etime.c         |   2 +-
 libgfortran/intrinsics/random.c        |  54 ++++++++---------
 libgfortran/io/read.c                  |   2 +-
 libgfortran/libgfortran.h              |   4 ++
 libgfortran/m4/cshift0.m4              |  34 +++++------
 libgfortran/m4/cshift1.m4              |   8 +--
 libgfortran/m4/cshift1a.m4             |  36 +++++------
 libgfortran/m4/eoshift1.m4             |   8 +--
 libgfortran/m4/eoshift3.m4             |   8 +--
 libgfortran/m4/ifindloc0.m4            |  22 +++----
 libgfortran/m4/ifindloc1.m4            |  45 +++++++-------
 libgfortran/m4/ifindloc2.m4            |  10 ++--
 libgfortran/m4/iforeach-s.m4           |  12 ++--
 libgfortran/m4/iforeach-s2.m4          |  12 ++--
 libgfortran/m4/iforeach.m4             |  12 ++--
 libgfortran/m4/ifunction-s.m4          |  45 +++++++-------
 libgfortran/m4/ifunction-s2.m4         |  47 ++++++++-------
 libgfortran/m4/ifunction.m4            |  41 +++++++------
 libgfortran/m4/ifunction_logical.m4    |  15 ++---
 libgfortran/m4/in_pack.m4              |   6 +-
 libgfortran/m4/in_unpack.m4            |   6 +-
 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               |   5 +-
 libgfortran/m4/maxval1s.m4             |   4 +-
 libgfortran/m4/minloc0.m4              |   8 +--
 libgfortran/m4/minloc1.m4              |  41 ++++++++-----
 libgfortran/m4/minloc1s.m4             |   4 +-
 libgfortran/m4/minloc2s.m4             |  10 ++--
 libgfortran/m4/minval.m4               |   7 ++-
 libgfortran/m4/minval1s.m4             |   4 +-
 libgfortran/m4/pack.m4                 |  18 +++---
 libgfortran/m4/reshape.m4              |  22 ++++---
 libgfortran/m4/spread.m4               |  32 +++++-----
 libgfortran/m4/unpack.m4               |  38 ++++++------
 40 files changed, 431 insertions(+), 354 deletions(-)

diff --git a/libgfortran/intrinsics/date_and_time.c 
b/libgfortran/intrinsics/date_and_time.c
index a5042cb2bcf8..00702b7dc6fb 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 *);
@@ -567,8 +588,11 @@ gmtime_i8 (GFC_INTEGER_8 * t, gfc_array_i8 * tarray)
     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..251eb4f61c2b 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;
@@ -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;
@@ -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;
@@ -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;
@@ -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;
@@ -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;
@@ -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;
@@ -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;
@@ -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;
@@ -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/libgfortran.h b/libgfortran/libgfortran.h
index afa2cc43ecd6..272639df9816 100644
--- a/libgfortran/libgfortran.h
+++ b/libgfortran/libgfortran.h
@@ -585,6 +585,10 @@ 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)
+
+
 /* Generic vtab structure.  */
 typedef struct
 {
diff --git a/libgfortran/m4/cshift0.m4 b/libgfortran/m4/cshift0.m4
index 6ca3db403ce1..2c31f7611373 100644
--- a/libgfortran/m4/cshift0.m4
+++ b/libgfortran/m4/cshift0.m4
@@ -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;
+               roffset = GFC_DESCRIPTOR_SIZE(ret);
              soffset = GFC_DESCRIPTOR_STRIDE(array,dim);
              if (soffset == 0)
-               soffset = 1;
+               soffset = GFC_DESCRIPTOR_SIZE(array);
              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] = GFC_DESCRIPTOR_SIZE(array);
       if (rstride[0] == 0)
-       rstride[0] = 1;
+       rstride[0] = GFC_DESCRIPTOR_SIZE(ret);
 
       dim = GFC_DESCRIPTOR_RANK (array);
     }
@@ -196,20 +196,20 @@ cshift0_'rtype_code` ('rtype` *ret, const 'rtype` *array, 
ptrdiff_t shift,
          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])
@@ -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..29d5b675b598 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] = GFC_DESCRIPTOR_SIZE(h);
 
   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])
@@ -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..b1cbac585b32 100644
--- a/libgfortran/m4/cshift1a.m4
+++ b/libgfortran/m4/cshift1a.m4
@@ -84,10 +84,10 @@ 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);
+          soffset = GFC_DESCRIPTOR_STRIDE_BYTES(array,dim);
           if (soffset == 0)
             soffset = 1;
           len = GFC_DESCRIPTOR_EXTENT(array,dim);
@@ -96,9 +96,9 @@ cshift1'rtype_qual`_'atype_code` ('atype` * const restrict 
ret,
         {
           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] = GFC_DESCRIPTOR_SIZE(array);
   if (rstride[0] == 0)
-    rstride[0] = 1;
+    rstride[0] = GFC_DESCRIPTOR_SIZE(ret);
   if (hstride[0] == 0)
-    hstride[0] = 1;
+    hstride[0] = GFC_DESCRIPTOR_SIZE(h);
 
   dim = GFC_DESCRIPTOR_RANK (array);
   rstride0 = rstride[0];
@@ -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])
@@ -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..07ebe3883e04 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])
@@ -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..4fa8287500fa 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;
@@ -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/ifindloc0.m4 b/libgfortran/m4/ifindloc0.m4
index c484342f3cb9..7d02b979e6b3 100644
--- a/libgfortran/m4/ifindloc0.m4
+++ b/libgfortran/m4/ifindloc0.m4
@@ -57,7 +57,7 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If 
not, see
                                "FINDLOC");
     }
 
-  dstride = GFC_DESCRIPTOR_STRIDE(retarray,0);
+  dstride = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
   dest = retarray->base_addr;
 
   /* Set the return value.  */
@@ -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)
@@ -103,7 +103,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] * 'base_mult`);
              n++;
              if (n >= rank)
                return;
@@ -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] * 'base_mult`);
            } while(++count[0] != extent[0]);
 
          n = 0;
@@ -147,7 +147,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] * 'base_mult`);
                }
            } while (count[n] == extent[n]);
        }
@@ -205,7 +205,7 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  
If not, see
   else
     internal_error (NULL, "Funny sized logical array");
 
-  dstride = GFC_DESCRIPTOR_STRIDE(retarray,0);
+  dstride = GFC_DESCRIPTOR_STRIDE_BYTES(retarray,0);
   dest = retarray->base_addr;
 
   /* Set the return value.  */
@@ -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];
@@ -228,7 +228,7 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  
If not, see
 
   if (back)
     {
-      base = array->base_addr + (sz - 1) * 'base_mult`;
+      base = (const 'atype_name` *) (((char*)array->base_addr) + (sz - 1) * 
'base_mult`);
       mbase = mbase + (sz - 1) * mask_kind;
       while (1)
         {
@@ -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] * 'base_mult`);
              mbase -= mstride[n] * extent[n];
              n++;
              if (n >= rank)
@@ -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] * 'base_mult`);
              mbase += mstride[0];
            } while(++count[0] != extent[0]);
 
@@ -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]* 'base_mult`);
                  mbase += mstride[n];
                }
            } while (count[n] == extent[n]);
diff --git a/libgfortran/m4/ifindloc1.m4 b/libgfortran/m4/ifindloc1.m4
index 7b2c2d2a6557..3ee3709fc6af 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;
     }
@@ -144,20 +144,21 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  
If not, see
       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 * 'base_mult`);
            }
        }
       *dest = result;
 
       count[0]++;
-      base += sstride[0] * 'base_mult`;
-      dest += dstride[0];
+      PTR_INCREMENT_BYTES (base, sstride[0] * 'base_mult`);
+      PTR_INCREMENT_BYTES (dest, dstride[0]);
       n = 0;
       while (count[n] == extent[n])
        {
@@ -173,8 +174,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] * 'base_mult`);
+             PTR_INCREMENT_BYTES (dest, dstride[n]);
            }
        }
     }
@@ -213,7 +214,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 +232,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 +241,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 +288,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;
     }
@@ -320,21 +321,23 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  
If not, see
        {
          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 * 'base_mult`);
+             msrc += mdelta;
            }
        }
       *dest = result;
 
       count[0]++;
-      base += sstride[0] * 'base_mult`;
+      PTR_INCREMENT_BYTES (base, sstride[0] * 'base_mult`);
+      PTR_INCREMENT_BYTES (dest, dstride[0]);
       mbase += mstride[0];
-      dest += dstride[0];
       n = 0;
       while (count[n] == extent[n])
        {
@@ -351,8 +354,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] * 'base_mult`);
+             PTR_INCREMENT_BYTES (dest, dstride[n]);
            }
        }
     }
@@ -446,7 +449,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,7 +461,7 @@ 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])
        {
@@ -473,7 +476,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..36a3a3728e66 100644
--- a/libgfortran/m4/ifindloc2.m4
+++ b/libgfortran/m4/ifindloc2.m4
@@ -37,10 +37,10 @@ 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) * 'base_mult`;
   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`)
@@ -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,12 +87,12 @@ 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) * 'base_mult`;
   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--)
        {
diff --git a/libgfortran/m4/iforeach-s.m4 b/libgfortran/m4/iforeach-s.m4
index b00f900a5fd7..12c4baaaa447 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) * len;
       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;
@@ -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) * len;
       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]);
@@ -233,7 +233,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-s2.m4 b/libgfortran/m4/iforeach-s2.m4
index c2248f312754..0a368582330a 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) * len;
       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;
@@ -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) * len;
       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]);
@@ -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..dd9ae01093aa 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;
@@ -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]);
@@ -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..f12b324dbf42 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) * string_len;
 
   for (n = 0; n < dim; n++)
     {
-      sstride[n] = GFC_DESCRIPTOR_STRIDE(array,n) * string_len;
+      sstride[n] = GFC_DESCRIPTOR_STRIDE_BYTES(array,n) * string_len;
       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) * string_len;
       extent[n] = GFC_DESCRIPTOR_EXTENT(array, n + 1);
 
       if (extent[n] < 0)
@@ -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])
        {
@@ -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) * string_len;
   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) * string_len;
       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) * string_len;
       mstride[n] = GFC_DESCRIPTOR_STRIDE_BYTES(mask, n + 1);
       extent[n] = GFC_DESCRIPTOR_EXTENT(array, n + 1);
 
@@ -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])
        {
@@ -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];
            }
        }
     }
@@ -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) * string_len;
     }
 
   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])
        {
@@ -508,7 +511,7 @@ s'name`'rtype_qual`_'atype_code` ('rtype` * const restrict 
retarray,
          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..df0448636a90 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) * string_len;
 
   for (n = 0; n < dim; n++)
     {
-      sstride[n] = GFC_DESCRIPTOR_STRIDE(array,n) * string_len;
+      sstride[n] = GFC_DESCRIPTOR_STRIDE_BYTES(array,n) * string_len;
       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) * string_len;
       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) * string_len;
       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])
        {
@@ -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) * string_len;
   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) * string_len;
       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) * string_len;
       mstride[n] = GFC_DESCRIPTOR_STRIDE_BYTES(mask, n + 1);
       extent[n] = GFC_DESCRIPTOR_EXTENT(array, n + 1);
 
@@ -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) * string_len;
       if (extent[n] <= 0)
        return;
     }
@@ -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])
        {
@@ -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];
            }
        }
     }
@@ -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) * string_len;
     }
 
   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])
        {
@@ -510,7 +513,7 @@ s'name`'rtype_qual`_'atype_code` ('rtype` * const restrict 
retarray,
          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..3bf9a05c9b46 100644
--- a/libgfortran/m4/ifunction.m4
+++ b/libgfortran/m4/ifunction.m4
@@ -135,20 +135,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])
        {
@@ -169,8 +170,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 +243,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 +258,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);
 
@@ -305,7 +306,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 +324,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])
        {
@@ -356,9 +359,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 +475,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 +484,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])
        {
@@ -497,7 +500,7 @@ s'name`'rtype_qual`_'atype_code` ('rtype` * const restrict 
retarray,
          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..dcfd03bd920d 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])
         {
@@ -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..bae7b9b4af69 100644
--- a/libgfortran/m4/in_pack.m4
+++ b/libgfortran/m4/in_pack.m4
@@ -57,7 +57,7 @@ internal_pack_'rtype_ccode` ('rtype` * source)
   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;
@@ -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..814e6c6552ef 100644
--- a/libgfortran/m4/in_unpack.m4
+++ b/libgfortran/m4/in_unpack.m4
@@ -52,7 +52,7 @@ internal_unpack_'rtype_ccode` ('rtype` * d, const 
'rtype_name` * src)
   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;
@@ -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;
@@ -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/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..884ab3e6a473 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;
+                   }
+                 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..614d6e409072 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) * len;
 
   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) * len;
 
   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..f38d9cb24726 100644
--- a/libgfortran/m4/maxval.m4
+++ b/libgfortran/m4/maxval.m4
@@ -39,6 +39,7 @@ ARRAY_FUNCTION(atype_min,
 `#if defined ('atype_nan`)
                if (*src >= result)
                  break;
+               PTR_INCREMENT_BYTES (src, delta);
              }
            if (unlikely (n >= len))
              result = 'atype_nan`;
@@ -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..9529868939b9 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,27 +50,32 @@ 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))
                    {
                      minval = *src;
                      result = (rtype_name) n + 1;
-                   }')
+                   }
+                 PTR_INCREMENT_BYTES (src, delta);')
 
 MASKED_ARRAY_FUNCTION(0,
 `      'atype_name` minval;
@@ -96,6 +101,8 @@ MASKED_ARRAY_FUNCTION(0,
                        break;
                      }
                  }
+               PTR_INCREMENT_BYTES (src, delta);
+               msrc += mdelta;
              }
 #if defined ('atype_nan`)
            if (unlikely (n >= len))
@@ -103,22 +110,26 @@ 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))
                      {
                        minval = *src;
                        result = (rtype_name) n + 1;
-                     }')
+                     }
+                   PTR_INCREMENT_BYTES (src, delta);
+                   msrc += mdelta;')
 
 SCALAR_ARRAY_FUNCTION(0)
 
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..39d4afef79e0 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) * len;
 
   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) * len;
 
   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..1529360bf9ec 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] = GFC_DESCRIPTOR_SIZE(array);
   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 = GFC_DESCRIPTOR_SIZE(ret);
   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;
@@ -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];
             }
         }
@@ -250,8 +250,8 @@ pack_'rtype_code` ('rtype` *ret, const 'rtype` *array,
           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..49059fc5055e 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]++;
 
@@ -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.  */
@@ -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..a4411d6d9250 100644
--- a/libgfortran/m4/spread.m4
+++ b/libgfortran/m4/spread.m4
@@ -78,7 +78,7 @@ spread_'rtype_code` ('rtype` *ret, const 'rtype` *source,
       ret->dtype.rank = rrank;
 
       dim = 0;
-      rs = 1;
+      rs = GFC_DESCRIPTOR_SIZE(ret);
       for (n = 0; n < rrank; n++)
        {
          stride = rs;
@@ -92,7 +92,7 @@ spread_'rtype_code` ('rtype` *ret, const 'rtype` *source,
            {
              count[dim] = 0;
              extent[dim] = GFC_DESCRIPTOR_EXTENT(source,dim);
-             sstride[dim] = GFC_DESCRIPTOR_STRIDE(source,dim);
+             sstride[dim] = GFC_DESCRIPTOR_STRIDE_BYTES(source,dim);
              rstride[dim] = rs;
 
              ub = extent[dim] - 1;
@@ -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])
@@ -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..28033a1fb6d9 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;
@@ -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;
@@ -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