https://gcc.gnu.org/g:447e2b86e7dccb35b71d9b5966bd81997f714121

commit 447e2b86e7dccb35b71d9b5966bd81997f714121
Author: Mikael Morin <mik...@gcc.gnu.org>
Date:   Wed May 14 19:09:09 2025 +0200

    Correction régression findloc_2

Diff:
---
 libgfortran/generated/findloc0_c10.c | 33 ++++++++++-----------------------
 libgfortran/generated/findloc0_c16.c | 33 ++++++++++-----------------------
 libgfortran/generated/findloc0_c17.c | 33 ++++++++++-----------------------
 libgfortran/generated/findloc0_c4.c  | 33 ++++++++++-----------------------
 libgfortran/generated/findloc0_c8.c  | 33 ++++++++++-----------------------
 libgfortran/generated/findloc0_i1.c  | 33 ++++++++++-----------------------
 libgfortran/generated/findloc0_i16.c | 33 ++++++++++-----------------------
 libgfortran/generated/findloc0_i2.c  | 33 ++++++++++-----------------------
 libgfortran/generated/findloc0_i4.c  | 33 ++++++++++-----------------------
 libgfortran/generated/findloc0_i8.c  | 33 ++++++++++-----------------------
 libgfortran/generated/findloc0_r10.c | 33 ++++++++++-----------------------
 libgfortran/generated/findloc0_r16.c | 33 ++++++++++-----------------------
 libgfortran/generated/findloc0_r17.c | 33 ++++++++++-----------------------
 libgfortran/generated/findloc0_r4.c  | 33 ++++++++++-----------------------
 libgfortran/generated/findloc0_r8.c  | 33 ++++++++++-----------------------
 libgfortran/generated/findloc0_s1.c  | 33 ++++++++++-----------------------
 libgfortran/generated/findloc0_s4.c  | 33 ++++++++++-----------------------
 libgfortran/m4/ifindloc0.m4          | 33 ++++++++++-----------------------
 18 files changed, 180 insertions(+), 414 deletions(-)

diff --git a/libgfortran/generated/findloc0_c10.c 
b/libgfortran/generated/findloc0_c10.c
index 435f50c52331..ee8a08e225cf 100644
--- a/libgfortran/generated/findloc0_c10.c
+++ b/libgfortran/generated/findloc0_c10.c
@@ -41,12 +41,9 @@ findloc0_c10 (gfc_array_index_type * const restrict retarray,
   index_type count[GFC_MAX_DIMENSIONS];
   index_type extent[GFC_MAX_DIMENSIONS];
   index_type sspacing[GFC_MAX_DIMENSIONS];
-  index_type dspacing;
   const GFC_COMPLEX_10 *base;
-  index_type * restrict dest;
   index_type rank;
   index_type n;
-  index_type sz;
 
   rank = GFC_DESCRIPTOR_RANK (array);
   if (rank <= 0)
@@ -66,19 +63,14 @@ findloc0_c10 (gfc_array_index_type * const restrict 
retarray,
                                "FINDLOC");
     }
 
-  dspacing = GFC_DESCRIPTOR_SPACING(retarray,0);
-  dest = retarray->base_addr;
-
   /* Set the return value.  */
   for (n = 0; n < rank; n++)
     GFC_DESCRIPTOR1_ELEM (index_type, retarray, n) = 0;
 
-  sz = sizeof (GFC_COMPLEX_10);
   for (n = 0; n < rank; n++)
     {
       sspacing[n] = GFC_DESCRIPTOR_SPACING(array,n);
       extent[n] = GFC_DESCRIPTOR_EXTENT(array,n);
-      sz *= extent[n];
       if (extent[n] <= 0)
        return;
     }
@@ -88,7 +80,9 @@ findloc0_c10 (gfc_array_index_type * const restrict retarray,
 
   if (back)
     {
-      base = (GFC_COMPLEX_10*) (((char*)array->base_addr) + (sz - 1));
+      base = array->base_addr;
+      for (n = 0; n < rank; n++)
+       base = (GFC_COMPLEX_10*) (((char*)base) + (extent[n] - 1) * 
sspacing[n]);
 
       while (1)
         {
@@ -178,14 +172,11 @@ mfindloc0_c10 (gfc_array_index_type * const restrict 
retarray,
   index_type extent[GFC_MAX_DIMENSIONS];
   index_type sspacing[GFC_MAX_DIMENSIONS];
   index_type mspacing[GFC_MAX_DIMENSIONS];
-  index_type dspacing;
   const GFC_COMPLEX_10 *base;
-  index_type * restrict dest;
   GFC_LOGICAL_1 *mbase;
   index_type rank;
   index_type n;
   int mask_kind;
-  index_type sz;
 
   rank = GFC_DESCRIPTOR_RANK (array);
   if (rank <= 0)
@@ -222,20 +213,15 @@ mfindloc0_c10 (gfc_array_index_type * const restrict 
retarray,
   else
     internal_error (NULL, "Funny sized logical array");
 
-  dspacing = GFC_DESCRIPTOR_SPACING(retarray,0);
-  dest = retarray->base_addr;
-
   /* Set the return value.  */
   for (n = 0; n < rank; n++)
     GFC_DESCRIPTOR1_ELEM (index_type, retarray, n) = 0;
 
-  sz = sizeof (GFC_COMPLEX_10);
   for (n = 0; n < rank; n++)
     {
       sspacing[n] = GFC_DESCRIPTOR_SPACING(array,n);
       mspacing[n] = GFC_DESCRIPTOR_SPACING(mask,n);
       extent[n] = GFC_DESCRIPTOR_EXTENT(array,n);
-      sz *= extent[n];
       if (extent[n] <= 0)
        return;
     }
@@ -245,8 +231,13 @@ mfindloc0_c10 (gfc_array_index_type * const restrict 
retarray,
 
   if (back)
     {
-      base = (GFC_COMPLEX_10*) (((char*)array->base_addr) + (sz - 1));
-      mbase = mbase + (sz - 1) * mask_kind;
+      base = array->base_addr;
+      for (n = 0; n < rank; n++)
+       {
+         base = (GFC_COMPLEX_10*) (((char*)base) + (extent[n] - 1) * 
sspacing[n]);
+         mbase = mbase + (extent[n] - 1) * mspacing[n];
+       }
+
       while (1)
         {
          do
@@ -338,8 +329,6 @@ sfindloc0_c10 (gfc_array_index_type * const restrict 
retarray,
            GFC_LOGICAL_4 * mask, GFC_LOGICAL_4 back)
 {
   index_type rank;
-  index_type dspacing;
-  index_type * restrict dest;
   index_type n;
 
   if (mask == NULL || *mask)
@@ -366,8 +355,6 @@ sfindloc0_c10 (gfc_array_index_type * const restrict 
retarray,
                               "FINDLOC");
     }
 
-  dspacing = GFC_DESCRIPTOR_SPACING(retarray,0);
-  dest = retarray->base_addr;
   for (n = 0; n<rank; n++)
     GFC_DESCRIPTOR1_ELEM (index_type, retarray, n) = 0 ;
 }
diff --git a/libgfortran/generated/findloc0_c16.c 
b/libgfortran/generated/findloc0_c16.c
index 95bf863cb8b3..f9e07a127165 100644
--- a/libgfortran/generated/findloc0_c16.c
+++ b/libgfortran/generated/findloc0_c16.c
@@ -41,12 +41,9 @@ findloc0_c16 (gfc_array_index_type * const restrict retarray,
   index_type count[GFC_MAX_DIMENSIONS];
   index_type extent[GFC_MAX_DIMENSIONS];
   index_type sspacing[GFC_MAX_DIMENSIONS];
-  index_type dspacing;
   const GFC_COMPLEX_16 *base;
-  index_type * restrict dest;
   index_type rank;
   index_type n;
-  index_type sz;
 
   rank = GFC_DESCRIPTOR_RANK (array);
   if (rank <= 0)
@@ -66,19 +63,14 @@ findloc0_c16 (gfc_array_index_type * const restrict 
retarray,
                                "FINDLOC");
     }
 
-  dspacing = GFC_DESCRIPTOR_SPACING(retarray,0);
-  dest = retarray->base_addr;
-
   /* Set the return value.  */
   for (n = 0; n < rank; n++)
     GFC_DESCRIPTOR1_ELEM (index_type, retarray, n) = 0;
 
-  sz = sizeof (GFC_COMPLEX_16);
   for (n = 0; n < rank; n++)
     {
       sspacing[n] = GFC_DESCRIPTOR_SPACING(array,n);
       extent[n] = GFC_DESCRIPTOR_EXTENT(array,n);
-      sz *= extent[n];
       if (extent[n] <= 0)
        return;
     }
@@ -88,7 +80,9 @@ findloc0_c16 (gfc_array_index_type * const restrict retarray,
 
   if (back)
     {
-      base = (GFC_COMPLEX_16*) (((char*)array->base_addr) + (sz - 1));
+      base = array->base_addr;
+      for (n = 0; n < rank; n++)
+       base = (GFC_COMPLEX_16*) (((char*)base) + (extent[n] - 1) * 
sspacing[n]);
 
       while (1)
         {
@@ -178,14 +172,11 @@ mfindloc0_c16 (gfc_array_index_type * const restrict 
retarray,
   index_type extent[GFC_MAX_DIMENSIONS];
   index_type sspacing[GFC_MAX_DIMENSIONS];
   index_type mspacing[GFC_MAX_DIMENSIONS];
-  index_type dspacing;
   const GFC_COMPLEX_16 *base;
-  index_type * restrict dest;
   GFC_LOGICAL_1 *mbase;
   index_type rank;
   index_type n;
   int mask_kind;
-  index_type sz;
 
   rank = GFC_DESCRIPTOR_RANK (array);
   if (rank <= 0)
@@ -222,20 +213,15 @@ mfindloc0_c16 (gfc_array_index_type * const restrict 
retarray,
   else
     internal_error (NULL, "Funny sized logical array");
 
-  dspacing = GFC_DESCRIPTOR_SPACING(retarray,0);
-  dest = retarray->base_addr;
-
   /* Set the return value.  */
   for (n = 0; n < rank; n++)
     GFC_DESCRIPTOR1_ELEM (index_type, retarray, n) = 0;
 
-  sz = sizeof (GFC_COMPLEX_16);
   for (n = 0; n < rank; n++)
     {
       sspacing[n] = GFC_DESCRIPTOR_SPACING(array,n);
       mspacing[n] = GFC_DESCRIPTOR_SPACING(mask,n);
       extent[n] = GFC_DESCRIPTOR_EXTENT(array,n);
-      sz *= extent[n];
       if (extent[n] <= 0)
        return;
     }
@@ -245,8 +231,13 @@ mfindloc0_c16 (gfc_array_index_type * const restrict 
retarray,
 
   if (back)
     {
-      base = (GFC_COMPLEX_16*) (((char*)array->base_addr) + (sz - 1));
-      mbase = mbase + (sz - 1) * mask_kind;
+      base = array->base_addr;
+      for (n = 0; n < rank; n++)
+       {
+         base = (GFC_COMPLEX_16*) (((char*)base) + (extent[n] - 1) * 
sspacing[n]);
+         mbase = mbase + (extent[n] - 1) * mspacing[n];
+       }
+
       while (1)
         {
          do
@@ -338,8 +329,6 @@ sfindloc0_c16 (gfc_array_index_type * const restrict 
retarray,
            GFC_LOGICAL_4 * mask, GFC_LOGICAL_4 back)
 {
   index_type rank;
-  index_type dspacing;
-  index_type * restrict dest;
   index_type n;
 
   if (mask == NULL || *mask)
@@ -366,8 +355,6 @@ sfindloc0_c16 (gfc_array_index_type * const restrict 
retarray,
                               "FINDLOC");
     }
 
-  dspacing = GFC_DESCRIPTOR_SPACING(retarray,0);
-  dest = retarray->base_addr;
   for (n = 0; n<rank; n++)
     GFC_DESCRIPTOR1_ELEM (index_type, retarray, n) = 0 ;
 }
diff --git a/libgfortran/generated/findloc0_c17.c 
b/libgfortran/generated/findloc0_c17.c
index ce43ab66b0a6..fa77f113b31e 100644
--- a/libgfortran/generated/findloc0_c17.c
+++ b/libgfortran/generated/findloc0_c17.c
@@ -41,12 +41,9 @@ findloc0_c17 (gfc_array_index_type * const restrict retarray,
   index_type count[GFC_MAX_DIMENSIONS];
   index_type extent[GFC_MAX_DIMENSIONS];
   index_type sspacing[GFC_MAX_DIMENSIONS];
-  index_type dspacing;
   const GFC_COMPLEX_17 *base;
-  index_type * restrict dest;
   index_type rank;
   index_type n;
-  index_type sz;
 
   rank = GFC_DESCRIPTOR_RANK (array);
   if (rank <= 0)
@@ -66,19 +63,14 @@ findloc0_c17 (gfc_array_index_type * const restrict 
retarray,
                                "FINDLOC");
     }
 
-  dspacing = GFC_DESCRIPTOR_SPACING(retarray,0);
-  dest = retarray->base_addr;
-
   /* Set the return value.  */
   for (n = 0; n < rank; n++)
     GFC_DESCRIPTOR1_ELEM (index_type, retarray, n) = 0;
 
-  sz = sizeof (GFC_COMPLEX_17);
   for (n = 0; n < rank; n++)
     {
       sspacing[n] = GFC_DESCRIPTOR_SPACING(array,n);
       extent[n] = GFC_DESCRIPTOR_EXTENT(array,n);
-      sz *= extent[n];
       if (extent[n] <= 0)
        return;
     }
@@ -88,7 +80,9 @@ findloc0_c17 (gfc_array_index_type * const restrict retarray,
 
   if (back)
     {
-      base = (GFC_COMPLEX_17*) (((char*)array->base_addr) + (sz - 1));
+      base = array->base_addr;
+      for (n = 0; n < rank; n++)
+       base = (GFC_COMPLEX_17*) (((char*)base) + (extent[n] - 1) * 
sspacing[n]);
 
       while (1)
         {
@@ -178,14 +172,11 @@ mfindloc0_c17 (gfc_array_index_type * const restrict 
retarray,
   index_type extent[GFC_MAX_DIMENSIONS];
   index_type sspacing[GFC_MAX_DIMENSIONS];
   index_type mspacing[GFC_MAX_DIMENSIONS];
-  index_type dspacing;
   const GFC_COMPLEX_17 *base;
-  index_type * restrict dest;
   GFC_LOGICAL_1 *mbase;
   index_type rank;
   index_type n;
   int mask_kind;
-  index_type sz;
 
   rank = GFC_DESCRIPTOR_RANK (array);
   if (rank <= 0)
@@ -222,20 +213,15 @@ mfindloc0_c17 (gfc_array_index_type * const restrict 
retarray,
   else
     internal_error (NULL, "Funny sized logical array");
 
-  dspacing = GFC_DESCRIPTOR_SPACING(retarray,0);
-  dest = retarray->base_addr;
-
   /* Set the return value.  */
   for (n = 0; n < rank; n++)
     GFC_DESCRIPTOR1_ELEM (index_type, retarray, n) = 0;
 
-  sz = sizeof (GFC_COMPLEX_17);
   for (n = 0; n < rank; n++)
     {
       sspacing[n] = GFC_DESCRIPTOR_SPACING(array,n);
       mspacing[n] = GFC_DESCRIPTOR_SPACING(mask,n);
       extent[n] = GFC_DESCRIPTOR_EXTENT(array,n);
-      sz *= extent[n];
       if (extent[n] <= 0)
        return;
     }
@@ -245,8 +231,13 @@ mfindloc0_c17 (gfc_array_index_type * const restrict 
retarray,
 
   if (back)
     {
-      base = (GFC_COMPLEX_17*) (((char*)array->base_addr) + (sz - 1));
-      mbase = mbase + (sz - 1) * mask_kind;
+      base = array->base_addr;
+      for (n = 0; n < rank; n++)
+       {
+         base = (GFC_COMPLEX_17*) (((char*)base) + (extent[n] - 1) * 
sspacing[n]);
+         mbase = mbase + (extent[n] - 1) * mspacing[n];
+       }
+
       while (1)
         {
          do
@@ -338,8 +329,6 @@ sfindloc0_c17 (gfc_array_index_type * const restrict 
retarray,
            GFC_LOGICAL_4 * mask, GFC_LOGICAL_4 back)
 {
   index_type rank;
-  index_type dspacing;
-  index_type * restrict dest;
   index_type n;
 
   if (mask == NULL || *mask)
@@ -366,8 +355,6 @@ sfindloc0_c17 (gfc_array_index_type * const restrict 
retarray,
                               "FINDLOC");
     }
 
-  dspacing = GFC_DESCRIPTOR_SPACING(retarray,0);
-  dest = retarray->base_addr;
   for (n = 0; n<rank; n++)
     GFC_DESCRIPTOR1_ELEM (index_type, retarray, n) = 0 ;
 }
diff --git a/libgfortran/generated/findloc0_c4.c 
b/libgfortran/generated/findloc0_c4.c
index 43c004605790..f9ac7062a185 100644
--- a/libgfortran/generated/findloc0_c4.c
+++ b/libgfortran/generated/findloc0_c4.c
@@ -41,12 +41,9 @@ findloc0_c4 (gfc_array_index_type * const restrict retarray,
   index_type count[GFC_MAX_DIMENSIONS];
   index_type extent[GFC_MAX_DIMENSIONS];
   index_type sspacing[GFC_MAX_DIMENSIONS];
-  index_type dspacing;
   const GFC_COMPLEX_4 *base;
-  index_type * restrict dest;
   index_type rank;
   index_type n;
-  index_type sz;
 
   rank = GFC_DESCRIPTOR_RANK (array);
   if (rank <= 0)
@@ -66,19 +63,14 @@ findloc0_c4 (gfc_array_index_type * const restrict retarray,
                                "FINDLOC");
     }
 
-  dspacing = GFC_DESCRIPTOR_SPACING(retarray,0);
-  dest = retarray->base_addr;
-
   /* Set the return value.  */
   for (n = 0; n < rank; n++)
     GFC_DESCRIPTOR1_ELEM (index_type, retarray, n) = 0;
 
-  sz = sizeof (GFC_COMPLEX_4);
   for (n = 0; n < rank; n++)
     {
       sspacing[n] = GFC_DESCRIPTOR_SPACING(array,n);
       extent[n] = GFC_DESCRIPTOR_EXTENT(array,n);
-      sz *= extent[n];
       if (extent[n] <= 0)
        return;
     }
@@ -88,7 +80,9 @@ findloc0_c4 (gfc_array_index_type * const restrict retarray,
 
   if (back)
     {
-      base = (GFC_COMPLEX_4*) (((char*)array->base_addr) + (sz - 1));
+      base = array->base_addr;
+      for (n = 0; n < rank; n++)
+       base = (GFC_COMPLEX_4*) (((char*)base) + (extent[n] - 1) * sspacing[n]);
 
       while (1)
         {
@@ -178,14 +172,11 @@ mfindloc0_c4 (gfc_array_index_type * const restrict 
retarray,
   index_type extent[GFC_MAX_DIMENSIONS];
   index_type sspacing[GFC_MAX_DIMENSIONS];
   index_type mspacing[GFC_MAX_DIMENSIONS];
-  index_type dspacing;
   const GFC_COMPLEX_4 *base;
-  index_type * restrict dest;
   GFC_LOGICAL_1 *mbase;
   index_type rank;
   index_type n;
   int mask_kind;
-  index_type sz;
 
   rank = GFC_DESCRIPTOR_RANK (array);
   if (rank <= 0)
@@ -222,20 +213,15 @@ mfindloc0_c4 (gfc_array_index_type * const restrict 
retarray,
   else
     internal_error (NULL, "Funny sized logical array");
 
-  dspacing = GFC_DESCRIPTOR_SPACING(retarray,0);
-  dest = retarray->base_addr;
-
   /* Set the return value.  */
   for (n = 0; n < rank; n++)
     GFC_DESCRIPTOR1_ELEM (index_type, retarray, n) = 0;
 
-  sz = sizeof (GFC_COMPLEX_4);
   for (n = 0; n < rank; n++)
     {
       sspacing[n] = GFC_DESCRIPTOR_SPACING(array,n);
       mspacing[n] = GFC_DESCRIPTOR_SPACING(mask,n);
       extent[n] = GFC_DESCRIPTOR_EXTENT(array,n);
-      sz *= extent[n];
       if (extent[n] <= 0)
        return;
     }
@@ -245,8 +231,13 @@ mfindloc0_c4 (gfc_array_index_type * const restrict 
retarray,
 
   if (back)
     {
-      base = (GFC_COMPLEX_4*) (((char*)array->base_addr) + (sz - 1));
-      mbase = mbase + (sz - 1) * mask_kind;
+      base = array->base_addr;
+      for (n = 0; n < rank; n++)
+       {
+         base = (GFC_COMPLEX_4*) (((char*)base) + (extent[n] - 1) * 
sspacing[n]);
+         mbase = mbase + (extent[n] - 1) * mspacing[n];
+       }
+
       while (1)
         {
          do
@@ -338,8 +329,6 @@ sfindloc0_c4 (gfc_array_index_type * const restrict 
retarray,
            GFC_LOGICAL_4 * mask, GFC_LOGICAL_4 back)
 {
   index_type rank;
-  index_type dspacing;
-  index_type * restrict dest;
   index_type n;
 
   if (mask == NULL || *mask)
@@ -366,8 +355,6 @@ sfindloc0_c4 (gfc_array_index_type * const restrict 
retarray,
                               "FINDLOC");
     }
 
-  dspacing = GFC_DESCRIPTOR_SPACING(retarray,0);
-  dest = retarray->base_addr;
   for (n = 0; n<rank; n++)
     GFC_DESCRIPTOR1_ELEM (index_type, retarray, n) = 0 ;
 }
diff --git a/libgfortran/generated/findloc0_c8.c 
b/libgfortran/generated/findloc0_c8.c
index bb4569d42a65..2117c488e4b1 100644
--- a/libgfortran/generated/findloc0_c8.c
+++ b/libgfortran/generated/findloc0_c8.c
@@ -41,12 +41,9 @@ findloc0_c8 (gfc_array_index_type * const restrict retarray,
   index_type count[GFC_MAX_DIMENSIONS];
   index_type extent[GFC_MAX_DIMENSIONS];
   index_type sspacing[GFC_MAX_DIMENSIONS];
-  index_type dspacing;
   const GFC_COMPLEX_8 *base;
-  index_type * restrict dest;
   index_type rank;
   index_type n;
-  index_type sz;
 
   rank = GFC_DESCRIPTOR_RANK (array);
   if (rank <= 0)
@@ -66,19 +63,14 @@ findloc0_c8 (gfc_array_index_type * const restrict retarray,
                                "FINDLOC");
     }
 
-  dspacing = GFC_DESCRIPTOR_SPACING(retarray,0);
-  dest = retarray->base_addr;
-
   /* Set the return value.  */
   for (n = 0; n < rank; n++)
     GFC_DESCRIPTOR1_ELEM (index_type, retarray, n) = 0;
 
-  sz = sizeof (GFC_COMPLEX_8);
   for (n = 0; n < rank; n++)
     {
       sspacing[n] = GFC_DESCRIPTOR_SPACING(array,n);
       extent[n] = GFC_DESCRIPTOR_EXTENT(array,n);
-      sz *= extent[n];
       if (extent[n] <= 0)
        return;
     }
@@ -88,7 +80,9 @@ findloc0_c8 (gfc_array_index_type * const restrict retarray,
 
   if (back)
     {
-      base = (GFC_COMPLEX_8*) (((char*)array->base_addr) + (sz - 1));
+      base = array->base_addr;
+      for (n = 0; n < rank; n++)
+       base = (GFC_COMPLEX_8*) (((char*)base) + (extent[n] - 1) * sspacing[n]);
 
       while (1)
         {
@@ -178,14 +172,11 @@ mfindloc0_c8 (gfc_array_index_type * const restrict 
retarray,
   index_type extent[GFC_MAX_DIMENSIONS];
   index_type sspacing[GFC_MAX_DIMENSIONS];
   index_type mspacing[GFC_MAX_DIMENSIONS];
-  index_type dspacing;
   const GFC_COMPLEX_8 *base;
-  index_type * restrict dest;
   GFC_LOGICAL_1 *mbase;
   index_type rank;
   index_type n;
   int mask_kind;
-  index_type sz;
 
   rank = GFC_DESCRIPTOR_RANK (array);
   if (rank <= 0)
@@ -222,20 +213,15 @@ mfindloc0_c8 (gfc_array_index_type * const restrict 
retarray,
   else
     internal_error (NULL, "Funny sized logical array");
 
-  dspacing = GFC_DESCRIPTOR_SPACING(retarray,0);
-  dest = retarray->base_addr;
-
   /* Set the return value.  */
   for (n = 0; n < rank; n++)
     GFC_DESCRIPTOR1_ELEM (index_type, retarray, n) = 0;
 
-  sz = sizeof (GFC_COMPLEX_8);
   for (n = 0; n < rank; n++)
     {
       sspacing[n] = GFC_DESCRIPTOR_SPACING(array,n);
       mspacing[n] = GFC_DESCRIPTOR_SPACING(mask,n);
       extent[n] = GFC_DESCRIPTOR_EXTENT(array,n);
-      sz *= extent[n];
       if (extent[n] <= 0)
        return;
     }
@@ -245,8 +231,13 @@ mfindloc0_c8 (gfc_array_index_type * const restrict 
retarray,
 
   if (back)
     {
-      base = (GFC_COMPLEX_8*) (((char*)array->base_addr) + (sz - 1));
-      mbase = mbase + (sz - 1) * mask_kind;
+      base = array->base_addr;
+      for (n = 0; n < rank; n++)
+       {
+         base = (GFC_COMPLEX_8*) (((char*)base) + (extent[n] - 1) * 
sspacing[n]);
+         mbase = mbase + (extent[n] - 1) * mspacing[n];
+       }
+
       while (1)
         {
          do
@@ -338,8 +329,6 @@ sfindloc0_c8 (gfc_array_index_type * const restrict 
retarray,
            GFC_LOGICAL_4 * mask, GFC_LOGICAL_4 back)
 {
   index_type rank;
-  index_type dspacing;
-  index_type * restrict dest;
   index_type n;
 
   if (mask == NULL || *mask)
@@ -366,8 +355,6 @@ sfindloc0_c8 (gfc_array_index_type * const restrict 
retarray,
                               "FINDLOC");
     }
 
-  dspacing = GFC_DESCRIPTOR_SPACING(retarray,0);
-  dest = retarray->base_addr;
   for (n = 0; n<rank; n++)
     GFC_DESCRIPTOR1_ELEM (index_type, retarray, n) = 0 ;
 }
diff --git a/libgfortran/generated/findloc0_i1.c 
b/libgfortran/generated/findloc0_i1.c
index 52ad16eb7596..e9fc4368292e 100644
--- a/libgfortran/generated/findloc0_i1.c
+++ b/libgfortran/generated/findloc0_i1.c
@@ -41,12 +41,9 @@ findloc0_i1 (gfc_array_index_type * const restrict retarray,
   index_type count[GFC_MAX_DIMENSIONS];
   index_type extent[GFC_MAX_DIMENSIONS];
   index_type sspacing[GFC_MAX_DIMENSIONS];
-  index_type dspacing;
   const GFC_INTEGER_1 *base;
-  index_type * restrict dest;
   index_type rank;
   index_type n;
-  index_type sz;
 
   rank = GFC_DESCRIPTOR_RANK (array);
   if (rank <= 0)
@@ -66,19 +63,14 @@ findloc0_i1 (gfc_array_index_type * const restrict retarray,
                                "FINDLOC");
     }
 
-  dspacing = GFC_DESCRIPTOR_SPACING(retarray,0);
-  dest = retarray->base_addr;
-
   /* Set the return value.  */
   for (n = 0; n < rank; n++)
     GFC_DESCRIPTOR1_ELEM (index_type, retarray, n) = 0;
 
-  sz = sizeof (GFC_INTEGER_1);
   for (n = 0; n < rank; n++)
     {
       sspacing[n] = GFC_DESCRIPTOR_SPACING(array,n);
       extent[n] = GFC_DESCRIPTOR_EXTENT(array,n);
-      sz *= extent[n];
       if (extent[n] <= 0)
        return;
     }
@@ -88,7 +80,9 @@ findloc0_i1 (gfc_array_index_type * const restrict retarray,
 
   if (back)
     {
-      base = (GFC_INTEGER_1*) (((char*)array->base_addr) + (sz - 1));
+      base = array->base_addr;
+      for (n = 0; n < rank; n++)
+       base = (GFC_INTEGER_1*) (((char*)base) + (extent[n] - 1) * sspacing[n]);
 
       while (1)
         {
@@ -178,14 +172,11 @@ mfindloc0_i1 (gfc_array_index_type * const restrict 
retarray,
   index_type extent[GFC_MAX_DIMENSIONS];
   index_type sspacing[GFC_MAX_DIMENSIONS];
   index_type mspacing[GFC_MAX_DIMENSIONS];
-  index_type dspacing;
   const GFC_INTEGER_1 *base;
-  index_type * restrict dest;
   GFC_LOGICAL_1 *mbase;
   index_type rank;
   index_type n;
   int mask_kind;
-  index_type sz;
 
   rank = GFC_DESCRIPTOR_RANK (array);
   if (rank <= 0)
@@ -222,20 +213,15 @@ mfindloc0_i1 (gfc_array_index_type * const restrict 
retarray,
   else
     internal_error (NULL, "Funny sized logical array");
 
-  dspacing = GFC_DESCRIPTOR_SPACING(retarray,0);
-  dest = retarray->base_addr;
-
   /* Set the return value.  */
   for (n = 0; n < rank; n++)
     GFC_DESCRIPTOR1_ELEM (index_type, retarray, n) = 0;
 
-  sz = sizeof (GFC_INTEGER_1);
   for (n = 0; n < rank; n++)
     {
       sspacing[n] = GFC_DESCRIPTOR_SPACING(array,n);
       mspacing[n] = GFC_DESCRIPTOR_SPACING(mask,n);
       extent[n] = GFC_DESCRIPTOR_EXTENT(array,n);
-      sz *= extent[n];
       if (extent[n] <= 0)
        return;
     }
@@ -245,8 +231,13 @@ mfindloc0_i1 (gfc_array_index_type * const restrict 
retarray,
 
   if (back)
     {
-      base = (GFC_INTEGER_1*) (((char*)array->base_addr) + (sz - 1));
-      mbase = mbase + (sz - 1) * mask_kind;
+      base = array->base_addr;
+      for (n = 0; n < rank; n++)
+       {
+         base = (GFC_INTEGER_1*) (((char*)base) + (extent[n] - 1) * 
sspacing[n]);
+         mbase = mbase + (extent[n] - 1) * mspacing[n];
+       }
+
       while (1)
         {
          do
@@ -338,8 +329,6 @@ sfindloc0_i1 (gfc_array_index_type * const restrict 
retarray,
            GFC_LOGICAL_4 * mask, GFC_LOGICAL_4 back)
 {
   index_type rank;
-  index_type dspacing;
-  index_type * restrict dest;
   index_type n;
 
   if (mask == NULL || *mask)
@@ -366,8 +355,6 @@ sfindloc0_i1 (gfc_array_index_type * const restrict 
retarray,
                               "FINDLOC");
     }
 
-  dspacing = GFC_DESCRIPTOR_SPACING(retarray,0);
-  dest = retarray->base_addr;
   for (n = 0; n<rank; n++)
     GFC_DESCRIPTOR1_ELEM (index_type, retarray, n) = 0 ;
 }
diff --git a/libgfortran/generated/findloc0_i16.c 
b/libgfortran/generated/findloc0_i16.c
index 52c6eea9d791..b06cdf6439bb 100644
--- a/libgfortran/generated/findloc0_i16.c
+++ b/libgfortran/generated/findloc0_i16.c
@@ -41,12 +41,9 @@ findloc0_i16 (gfc_array_index_type * const restrict retarray,
   index_type count[GFC_MAX_DIMENSIONS];
   index_type extent[GFC_MAX_DIMENSIONS];
   index_type sspacing[GFC_MAX_DIMENSIONS];
-  index_type dspacing;
   const GFC_INTEGER_16 *base;
-  index_type * restrict dest;
   index_type rank;
   index_type n;
-  index_type sz;
 
   rank = GFC_DESCRIPTOR_RANK (array);
   if (rank <= 0)
@@ -66,19 +63,14 @@ findloc0_i16 (gfc_array_index_type * const restrict 
retarray,
                                "FINDLOC");
     }
 
-  dspacing = GFC_DESCRIPTOR_SPACING(retarray,0);
-  dest = retarray->base_addr;
-
   /* Set the return value.  */
   for (n = 0; n < rank; n++)
     GFC_DESCRIPTOR1_ELEM (index_type, retarray, n) = 0;
 
-  sz = sizeof (GFC_INTEGER_16);
   for (n = 0; n < rank; n++)
     {
       sspacing[n] = GFC_DESCRIPTOR_SPACING(array,n);
       extent[n] = GFC_DESCRIPTOR_EXTENT(array,n);
-      sz *= extent[n];
       if (extent[n] <= 0)
        return;
     }
@@ -88,7 +80,9 @@ findloc0_i16 (gfc_array_index_type * const restrict retarray,
 
   if (back)
     {
-      base = (GFC_INTEGER_16*) (((char*)array->base_addr) + (sz - 1));
+      base = array->base_addr;
+      for (n = 0; n < rank; n++)
+       base = (GFC_INTEGER_16*) (((char*)base) + (extent[n] - 1) * 
sspacing[n]);
 
       while (1)
         {
@@ -178,14 +172,11 @@ mfindloc0_i16 (gfc_array_index_type * const restrict 
retarray,
   index_type extent[GFC_MAX_DIMENSIONS];
   index_type sspacing[GFC_MAX_DIMENSIONS];
   index_type mspacing[GFC_MAX_DIMENSIONS];
-  index_type dspacing;
   const GFC_INTEGER_16 *base;
-  index_type * restrict dest;
   GFC_LOGICAL_1 *mbase;
   index_type rank;
   index_type n;
   int mask_kind;
-  index_type sz;
 
   rank = GFC_DESCRIPTOR_RANK (array);
   if (rank <= 0)
@@ -222,20 +213,15 @@ mfindloc0_i16 (gfc_array_index_type * const restrict 
retarray,
   else
     internal_error (NULL, "Funny sized logical array");
 
-  dspacing = GFC_DESCRIPTOR_SPACING(retarray,0);
-  dest = retarray->base_addr;
-
   /* Set the return value.  */
   for (n = 0; n < rank; n++)
     GFC_DESCRIPTOR1_ELEM (index_type, retarray, n) = 0;
 
-  sz = sizeof (GFC_INTEGER_16);
   for (n = 0; n < rank; n++)
     {
       sspacing[n] = GFC_DESCRIPTOR_SPACING(array,n);
       mspacing[n] = GFC_DESCRIPTOR_SPACING(mask,n);
       extent[n] = GFC_DESCRIPTOR_EXTENT(array,n);
-      sz *= extent[n];
       if (extent[n] <= 0)
        return;
     }
@@ -245,8 +231,13 @@ mfindloc0_i16 (gfc_array_index_type * const restrict 
retarray,
 
   if (back)
     {
-      base = (GFC_INTEGER_16*) (((char*)array->base_addr) + (sz - 1));
-      mbase = mbase + (sz - 1) * mask_kind;
+      base = array->base_addr;
+      for (n = 0; n < rank; n++)
+       {
+         base = (GFC_INTEGER_16*) (((char*)base) + (extent[n] - 1) * 
sspacing[n]);
+         mbase = mbase + (extent[n] - 1) * mspacing[n];
+       }
+
       while (1)
         {
          do
@@ -338,8 +329,6 @@ sfindloc0_i16 (gfc_array_index_type * const restrict 
retarray,
            GFC_LOGICAL_4 * mask, GFC_LOGICAL_4 back)
 {
   index_type rank;
-  index_type dspacing;
-  index_type * restrict dest;
   index_type n;
 
   if (mask == NULL || *mask)
@@ -366,8 +355,6 @@ sfindloc0_i16 (gfc_array_index_type * const restrict 
retarray,
                               "FINDLOC");
     }
 
-  dspacing = GFC_DESCRIPTOR_SPACING(retarray,0);
-  dest = retarray->base_addr;
   for (n = 0; n<rank; n++)
     GFC_DESCRIPTOR1_ELEM (index_type, retarray, n) = 0 ;
 }
diff --git a/libgfortran/generated/findloc0_i2.c 
b/libgfortran/generated/findloc0_i2.c
index b4c67b9112db..f98350c6e97b 100644
--- a/libgfortran/generated/findloc0_i2.c
+++ b/libgfortran/generated/findloc0_i2.c
@@ -41,12 +41,9 @@ findloc0_i2 (gfc_array_index_type * const restrict retarray,
   index_type count[GFC_MAX_DIMENSIONS];
   index_type extent[GFC_MAX_DIMENSIONS];
   index_type sspacing[GFC_MAX_DIMENSIONS];
-  index_type dspacing;
   const GFC_INTEGER_2 *base;
-  index_type * restrict dest;
   index_type rank;
   index_type n;
-  index_type sz;
 
   rank = GFC_DESCRIPTOR_RANK (array);
   if (rank <= 0)
@@ -66,19 +63,14 @@ findloc0_i2 (gfc_array_index_type * const restrict retarray,
                                "FINDLOC");
     }
 
-  dspacing = GFC_DESCRIPTOR_SPACING(retarray,0);
-  dest = retarray->base_addr;
-
   /* Set the return value.  */
   for (n = 0; n < rank; n++)
     GFC_DESCRIPTOR1_ELEM (index_type, retarray, n) = 0;
 
-  sz = sizeof (GFC_INTEGER_2);
   for (n = 0; n < rank; n++)
     {
       sspacing[n] = GFC_DESCRIPTOR_SPACING(array,n);
       extent[n] = GFC_DESCRIPTOR_EXTENT(array,n);
-      sz *= extent[n];
       if (extent[n] <= 0)
        return;
     }
@@ -88,7 +80,9 @@ findloc0_i2 (gfc_array_index_type * const restrict retarray,
 
   if (back)
     {
-      base = (GFC_INTEGER_2*) (((char*)array->base_addr) + (sz - 1));
+      base = array->base_addr;
+      for (n = 0; n < rank; n++)
+       base = (GFC_INTEGER_2*) (((char*)base) + (extent[n] - 1) * sspacing[n]);
 
       while (1)
         {
@@ -178,14 +172,11 @@ mfindloc0_i2 (gfc_array_index_type * const restrict 
retarray,
   index_type extent[GFC_MAX_DIMENSIONS];
   index_type sspacing[GFC_MAX_DIMENSIONS];
   index_type mspacing[GFC_MAX_DIMENSIONS];
-  index_type dspacing;
   const GFC_INTEGER_2 *base;
-  index_type * restrict dest;
   GFC_LOGICAL_1 *mbase;
   index_type rank;
   index_type n;
   int mask_kind;
-  index_type sz;
 
   rank = GFC_DESCRIPTOR_RANK (array);
   if (rank <= 0)
@@ -222,20 +213,15 @@ mfindloc0_i2 (gfc_array_index_type * const restrict 
retarray,
   else
     internal_error (NULL, "Funny sized logical array");
 
-  dspacing = GFC_DESCRIPTOR_SPACING(retarray,0);
-  dest = retarray->base_addr;
-
   /* Set the return value.  */
   for (n = 0; n < rank; n++)
     GFC_DESCRIPTOR1_ELEM (index_type, retarray, n) = 0;
 
-  sz = sizeof (GFC_INTEGER_2);
   for (n = 0; n < rank; n++)
     {
       sspacing[n] = GFC_DESCRIPTOR_SPACING(array,n);
       mspacing[n] = GFC_DESCRIPTOR_SPACING(mask,n);
       extent[n] = GFC_DESCRIPTOR_EXTENT(array,n);
-      sz *= extent[n];
       if (extent[n] <= 0)
        return;
     }
@@ -245,8 +231,13 @@ mfindloc0_i2 (gfc_array_index_type * const restrict 
retarray,
 
   if (back)
     {
-      base = (GFC_INTEGER_2*) (((char*)array->base_addr) + (sz - 1));
-      mbase = mbase + (sz - 1) * mask_kind;
+      base = array->base_addr;
+      for (n = 0; n < rank; n++)
+       {
+         base = (GFC_INTEGER_2*) (((char*)base) + (extent[n] - 1) * 
sspacing[n]);
+         mbase = mbase + (extent[n] - 1) * mspacing[n];
+       }
+
       while (1)
         {
          do
@@ -338,8 +329,6 @@ sfindloc0_i2 (gfc_array_index_type * const restrict 
retarray,
            GFC_LOGICAL_4 * mask, GFC_LOGICAL_4 back)
 {
   index_type rank;
-  index_type dspacing;
-  index_type * restrict dest;
   index_type n;
 
   if (mask == NULL || *mask)
@@ -366,8 +355,6 @@ sfindloc0_i2 (gfc_array_index_type * const restrict 
retarray,
                               "FINDLOC");
     }
 
-  dspacing = GFC_DESCRIPTOR_SPACING(retarray,0);
-  dest = retarray->base_addr;
   for (n = 0; n<rank; n++)
     GFC_DESCRIPTOR1_ELEM (index_type, retarray, n) = 0 ;
 }
diff --git a/libgfortran/generated/findloc0_i4.c 
b/libgfortran/generated/findloc0_i4.c
index 1a59cddeb7ad..fdfbd98636ec 100644
--- a/libgfortran/generated/findloc0_i4.c
+++ b/libgfortran/generated/findloc0_i4.c
@@ -41,12 +41,9 @@ findloc0_i4 (gfc_array_index_type * const restrict retarray,
   index_type count[GFC_MAX_DIMENSIONS];
   index_type extent[GFC_MAX_DIMENSIONS];
   index_type sspacing[GFC_MAX_DIMENSIONS];
-  index_type dspacing;
   const GFC_INTEGER_4 *base;
-  index_type * restrict dest;
   index_type rank;
   index_type n;
-  index_type sz;
 
   rank = GFC_DESCRIPTOR_RANK (array);
   if (rank <= 0)
@@ -66,19 +63,14 @@ findloc0_i4 (gfc_array_index_type * const restrict retarray,
                                "FINDLOC");
     }
 
-  dspacing = GFC_DESCRIPTOR_SPACING(retarray,0);
-  dest = retarray->base_addr;
-
   /* Set the return value.  */
   for (n = 0; n < rank; n++)
     GFC_DESCRIPTOR1_ELEM (index_type, retarray, n) = 0;
 
-  sz = sizeof (GFC_INTEGER_4);
   for (n = 0; n < rank; n++)
     {
       sspacing[n] = GFC_DESCRIPTOR_SPACING(array,n);
       extent[n] = GFC_DESCRIPTOR_EXTENT(array,n);
-      sz *= extent[n];
       if (extent[n] <= 0)
        return;
     }
@@ -88,7 +80,9 @@ findloc0_i4 (gfc_array_index_type * const restrict retarray,
 
   if (back)
     {
-      base = (GFC_INTEGER_4*) (((char*)array->base_addr) + (sz - 1));
+      base = array->base_addr;
+      for (n = 0; n < rank; n++)
+       base = (GFC_INTEGER_4*) (((char*)base) + (extent[n] - 1) * sspacing[n]);
 
       while (1)
         {
@@ -178,14 +172,11 @@ mfindloc0_i4 (gfc_array_index_type * const restrict 
retarray,
   index_type extent[GFC_MAX_DIMENSIONS];
   index_type sspacing[GFC_MAX_DIMENSIONS];
   index_type mspacing[GFC_MAX_DIMENSIONS];
-  index_type dspacing;
   const GFC_INTEGER_4 *base;
-  index_type * restrict dest;
   GFC_LOGICAL_1 *mbase;
   index_type rank;
   index_type n;
   int mask_kind;
-  index_type sz;
 
   rank = GFC_DESCRIPTOR_RANK (array);
   if (rank <= 0)
@@ -222,20 +213,15 @@ mfindloc0_i4 (gfc_array_index_type * const restrict 
retarray,
   else
     internal_error (NULL, "Funny sized logical array");
 
-  dspacing = GFC_DESCRIPTOR_SPACING(retarray,0);
-  dest = retarray->base_addr;
-
   /* Set the return value.  */
   for (n = 0; n < rank; n++)
     GFC_DESCRIPTOR1_ELEM (index_type, retarray, n) = 0;
 
-  sz = sizeof (GFC_INTEGER_4);
   for (n = 0; n < rank; n++)
     {
       sspacing[n] = GFC_DESCRIPTOR_SPACING(array,n);
       mspacing[n] = GFC_DESCRIPTOR_SPACING(mask,n);
       extent[n] = GFC_DESCRIPTOR_EXTENT(array,n);
-      sz *= extent[n];
       if (extent[n] <= 0)
        return;
     }
@@ -245,8 +231,13 @@ mfindloc0_i4 (gfc_array_index_type * const restrict 
retarray,
 
   if (back)
     {
-      base = (GFC_INTEGER_4*) (((char*)array->base_addr) + (sz - 1));
-      mbase = mbase + (sz - 1) * mask_kind;
+      base = array->base_addr;
+      for (n = 0; n < rank; n++)
+       {
+         base = (GFC_INTEGER_4*) (((char*)base) + (extent[n] - 1) * 
sspacing[n]);
+         mbase = mbase + (extent[n] - 1) * mspacing[n];
+       }
+
       while (1)
         {
          do
@@ -338,8 +329,6 @@ sfindloc0_i4 (gfc_array_index_type * const restrict 
retarray,
            GFC_LOGICAL_4 * mask, GFC_LOGICAL_4 back)
 {
   index_type rank;
-  index_type dspacing;
-  index_type * restrict dest;
   index_type n;
 
   if (mask == NULL || *mask)
@@ -366,8 +355,6 @@ sfindloc0_i4 (gfc_array_index_type * const restrict 
retarray,
                               "FINDLOC");
     }
 
-  dspacing = GFC_DESCRIPTOR_SPACING(retarray,0);
-  dest = retarray->base_addr;
   for (n = 0; n<rank; n++)
     GFC_DESCRIPTOR1_ELEM (index_type, retarray, n) = 0 ;
 }
diff --git a/libgfortran/generated/findloc0_i8.c 
b/libgfortran/generated/findloc0_i8.c
index f75388027c20..228b4ecd5942 100644
--- a/libgfortran/generated/findloc0_i8.c
+++ b/libgfortran/generated/findloc0_i8.c
@@ -41,12 +41,9 @@ findloc0_i8 (gfc_array_index_type * const restrict retarray,
   index_type count[GFC_MAX_DIMENSIONS];
   index_type extent[GFC_MAX_DIMENSIONS];
   index_type sspacing[GFC_MAX_DIMENSIONS];
-  index_type dspacing;
   const GFC_INTEGER_8 *base;
-  index_type * restrict dest;
   index_type rank;
   index_type n;
-  index_type sz;
 
   rank = GFC_DESCRIPTOR_RANK (array);
   if (rank <= 0)
@@ -66,19 +63,14 @@ findloc0_i8 (gfc_array_index_type * const restrict retarray,
                                "FINDLOC");
     }
 
-  dspacing = GFC_DESCRIPTOR_SPACING(retarray,0);
-  dest = retarray->base_addr;
-
   /* Set the return value.  */
   for (n = 0; n < rank; n++)
     GFC_DESCRIPTOR1_ELEM (index_type, retarray, n) = 0;
 
-  sz = sizeof (GFC_INTEGER_8);
   for (n = 0; n < rank; n++)
     {
       sspacing[n] = GFC_DESCRIPTOR_SPACING(array,n);
       extent[n] = GFC_DESCRIPTOR_EXTENT(array,n);
-      sz *= extent[n];
       if (extent[n] <= 0)
        return;
     }
@@ -88,7 +80,9 @@ findloc0_i8 (gfc_array_index_type * const restrict retarray,
 
   if (back)
     {
-      base = (GFC_INTEGER_8*) (((char*)array->base_addr) + (sz - 1));
+      base = array->base_addr;
+      for (n = 0; n < rank; n++)
+       base = (GFC_INTEGER_8*) (((char*)base) + (extent[n] - 1) * sspacing[n]);
 
       while (1)
         {
@@ -178,14 +172,11 @@ mfindloc0_i8 (gfc_array_index_type * const restrict 
retarray,
   index_type extent[GFC_MAX_DIMENSIONS];
   index_type sspacing[GFC_MAX_DIMENSIONS];
   index_type mspacing[GFC_MAX_DIMENSIONS];
-  index_type dspacing;
   const GFC_INTEGER_8 *base;
-  index_type * restrict dest;
   GFC_LOGICAL_1 *mbase;
   index_type rank;
   index_type n;
   int mask_kind;
-  index_type sz;
 
   rank = GFC_DESCRIPTOR_RANK (array);
   if (rank <= 0)
@@ -222,20 +213,15 @@ mfindloc0_i8 (gfc_array_index_type * const restrict 
retarray,
   else
     internal_error (NULL, "Funny sized logical array");
 
-  dspacing = GFC_DESCRIPTOR_SPACING(retarray,0);
-  dest = retarray->base_addr;
-
   /* Set the return value.  */
   for (n = 0; n < rank; n++)
     GFC_DESCRIPTOR1_ELEM (index_type, retarray, n) = 0;
 
-  sz = sizeof (GFC_INTEGER_8);
   for (n = 0; n < rank; n++)
     {
       sspacing[n] = GFC_DESCRIPTOR_SPACING(array,n);
       mspacing[n] = GFC_DESCRIPTOR_SPACING(mask,n);
       extent[n] = GFC_DESCRIPTOR_EXTENT(array,n);
-      sz *= extent[n];
       if (extent[n] <= 0)
        return;
     }
@@ -245,8 +231,13 @@ mfindloc0_i8 (gfc_array_index_type * const restrict 
retarray,
 
   if (back)
     {
-      base = (GFC_INTEGER_8*) (((char*)array->base_addr) + (sz - 1));
-      mbase = mbase + (sz - 1) * mask_kind;
+      base = array->base_addr;
+      for (n = 0; n < rank; n++)
+       {
+         base = (GFC_INTEGER_8*) (((char*)base) + (extent[n] - 1) * 
sspacing[n]);
+         mbase = mbase + (extent[n] - 1) * mspacing[n];
+       }
+
       while (1)
         {
          do
@@ -338,8 +329,6 @@ sfindloc0_i8 (gfc_array_index_type * const restrict 
retarray,
            GFC_LOGICAL_4 * mask, GFC_LOGICAL_4 back)
 {
   index_type rank;
-  index_type dspacing;
-  index_type * restrict dest;
   index_type n;
 
   if (mask == NULL || *mask)
@@ -366,8 +355,6 @@ sfindloc0_i8 (gfc_array_index_type * const restrict 
retarray,
                               "FINDLOC");
     }
 
-  dspacing = GFC_DESCRIPTOR_SPACING(retarray,0);
-  dest = retarray->base_addr;
   for (n = 0; n<rank; n++)
     GFC_DESCRIPTOR1_ELEM (index_type, retarray, n) = 0 ;
 }
diff --git a/libgfortran/generated/findloc0_r10.c 
b/libgfortran/generated/findloc0_r10.c
index 4d4219322996..8432265f5b29 100644
--- a/libgfortran/generated/findloc0_r10.c
+++ b/libgfortran/generated/findloc0_r10.c
@@ -41,12 +41,9 @@ findloc0_r10 (gfc_array_index_type * const restrict retarray,
   index_type count[GFC_MAX_DIMENSIONS];
   index_type extent[GFC_MAX_DIMENSIONS];
   index_type sspacing[GFC_MAX_DIMENSIONS];
-  index_type dspacing;
   const GFC_REAL_10 *base;
-  index_type * restrict dest;
   index_type rank;
   index_type n;
-  index_type sz;
 
   rank = GFC_DESCRIPTOR_RANK (array);
   if (rank <= 0)
@@ -66,19 +63,14 @@ findloc0_r10 (gfc_array_index_type * const restrict 
retarray,
                                "FINDLOC");
     }
 
-  dspacing = GFC_DESCRIPTOR_SPACING(retarray,0);
-  dest = retarray->base_addr;
-
   /* Set the return value.  */
   for (n = 0; n < rank; n++)
     GFC_DESCRIPTOR1_ELEM (index_type, retarray, n) = 0;
 
-  sz = sizeof (GFC_REAL_10);
   for (n = 0; n < rank; n++)
     {
       sspacing[n] = GFC_DESCRIPTOR_SPACING(array,n);
       extent[n] = GFC_DESCRIPTOR_EXTENT(array,n);
-      sz *= extent[n];
       if (extent[n] <= 0)
        return;
     }
@@ -88,7 +80,9 @@ findloc0_r10 (gfc_array_index_type * const restrict retarray,
 
   if (back)
     {
-      base = (GFC_REAL_10*) (((char*)array->base_addr) + (sz - 1));
+      base = array->base_addr;
+      for (n = 0; n < rank; n++)
+       base = (GFC_REAL_10*) (((char*)base) + (extent[n] - 1) * sspacing[n]);
 
       while (1)
         {
@@ -178,14 +172,11 @@ mfindloc0_r10 (gfc_array_index_type * const restrict 
retarray,
   index_type extent[GFC_MAX_DIMENSIONS];
   index_type sspacing[GFC_MAX_DIMENSIONS];
   index_type mspacing[GFC_MAX_DIMENSIONS];
-  index_type dspacing;
   const GFC_REAL_10 *base;
-  index_type * restrict dest;
   GFC_LOGICAL_1 *mbase;
   index_type rank;
   index_type n;
   int mask_kind;
-  index_type sz;
 
   rank = GFC_DESCRIPTOR_RANK (array);
   if (rank <= 0)
@@ -222,20 +213,15 @@ mfindloc0_r10 (gfc_array_index_type * const restrict 
retarray,
   else
     internal_error (NULL, "Funny sized logical array");
 
-  dspacing = GFC_DESCRIPTOR_SPACING(retarray,0);
-  dest = retarray->base_addr;
-
   /* Set the return value.  */
   for (n = 0; n < rank; n++)
     GFC_DESCRIPTOR1_ELEM (index_type, retarray, n) = 0;
 
-  sz = sizeof (GFC_REAL_10);
   for (n = 0; n < rank; n++)
     {
       sspacing[n] = GFC_DESCRIPTOR_SPACING(array,n);
       mspacing[n] = GFC_DESCRIPTOR_SPACING(mask,n);
       extent[n] = GFC_DESCRIPTOR_EXTENT(array,n);
-      sz *= extent[n];
       if (extent[n] <= 0)
        return;
     }
@@ -245,8 +231,13 @@ mfindloc0_r10 (gfc_array_index_type * const restrict 
retarray,
 
   if (back)
     {
-      base = (GFC_REAL_10*) (((char*)array->base_addr) + (sz - 1));
-      mbase = mbase + (sz - 1) * mask_kind;
+      base = array->base_addr;
+      for (n = 0; n < rank; n++)
+       {
+         base = (GFC_REAL_10*) (((char*)base) + (extent[n] - 1) * sspacing[n]);
+         mbase = mbase + (extent[n] - 1) * mspacing[n];
+       }
+
       while (1)
         {
          do
@@ -338,8 +329,6 @@ sfindloc0_r10 (gfc_array_index_type * const restrict 
retarray,
            GFC_LOGICAL_4 * mask, GFC_LOGICAL_4 back)
 {
   index_type rank;
-  index_type dspacing;
-  index_type * restrict dest;
   index_type n;
 
   if (mask == NULL || *mask)
@@ -366,8 +355,6 @@ sfindloc0_r10 (gfc_array_index_type * const restrict 
retarray,
                               "FINDLOC");
     }
 
-  dspacing = GFC_DESCRIPTOR_SPACING(retarray,0);
-  dest = retarray->base_addr;
   for (n = 0; n<rank; n++)
     GFC_DESCRIPTOR1_ELEM (index_type, retarray, n) = 0 ;
 }
diff --git a/libgfortran/generated/findloc0_r16.c 
b/libgfortran/generated/findloc0_r16.c
index 570011ecd1f9..39408dd05976 100644
--- a/libgfortran/generated/findloc0_r16.c
+++ b/libgfortran/generated/findloc0_r16.c
@@ -41,12 +41,9 @@ findloc0_r16 (gfc_array_index_type * const restrict retarray,
   index_type count[GFC_MAX_DIMENSIONS];
   index_type extent[GFC_MAX_DIMENSIONS];
   index_type sspacing[GFC_MAX_DIMENSIONS];
-  index_type dspacing;
   const GFC_REAL_16 *base;
-  index_type * restrict dest;
   index_type rank;
   index_type n;
-  index_type sz;
 
   rank = GFC_DESCRIPTOR_RANK (array);
   if (rank <= 0)
@@ -66,19 +63,14 @@ findloc0_r16 (gfc_array_index_type * const restrict 
retarray,
                                "FINDLOC");
     }
 
-  dspacing = GFC_DESCRIPTOR_SPACING(retarray,0);
-  dest = retarray->base_addr;
-
   /* Set the return value.  */
   for (n = 0; n < rank; n++)
     GFC_DESCRIPTOR1_ELEM (index_type, retarray, n) = 0;
 
-  sz = sizeof (GFC_REAL_16);
   for (n = 0; n < rank; n++)
     {
       sspacing[n] = GFC_DESCRIPTOR_SPACING(array,n);
       extent[n] = GFC_DESCRIPTOR_EXTENT(array,n);
-      sz *= extent[n];
       if (extent[n] <= 0)
        return;
     }
@@ -88,7 +80,9 @@ findloc0_r16 (gfc_array_index_type * const restrict retarray,
 
   if (back)
     {
-      base = (GFC_REAL_16*) (((char*)array->base_addr) + (sz - 1));
+      base = array->base_addr;
+      for (n = 0; n < rank; n++)
+       base = (GFC_REAL_16*) (((char*)base) + (extent[n] - 1) * sspacing[n]);
 
       while (1)
         {
@@ -178,14 +172,11 @@ mfindloc0_r16 (gfc_array_index_type * const restrict 
retarray,
   index_type extent[GFC_MAX_DIMENSIONS];
   index_type sspacing[GFC_MAX_DIMENSIONS];
   index_type mspacing[GFC_MAX_DIMENSIONS];
-  index_type dspacing;
   const GFC_REAL_16 *base;
-  index_type * restrict dest;
   GFC_LOGICAL_1 *mbase;
   index_type rank;
   index_type n;
   int mask_kind;
-  index_type sz;
 
   rank = GFC_DESCRIPTOR_RANK (array);
   if (rank <= 0)
@@ -222,20 +213,15 @@ mfindloc0_r16 (gfc_array_index_type * const restrict 
retarray,
   else
     internal_error (NULL, "Funny sized logical array");
 
-  dspacing = GFC_DESCRIPTOR_SPACING(retarray,0);
-  dest = retarray->base_addr;
-
   /* Set the return value.  */
   for (n = 0; n < rank; n++)
     GFC_DESCRIPTOR1_ELEM (index_type, retarray, n) = 0;
 
-  sz = sizeof (GFC_REAL_16);
   for (n = 0; n < rank; n++)
     {
       sspacing[n] = GFC_DESCRIPTOR_SPACING(array,n);
       mspacing[n] = GFC_DESCRIPTOR_SPACING(mask,n);
       extent[n] = GFC_DESCRIPTOR_EXTENT(array,n);
-      sz *= extent[n];
       if (extent[n] <= 0)
        return;
     }
@@ -245,8 +231,13 @@ mfindloc0_r16 (gfc_array_index_type * const restrict 
retarray,
 
   if (back)
     {
-      base = (GFC_REAL_16*) (((char*)array->base_addr) + (sz - 1));
-      mbase = mbase + (sz - 1) * mask_kind;
+      base = array->base_addr;
+      for (n = 0; n < rank; n++)
+       {
+         base = (GFC_REAL_16*) (((char*)base) + (extent[n] - 1) * sspacing[n]);
+         mbase = mbase + (extent[n] - 1) * mspacing[n];
+       }
+
       while (1)
         {
          do
@@ -338,8 +329,6 @@ sfindloc0_r16 (gfc_array_index_type * const restrict 
retarray,
            GFC_LOGICAL_4 * mask, GFC_LOGICAL_4 back)
 {
   index_type rank;
-  index_type dspacing;
-  index_type * restrict dest;
   index_type n;
 
   if (mask == NULL || *mask)
@@ -366,8 +355,6 @@ sfindloc0_r16 (gfc_array_index_type * const restrict 
retarray,
                               "FINDLOC");
     }
 
-  dspacing = GFC_DESCRIPTOR_SPACING(retarray,0);
-  dest = retarray->base_addr;
   for (n = 0; n<rank; n++)
     GFC_DESCRIPTOR1_ELEM (index_type, retarray, n) = 0 ;
 }
diff --git a/libgfortran/generated/findloc0_r17.c 
b/libgfortran/generated/findloc0_r17.c
index 607246546839..731a3d029b6d 100644
--- a/libgfortran/generated/findloc0_r17.c
+++ b/libgfortran/generated/findloc0_r17.c
@@ -41,12 +41,9 @@ findloc0_r17 (gfc_array_index_type * const restrict retarray,
   index_type count[GFC_MAX_DIMENSIONS];
   index_type extent[GFC_MAX_DIMENSIONS];
   index_type sspacing[GFC_MAX_DIMENSIONS];
-  index_type dspacing;
   const GFC_REAL_17 *base;
-  index_type * restrict dest;
   index_type rank;
   index_type n;
-  index_type sz;
 
   rank = GFC_DESCRIPTOR_RANK (array);
   if (rank <= 0)
@@ -66,19 +63,14 @@ findloc0_r17 (gfc_array_index_type * const restrict 
retarray,
                                "FINDLOC");
     }
 
-  dspacing = GFC_DESCRIPTOR_SPACING(retarray,0);
-  dest = retarray->base_addr;
-
   /* Set the return value.  */
   for (n = 0; n < rank; n++)
     GFC_DESCRIPTOR1_ELEM (index_type, retarray, n) = 0;
 
-  sz = sizeof (GFC_REAL_17);
   for (n = 0; n < rank; n++)
     {
       sspacing[n] = GFC_DESCRIPTOR_SPACING(array,n);
       extent[n] = GFC_DESCRIPTOR_EXTENT(array,n);
-      sz *= extent[n];
       if (extent[n] <= 0)
        return;
     }
@@ -88,7 +80,9 @@ findloc0_r17 (gfc_array_index_type * const restrict retarray,
 
   if (back)
     {
-      base = (GFC_REAL_17*) (((char*)array->base_addr) + (sz - 1));
+      base = array->base_addr;
+      for (n = 0; n < rank; n++)
+       base = (GFC_REAL_17*) (((char*)base) + (extent[n] - 1) * sspacing[n]);
 
       while (1)
         {
@@ -178,14 +172,11 @@ mfindloc0_r17 (gfc_array_index_type * const restrict 
retarray,
   index_type extent[GFC_MAX_DIMENSIONS];
   index_type sspacing[GFC_MAX_DIMENSIONS];
   index_type mspacing[GFC_MAX_DIMENSIONS];
-  index_type dspacing;
   const GFC_REAL_17 *base;
-  index_type * restrict dest;
   GFC_LOGICAL_1 *mbase;
   index_type rank;
   index_type n;
   int mask_kind;
-  index_type sz;
 
   rank = GFC_DESCRIPTOR_RANK (array);
   if (rank <= 0)
@@ -222,20 +213,15 @@ mfindloc0_r17 (gfc_array_index_type * const restrict 
retarray,
   else
     internal_error (NULL, "Funny sized logical array");
 
-  dspacing = GFC_DESCRIPTOR_SPACING(retarray,0);
-  dest = retarray->base_addr;
-
   /* Set the return value.  */
   for (n = 0; n < rank; n++)
     GFC_DESCRIPTOR1_ELEM (index_type, retarray, n) = 0;
 
-  sz = sizeof (GFC_REAL_17);
   for (n = 0; n < rank; n++)
     {
       sspacing[n] = GFC_DESCRIPTOR_SPACING(array,n);
       mspacing[n] = GFC_DESCRIPTOR_SPACING(mask,n);
       extent[n] = GFC_DESCRIPTOR_EXTENT(array,n);
-      sz *= extent[n];
       if (extent[n] <= 0)
        return;
     }
@@ -245,8 +231,13 @@ mfindloc0_r17 (gfc_array_index_type * const restrict 
retarray,
 
   if (back)
     {
-      base = (GFC_REAL_17*) (((char*)array->base_addr) + (sz - 1));
-      mbase = mbase + (sz - 1) * mask_kind;
+      base = array->base_addr;
+      for (n = 0; n < rank; n++)
+       {
+         base = (GFC_REAL_17*) (((char*)base) + (extent[n] - 1) * sspacing[n]);
+         mbase = mbase + (extent[n] - 1) * mspacing[n];
+       }
+
       while (1)
         {
          do
@@ -338,8 +329,6 @@ sfindloc0_r17 (gfc_array_index_type * const restrict 
retarray,
            GFC_LOGICAL_4 * mask, GFC_LOGICAL_4 back)
 {
   index_type rank;
-  index_type dspacing;
-  index_type * restrict dest;
   index_type n;
 
   if (mask == NULL || *mask)
@@ -366,8 +355,6 @@ sfindloc0_r17 (gfc_array_index_type * const restrict 
retarray,
                               "FINDLOC");
     }
 
-  dspacing = GFC_DESCRIPTOR_SPACING(retarray,0);
-  dest = retarray->base_addr;
   for (n = 0; n<rank; n++)
     GFC_DESCRIPTOR1_ELEM (index_type, retarray, n) = 0 ;
 }
diff --git a/libgfortran/generated/findloc0_r4.c 
b/libgfortran/generated/findloc0_r4.c
index 71276e665fc2..2e0d6a8f0346 100644
--- a/libgfortran/generated/findloc0_r4.c
+++ b/libgfortran/generated/findloc0_r4.c
@@ -41,12 +41,9 @@ findloc0_r4 (gfc_array_index_type * const restrict retarray,
   index_type count[GFC_MAX_DIMENSIONS];
   index_type extent[GFC_MAX_DIMENSIONS];
   index_type sspacing[GFC_MAX_DIMENSIONS];
-  index_type dspacing;
   const GFC_REAL_4 *base;
-  index_type * restrict dest;
   index_type rank;
   index_type n;
-  index_type sz;
 
   rank = GFC_DESCRIPTOR_RANK (array);
   if (rank <= 0)
@@ -66,19 +63,14 @@ findloc0_r4 (gfc_array_index_type * const restrict retarray,
                                "FINDLOC");
     }
 
-  dspacing = GFC_DESCRIPTOR_SPACING(retarray,0);
-  dest = retarray->base_addr;
-
   /* Set the return value.  */
   for (n = 0; n < rank; n++)
     GFC_DESCRIPTOR1_ELEM (index_type, retarray, n) = 0;
 
-  sz = sizeof (GFC_REAL_4);
   for (n = 0; n < rank; n++)
     {
       sspacing[n] = GFC_DESCRIPTOR_SPACING(array,n);
       extent[n] = GFC_DESCRIPTOR_EXTENT(array,n);
-      sz *= extent[n];
       if (extent[n] <= 0)
        return;
     }
@@ -88,7 +80,9 @@ findloc0_r4 (gfc_array_index_type * const restrict retarray,
 
   if (back)
     {
-      base = (GFC_REAL_4*) (((char*)array->base_addr) + (sz - 1));
+      base = array->base_addr;
+      for (n = 0; n < rank; n++)
+       base = (GFC_REAL_4*) (((char*)base) + (extent[n] - 1) * sspacing[n]);
 
       while (1)
         {
@@ -178,14 +172,11 @@ mfindloc0_r4 (gfc_array_index_type * const restrict 
retarray,
   index_type extent[GFC_MAX_DIMENSIONS];
   index_type sspacing[GFC_MAX_DIMENSIONS];
   index_type mspacing[GFC_MAX_DIMENSIONS];
-  index_type dspacing;
   const GFC_REAL_4 *base;
-  index_type * restrict dest;
   GFC_LOGICAL_1 *mbase;
   index_type rank;
   index_type n;
   int mask_kind;
-  index_type sz;
 
   rank = GFC_DESCRIPTOR_RANK (array);
   if (rank <= 0)
@@ -222,20 +213,15 @@ mfindloc0_r4 (gfc_array_index_type * const restrict 
retarray,
   else
     internal_error (NULL, "Funny sized logical array");
 
-  dspacing = GFC_DESCRIPTOR_SPACING(retarray,0);
-  dest = retarray->base_addr;
-
   /* Set the return value.  */
   for (n = 0; n < rank; n++)
     GFC_DESCRIPTOR1_ELEM (index_type, retarray, n) = 0;
 
-  sz = sizeof (GFC_REAL_4);
   for (n = 0; n < rank; n++)
     {
       sspacing[n] = GFC_DESCRIPTOR_SPACING(array,n);
       mspacing[n] = GFC_DESCRIPTOR_SPACING(mask,n);
       extent[n] = GFC_DESCRIPTOR_EXTENT(array,n);
-      sz *= extent[n];
       if (extent[n] <= 0)
        return;
     }
@@ -245,8 +231,13 @@ mfindloc0_r4 (gfc_array_index_type * const restrict 
retarray,
 
   if (back)
     {
-      base = (GFC_REAL_4*) (((char*)array->base_addr) + (sz - 1));
-      mbase = mbase + (sz - 1) * mask_kind;
+      base = array->base_addr;
+      for (n = 0; n < rank; n++)
+       {
+         base = (GFC_REAL_4*) (((char*)base) + (extent[n] - 1) * sspacing[n]);
+         mbase = mbase + (extent[n] - 1) * mspacing[n];
+       }
+
       while (1)
         {
          do
@@ -338,8 +329,6 @@ sfindloc0_r4 (gfc_array_index_type * const restrict 
retarray,
            GFC_LOGICAL_4 * mask, GFC_LOGICAL_4 back)
 {
   index_type rank;
-  index_type dspacing;
-  index_type * restrict dest;
   index_type n;
 
   if (mask == NULL || *mask)
@@ -366,8 +355,6 @@ sfindloc0_r4 (gfc_array_index_type * const restrict 
retarray,
                               "FINDLOC");
     }
 
-  dspacing = GFC_DESCRIPTOR_SPACING(retarray,0);
-  dest = retarray->base_addr;
   for (n = 0; n<rank; n++)
     GFC_DESCRIPTOR1_ELEM (index_type, retarray, n) = 0 ;
 }
diff --git a/libgfortran/generated/findloc0_r8.c 
b/libgfortran/generated/findloc0_r8.c
index 692ff6380bf2..a650d21a3758 100644
--- a/libgfortran/generated/findloc0_r8.c
+++ b/libgfortran/generated/findloc0_r8.c
@@ -41,12 +41,9 @@ findloc0_r8 (gfc_array_index_type * const restrict retarray,
   index_type count[GFC_MAX_DIMENSIONS];
   index_type extent[GFC_MAX_DIMENSIONS];
   index_type sspacing[GFC_MAX_DIMENSIONS];
-  index_type dspacing;
   const GFC_REAL_8 *base;
-  index_type * restrict dest;
   index_type rank;
   index_type n;
-  index_type sz;
 
   rank = GFC_DESCRIPTOR_RANK (array);
   if (rank <= 0)
@@ -66,19 +63,14 @@ findloc0_r8 (gfc_array_index_type * const restrict retarray,
                                "FINDLOC");
     }
 
-  dspacing = GFC_DESCRIPTOR_SPACING(retarray,0);
-  dest = retarray->base_addr;
-
   /* Set the return value.  */
   for (n = 0; n < rank; n++)
     GFC_DESCRIPTOR1_ELEM (index_type, retarray, n) = 0;
 
-  sz = sizeof (GFC_REAL_8);
   for (n = 0; n < rank; n++)
     {
       sspacing[n] = GFC_DESCRIPTOR_SPACING(array,n);
       extent[n] = GFC_DESCRIPTOR_EXTENT(array,n);
-      sz *= extent[n];
       if (extent[n] <= 0)
        return;
     }
@@ -88,7 +80,9 @@ findloc0_r8 (gfc_array_index_type * const restrict retarray,
 
   if (back)
     {
-      base = (GFC_REAL_8*) (((char*)array->base_addr) + (sz - 1));
+      base = array->base_addr;
+      for (n = 0; n < rank; n++)
+       base = (GFC_REAL_8*) (((char*)base) + (extent[n] - 1) * sspacing[n]);
 
       while (1)
         {
@@ -178,14 +172,11 @@ mfindloc0_r8 (gfc_array_index_type * const restrict 
retarray,
   index_type extent[GFC_MAX_DIMENSIONS];
   index_type sspacing[GFC_MAX_DIMENSIONS];
   index_type mspacing[GFC_MAX_DIMENSIONS];
-  index_type dspacing;
   const GFC_REAL_8 *base;
-  index_type * restrict dest;
   GFC_LOGICAL_1 *mbase;
   index_type rank;
   index_type n;
   int mask_kind;
-  index_type sz;
 
   rank = GFC_DESCRIPTOR_RANK (array);
   if (rank <= 0)
@@ -222,20 +213,15 @@ mfindloc0_r8 (gfc_array_index_type * const restrict 
retarray,
   else
     internal_error (NULL, "Funny sized logical array");
 
-  dspacing = GFC_DESCRIPTOR_SPACING(retarray,0);
-  dest = retarray->base_addr;
-
   /* Set the return value.  */
   for (n = 0; n < rank; n++)
     GFC_DESCRIPTOR1_ELEM (index_type, retarray, n) = 0;
 
-  sz = sizeof (GFC_REAL_8);
   for (n = 0; n < rank; n++)
     {
       sspacing[n] = GFC_DESCRIPTOR_SPACING(array,n);
       mspacing[n] = GFC_DESCRIPTOR_SPACING(mask,n);
       extent[n] = GFC_DESCRIPTOR_EXTENT(array,n);
-      sz *= extent[n];
       if (extent[n] <= 0)
        return;
     }
@@ -245,8 +231,13 @@ mfindloc0_r8 (gfc_array_index_type * const restrict 
retarray,
 
   if (back)
     {
-      base = (GFC_REAL_8*) (((char*)array->base_addr) + (sz - 1));
-      mbase = mbase + (sz - 1) * mask_kind;
+      base = array->base_addr;
+      for (n = 0; n < rank; n++)
+       {
+         base = (GFC_REAL_8*) (((char*)base) + (extent[n] - 1) * sspacing[n]);
+         mbase = mbase + (extent[n] - 1) * mspacing[n];
+       }
+
       while (1)
         {
          do
@@ -338,8 +329,6 @@ sfindloc0_r8 (gfc_array_index_type * const restrict 
retarray,
            GFC_LOGICAL_4 * mask, GFC_LOGICAL_4 back)
 {
   index_type rank;
-  index_type dspacing;
-  index_type * restrict dest;
   index_type n;
 
   if (mask == NULL || *mask)
@@ -366,8 +355,6 @@ sfindloc0_r8 (gfc_array_index_type * const restrict 
retarray,
                               "FINDLOC");
     }
 
-  dspacing = GFC_DESCRIPTOR_SPACING(retarray,0);
-  dest = retarray->base_addr;
   for (n = 0; n<rank; n++)
     GFC_DESCRIPTOR1_ELEM (index_type, retarray, n) = 0 ;
 }
diff --git a/libgfortran/generated/findloc0_s1.c 
b/libgfortran/generated/findloc0_s1.c
index d2af2bfbc697..8acc9edfd52f 100644
--- a/libgfortran/generated/findloc0_s1.c
+++ b/libgfortran/generated/findloc0_s1.c
@@ -42,12 +42,9 @@ findloc0_s1 (gfc_array_index_type * const restrict retarray,
   index_type count[GFC_MAX_DIMENSIONS];
   index_type extent[GFC_MAX_DIMENSIONS];
   index_type sspacing[GFC_MAX_DIMENSIONS];
-  index_type dspacing;
   const GFC_UINTEGER_1 *base;
-  index_type * restrict dest;
   index_type rank;
   index_type n;
-  index_type sz;
 
   rank = GFC_DESCRIPTOR_RANK (array);
   if (rank <= 0)
@@ -67,19 +64,14 @@ findloc0_s1 (gfc_array_index_type * const restrict retarray,
                                "FINDLOC");
     }
 
-  dspacing = GFC_DESCRIPTOR_SPACING(retarray,0);
-  dest = retarray->base_addr;
-
   /* Set the return value.  */
   for (n = 0; n < rank; n++)
     GFC_DESCRIPTOR1_ELEM (index_type, retarray, n) = 0;
 
-  sz = sizeof (GFC_UINTEGER_1);
   for (n = 0; n < rank; n++)
     {
       sspacing[n] = GFC_DESCRIPTOR_SPACING(array,n);
       extent[n] = GFC_DESCRIPTOR_EXTENT(array,n);
-      sz *= extent[n];
       if (extent[n] <= 0)
        return;
     }
@@ -89,7 +81,9 @@ findloc0_s1 (gfc_array_index_type * const restrict retarray,
 
   if (back)
     {
-      base = (GFC_UINTEGER_1*) (((char*)array->base_addr) + (sz - 1));
+      base = array->base_addr;
+      for (n = 0; n < rank; n++)
+       base = (GFC_UINTEGER_1*) (((char*)base) + (extent[n] - 1) * 
sspacing[n]);
 
       while (1)
         {
@@ -181,14 +175,11 @@ mfindloc0_s1 (gfc_array_index_type * const restrict 
retarray,
   index_type extent[GFC_MAX_DIMENSIONS];
   index_type sspacing[GFC_MAX_DIMENSIONS];
   index_type mspacing[GFC_MAX_DIMENSIONS];
-  index_type dspacing;
   const GFC_UINTEGER_1 *base;
-  index_type * restrict dest;
   GFC_LOGICAL_1 *mbase;
   index_type rank;
   index_type n;
   int mask_kind;
-  index_type sz;
 
   rank = GFC_DESCRIPTOR_RANK (array);
   if (rank <= 0)
@@ -225,20 +216,15 @@ mfindloc0_s1 (gfc_array_index_type * const restrict 
retarray,
   else
     internal_error (NULL, "Funny sized logical array");
 
-  dspacing = GFC_DESCRIPTOR_SPACING(retarray,0);
-  dest = retarray->base_addr;
-
   /* Set the return value.  */
   for (n = 0; n < rank; n++)
     GFC_DESCRIPTOR1_ELEM (index_type, retarray, n) = 0;
 
-  sz = sizeof (GFC_UINTEGER_1);
   for (n = 0; n < rank; n++)
     {
       sspacing[n] = GFC_DESCRIPTOR_SPACING(array,n);
       mspacing[n] = GFC_DESCRIPTOR_SPACING(mask,n);
       extent[n] = GFC_DESCRIPTOR_EXTENT(array,n);
-      sz *= extent[n];
       if (extent[n] <= 0)
        return;
     }
@@ -248,8 +234,13 @@ mfindloc0_s1 (gfc_array_index_type * const restrict 
retarray,
 
   if (back)
     {
-      base = (GFC_UINTEGER_1*) (((char*)array->base_addr) + (sz - 1));
-      mbase = mbase + (sz - 1) * mask_kind;
+      base = array->base_addr;
+      for (n = 0; n < rank; n++)
+       {
+         base = (GFC_UINTEGER_1*) (((char*)base) + (extent[n] - 1) * 
sspacing[n]);
+         mbase = mbase + (extent[n] - 1) * mspacing[n];
+       }
+
       while (1)
         {
          do
@@ -343,8 +334,6 @@ sfindloc0_s1 (gfc_array_index_type * const restrict 
retarray,
            gfc_charlen_type len_value)
 {
   index_type rank;
-  index_type dspacing;
-  index_type * restrict dest;
   index_type n;
 
   if (mask == NULL || *mask)
@@ -371,8 +360,6 @@ sfindloc0_s1 (gfc_array_index_type * const restrict 
retarray,
                               "FINDLOC");
     }
 
-  dspacing = GFC_DESCRIPTOR_SPACING(retarray,0);
-  dest = retarray->base_addr;
   for (n = 0; n<rank; n++)
     GFC_DESCRIPTOR1_ELEM (index_type, retarray, n) = 0 ;
 }
diff --git a/libgfortran/generated/findloc0_s4.c 
b/libgfortran/generated/findloc0_s4.c
index e98e06ebe86d..520ee21e3f65 100644
--- a/libgfortran/generated/findloc0_s4.c
+++ b/libgfortran/generated/findloc0_s4.c
@@ -42,12 +42,9 @@ findloc0_s4 (gfc_array_index_type * const restrict retarray,
   index_type count[GFC_MAX_DIMENSIONS];
   index_type extent[GFC_MAX_DIMENSIONS];
   index_type sspacing[GFC_MAX_DIMENSIONS];
-  index_type dspacing;
   const GFC_UINTEGER_4 *base;
-  index_type * restrict dest;
   index_type rank;
   index_type n;
-  index_type sz;
 
   rank = GFC_DESCRIPTOR_RANK (array);
   if (rank <= 0)
@@ -67,19 +64,14 @@ findloc0_s4 (gfc_array_index_type * const restrict retarray,
                                "FINDLOC");
     }
 
-  dspacing = GFC_DESCRIPTOR_SPACING(retarray,0);
-  dest = retarray->base_addr;
-
   /* Set the return value.  */
   for (n = 0; n < rank; n++)
     GFC_DESCRIPTOR1_ELEM (index_type, retarray, n) = 0;
 
-  sz = sizeof (GFC_UINTEGER_4);
   for (n = 0; n < rank; n++)
     {
       sspacing[n] = GFC_DESCRIPTOR_SPACING(array,n);
       extent[n] = GFC_DESCRIPTOR_EXTENT(array,n);
-      sz *= extent[n];
       if (extent[n] <= 0)
        return;
     }
@@ -89,7 +81,9 @@ findloc0_s4 (gfc_array_index_type * const restrict retarray,
 
   if (back)
     {
-      base = (GFC_UINTEGER_4*) (((char*)array->base_addr) + (sz - 1));
+      base = array->base_addr;
+      for (n = 0; n < rank; n++)
+       base = (GFC_UINTEGER_4*) (((char*)base) + (extent[n] - 1) * 
sspacing[n]);
 
       while (1)
         {
@@ -181,14 +175,11 @@ mfindloc0_s4 (gfc_array_index_type * const restrict 
retarray,
   index_type extent[GFC_MAX_DIMENSIONS];
   index_type sspacing[GFC_MAX_DIMENSIONS];
   index_type mspacing[GFC_MAX_DIMENSIONS];
-  index_type dspacing;
   const GFC_UINTEGER_4 *base;
-  index_type * restrict dest;
   GFC_LOGICAL_1 *mbase;
   index_type rank;
   index_type n;
   int mask_kind;
-  index_type sz;
 
   rank = GFC_DESCRIPTOR_RANK (array);
   if (rank <= 0)
@@ -225,20 +216,15 @@ mfindloc0_s4 (gfc_array_index_type * const restrict 
retarray,
   else
     internal_error (NULL, "Funny sized logical array");
 
-  dspacing = GFC_DESCRIPTOR_SPACING(retarray,0);
-  dest = retarray->base_addr;
-
   /* Set the return value.  */
   for (n = 0; n < rank; n++)
     GFC_DESCRIPTOR1_ELEM (index_type, retarray, n) = 0;
 
-  sz = sizeof (GFC_UINTEGER_4);
   for (n = 0; n < rank; n++)
     {
       sspacing[n] = GFC_DESCRIPTOR_SPACING(array,n);
       mspacing[n] = GFC_DESCRIPTOR_SPACING(mask,n);
       extent[n] = GFC_DESCRIPTOR_EXTENT(array,n);
-      sz *= extent[n];
       if (extent[n] <= 0)
        return;
     }
@@ -248,8 +234,13 @@ mfindloc0_s4 (gfc_array_index_type * const restrict 
retarray,
 
   if (back)
     {
-      base = (GFC_UINTEGER_4*) (((char*)array->base_addr) + (sz - 1));
-      mbase = mbase + (sz - 1) * mask_kind;
+      base = array->base_addr;
+      for (n = 0; n < rank; n++)
+       {
+         base = (GFC_UINTEGER_4*) (((char*)base) + (extent[n] - 1) * 
sspacing[n]);
+         mbase = mbase + (extent[n] - 1) * mspacing[n];
+       }
+
       while (1)
         {
          do
@@ -343,8 +334,6 @@ sfindloc0_s4 (gfc_array_index_type * const restrict 
retarray,
            gfc_charlen_type len_value)
 {
   index_type rank;
-  index_type dspacing;
-  index_type * restrict dest;
   index_type n;
 
   if (mask == NULL || *mask)
@@ -371,8 +360,6 @@ sfindloc0_s4 (gfc_array_index_type * const restrict 
retarray,
                               "FINDLOC");
     }
 
-  dspacing = GFC_DESCRIPTOR_SPACING(retarray,0);
-  dest = retarray->base_addr;
   for (n = 0; n<rank; n++)
     GFC_DESCRIPTOR1_ELEM (index_type, retarray, n) = 0 ;
 }
diff --git a/libgfortran/m4/ifindloc0.m4 b/libgfortran/m4/ifindloc0.m4
index 52603528aa1f..fb98e25a7d7f 100644
--- a/libgfortran/m4/ifindloc0.m4
+++ b/libgfortran/m4/ifindloc0.m4
@@ -32,12 +32,9 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If 
not, see
   index_type count[GFC_MAX_DIMENSIONS];
   index_type extent[GFC_MAX_DIMENSIONS];
   index_type sspacing[GFC_MAX_DIMENSIONS];
-  index_type dspacing;
   const 'atype_name` *base;
-  index_type * restrict dest;
   index_type rank;
   index_type n;
-  index_type sz;
 
   rank = GFC_DESCRIPTOR_RANK (array);
   if (rank <= 0)
@@ -57,19 +54,14 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  
If not, see
                                "FINDLOC");
     }
 
-  dspacing = GFC_DESCRIPTOR_SPACING(retarray,0);
-  dest = retarray->base_addr;
-
   /* Set the return value.  */
   for (n = 0; n < rank; n++)
     GFC_DESCRIPTOR1_ELEM (index_type, retarray, n) = 0;
 
-  sz = sizeof ('atype_name`);
   for (n = 0; n < rank; n++)
     {
       sspacing[n] = GFC_DESCRIPTOR_SPACING(array,n);
       extent[n] = GFC_DESCRIPTOR_EXTENT(array,n);
-      sz *= extent[n];
       if (extent[n] <= 0)
        return;
     }
@@ -79,7 +71,9 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If 
not, see
 
   if (back)
     {
-      base = ('atype_name`*) (((char*)array->base_addr) + (sz - 1));
+      base = array->base_addr;
+      for (n = 0; n < rank; n++)
+       base = ('atype_name`*) (((char*)base) + (extent[n] - 1) * sspacing[n]);
 
       while (1)
         {
@@ -161,14 +155,11 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  
If not, see
   index_type extent[GFC_MAX_DIMENSIONS];
   index_type sspacing[GFC_MAX_DIMENSIONS];
   index_type mspacing[GFC_MAX_DIMENSIONS];
-  index_type dspacing;
   const 'atype_name` *base;
-  index_type * restrict dest;
   GFC_LOGICAL_1 *mbase;
   index_type rank;
   index_type n;
   int mask_kind;
-  index_type sz;
 
   rank = GFC_DESCRIPTOR_RANK (array);
   if (rank <= 0)
@@ -205,20 +196,15 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  
If not, see
   else
     internal_error (NULL, "Funny sized logical array");
 
-  dspacing = GFC_DESCRIPTOR_SPACING(retarray,0);
-  dest = retarray->base_addr;
-
   /* Set the return value.  */
   for (n = 0; n < rank; n++)
     GFC_DESCRIPTOR1_ELEM (index_type, retarray, n) = 0;
 
-  sz = sizeof ('atype_name`);
   for (n = 0; n < rank; n++)
     {
       sspacing[n] = GFC_DESCRIPTOR_SPACING(array,n);
       mspacing[n] = GFC_DESCRIPTOR_SPACING(mask,n);
       extent[n] = GFC_DESCRIPTOR_EXTENT(array,n);
-      sz *= extent[n];
       if (extent[n] <= 0)
        return;
     }
@@ -228,8 +214,13 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  
If not, see
 
   if (back)
     {
-      base = ('atype_name`*) (((char*)array->base_addr) + (sz - 1));
-      mbase = mbase + (sz - 1) * mask_kind;
+      base = array->base_addr;
+      for (n = 0; n < rank; n++)
+       {
+         base = ('atype_name`*) (((char*)base) + (extent[n] - 1) * 
sspacing[n]);
+         mbase = mbase + (extent[n] - 1) * mspacing[n];
+       }
+
       while (1)
         {
          do
@@ -313,8 +304,6 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  
If not, see
 'header3`
 {
   index_type rank;
-  index_type dspacing;
-  index_type * restrict dest;
   index_type n;
 
   if (mask == NULL || *mask)
@@ -341,8 +330,6 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  
If not, see
                               "FINDLOC");
     }
 
-  dspacing = GFC_DESCRIPTOR_SPACING(retarray,0);
-  dest = retarray->base_addr;
   for (n = 0; n<rank; n++)
     GFC_DESCRIPTOR1_ELEM (index_type, retarray, n) = 0 ;
 }

Reply via email to