Dear all,

the attached patch simply implements the 1-line bugfix for the
described situation that Federico pointed out in the PR, as
well as adjusts his testcase for the testsuite.

I did some whitespace consistency cleanup in the affected m4 files.

Regtested on x86_64-pc-linux-gnu.  OK for mainline?

This affects all versions prior to 15 even with optimization.
Starting with 15 MINLOC/MAXLOC may get inlined with optimization.
Is a backport desired?

Cheers,
Harald

From ff80af8bf915fbc3bbbbda7eef3300e11b278b91 Mon Sep 17 00:00:00 2001
From: Harald Anlauf <[email protected]>
Date: Tue, 13 Oct 2026 20:46:28 +0200
Subject: [PATCH] fortran: Fix MINLOC/MAXLOC with MASK and BACK=.true.
 [PR127846]

The runtime library templates for MINLOC/MAXLOC did not advance properly
through the array argument when MASK was present and BACK was .true. .

Co-authored-by: Federico Perini <[email protected]>

	PR fortran/127846

libgfortran/ChangeLog:

	* generated/maxloc0_16_i1.c (mmaxloc0_16_i1): Regenerate.
	* generated/maxloc0_16_i16.c (mmaxloc0_16_i16): Likewise.
	* generated/maxloc0_16_i2.c (mmaxloc0_16_i2): Likewise.
	* generated/maxloc0_16_i4.c (mmaxloc0_16_i4): Likewise.
	* generated/maxloc0_16_i8.c (mmaxloc0_16_i8): Likewise.
	* generated/maxloc0_16_m1.c (mmaxloc0_16_m1): Likewise.
	* generated/maxloc0_16_m16.c (mmaxloc0_16_m16): Likewise.
	* generated/maxloc0_16_m2.c (mmaxloc0_16_m2): Likewise.
	* generated/maxloc0_16_m4.c (mmaxloc0_16_m4): Likewise.
	* generated/maxloc0_16_m8.c (mmaxloc0_16_m8): Likewise.
	* generated/maxloc0_16_r10.c (mmaxloc0_16_r10): Likewise.
	* generated/maxloc0_16_r16.c (mmaxloc0_16_r16): Likewise.
	* generated/maxloc0_16_r17.c (mmaxloc0_16_r17): Likewise.
	* generated/maxloc0_16_r4.c (mmaxloc0_16_r4): Likewise.
	* generated/maxloc0_16_r8.c (mmaxloc0_16_r8): Likewise.
	* generated/maxloc0_4_i1.c (mmaxloc0_4_i1): Likewise.
	* generated/maxloc0_4_i16.c (mmaxloc0_4_i16): Likewise.
	* generated/maxloc0_4_i2.c (mmaxloc0_4_i2): Likewise.
	* generated/maxloc0_4_i4.c (mmaxloc0_4_i4): Likewise.
	* generated/maxloc0_4_i8.c (mmaxloc0_4_i8): Likewise.
	* generated/maxloc0_4_m1.c (mmaxloc0_4_m1): Likewise.
	* generated/maxloc0_4_m16.c (mmaxloc0_4_m16): Likewise.
	* generated/maxloc0_4_m2.c (mmaxloc0_4_m2): Likewise.
	* generated/maxloc0_4_m4.c (mmaxloc0_4_m4): Likewise.
	* generated/maxloc0_4_m8.c (mmaxloc0_4_m8): Likewise.
	* generated/maxloc0_4_r10.c (mmaxloc0_4_r10): Likewise.
	* generated/maxloc0_4_r16.c (mmaxloc0_4_r16): Likewise.
	* generated/maxloc0_4_r17.c (mmaxloc0_4_r17): Likewise.
	* generated/maxloc0_4_r4.c (mmaxloc0_4_r4): Likewise.
	* generated/maxloc0_4_r8.c (mmaxloc0_4_r8): Likewise.
	* generated/maxloc0_8_i1.c (mmaxloc0_8_i1): Likewise.
	* generated/maxloc0_8_i16.c (mmaxloc0_8_i16): Likewise.
	* generated/maxloc0_8_i2.c (mmaxloc0_8_i2): Likewise.
	* generated/maxloc0_8_i4.c (mmaxloc0_8_i4): Likewise.
	* generated/maxloc0_8_i8.c (mmaxloc0_8_i8): Likewise.
	* generated/maxloc0_8_m1.c (mmaxloc0_8_m1): Likewise.
	* generated/maxloc0_8_m16.c (mmaxloc0_8_m16): Likewise.
	* generated/maxloc0_8_m2.c (mmaxloc0_8_m2): Likewise.
	* generated/maxloc0_8_m4.c (mmaxloc0_8_m4): Likewise.
	* generated/maxloc0_8_m8.c (mmaxloc0_8_m8): Likewise.
	* generated/maxloc0_8_r10.c (mmaxloc0_8_r10): Likewise.
	* generated/maxloc0_8_r16.c (mmaxloc0_8_r16): Likewise.
	* generated/maxloc0_8_r17.c (mmaxloc0_8_r17): Likewise.
	* generated/maxloc0_8_r4.c (mmaxloc0_8_r4): Likewise.
	* generated/maxloc0_8_r8.c (mmaxloc0_8_r8): Likewise.
	* generated/minloc0_16_i1.c (mminloc0_16_i1): Likewise.
	* generated/minloc0_16_i16.c (mminloc0_16_i16): Likewise.
	* generated/minloc0_16_i2.c (mminloc0_16_i2): Likewise.
	* generated/minloc0_16_i4.c (mminloc0_16_i4): Likewise.
	* generated/minloc0_16_i8.c (mminloc0_16_i8): Likewise.
	* generated/minloc0_16_m1.c (mminloc0_16_m1): Likewise.
	* generated/minloc0_16_m16.c (mminloc0_16_m16): Likewise.
	* generated/minloc0_16_m2.c (mminloc0_16_m2): Likewise.
	* generated/minloc0_16_m4.c (mminloc0_16_m4): Likewise.
	* generated/minloc0_16_m8.c (mminloc0_16_m8): Likewise.
	* generated/minloc0_16_r10.c (mminloc0_16_r10): Likewise.
	* generated/minloc0_16_r16.c (mminloc0_16_r16): Likewise.
	* generated/minloc0_16_r17.c (mminloc0_16_r17): Likewise.
	* generated/minloc0_16_r4.c (mminloc0_16_r4): Likewise.
	* generated/minloc0_16_r8.c (mminloc0_16_r8): Likewise.
	* generated/minloc0_4_i1.c (mminloc0_4_i1): Likewise.
	* generated/minloc0_4_i16.c (mminloc0_4_i16): Likewise.
	* generated/minloc0_4_i2.c (mminloc0_4_i2): Likewise.
	* generated/minloc0_4_i4.c (mminloc0_4_i4): Likewise.
	* generated/minloc0_4_i8.c (mminloc0_4_i8): Likewise.
	* generated/minloc0_4_m1.c (mminloc0_4_m1): Likewise.
	* generated/minloc0_4_m16.c (mminloc0_4_m16): Likewise.
	* generated/minloc0_4_m2.c (mminloc0_4_m2): Likewise.
	* generated/minloc0_4_m4.c (mminloc0_4_m4): Likewise.
	* generated/minloc0_4_m8.c (mminloc0_4_m8): Likewise.
	* generated/minloc0_4_r10.c (mminloc0_4_r10): Likewise.
	* generated/minloc0_4_r16.c (mminloc0_4_r16): Likewise.
	* generated/minloc0_4_r17.c (mminloc0_4_r17): Likewise.
	* generated/minloc0_4_r4.c (mminloc0_4_r4): Likewise.
	* generated/minloc0_4_r8.c (mminloc0_4_r8): Likewise.
	* generated/minloc0_8_i1.c (mminloc0_8_i1): Likewise.
	* generated/minloc0_8_i16.c (mminloc0_8_i16): Likewise.
	* generated/minloc0_8_i2.c (mminloc0_8_i2): Likewise.
	* generated/minloc0_8_i4.c (mminloc0_8_i4): Likewise.
	* generated/minloc0_8_i8.c (mminloc0_8_i8): Likewise.
	* generated/minloc0_8_m1.c (mminloc0_8_m1): Likewise.
	* generated/minloc0_8_m16.c (mminloc0_8_m16): Likewise.
	* generated/minloc0_8_m2.c (mminloc0_8_m2): Likewise.
	* generated/minloc0_8_m4.c (mminloc0_8_m4): Likewise.
	* generated/minloc0_8_m8.c (mminloc0_8_m8): Likewise.
	* generated/minloc0_8_r10.c (mminloc0_8_r10): Likewise.
	* generated/minloc0_8_r16.c (mminloc0_8_r16): Likewise.
	* generated/minloc0_8_r17.c (mminloc0_8_r17): Likewise.
	* generated/minloc0_8_r4.c (mminloc0_8_r4): Likewise.
	* generated/minloc0_8_r8.c (mminloc0_8_r8): Likewise.
	* m4/maxloc0.m4: Fix looping through array argument when BACK=.true.
	* m4/minloc0.m4: Likewise.

gcc/testsuite/ChangeLog:

	* gfortran.dg/minmaxloc_mask_back.f90: New test.
---
 .../gfortran.dg/minmaxloc_mask_back.f90       | 32 +++++++++++++++++++
 libgfortran/generated/maxloc0_16_i1.c         |  2 +-
 libgfortran/generated/maxloc0_16_i16.c        |  2 +-
 libgfortran/generated/maxloc0_16_i2.c         |  2 +-
 libgfortran/generated/maxloc0_16_i4.c         |  2 +-
 libgfortran/generated/maxloc0_16_i8.c         |  2 +-
 libgfortran/generated/maxloc0_16_m1.c         |  2 +-
 libgfortran/generated/maxloc0_16_m16.c        |  2 +-
 libgfortran/generated/maxloc0_16_m2.c         |  2 +-
 libgfortran/generated/maxloc0_16_m4.c         |  2 +-
 libgfortran/generated/maxloc0_16_m8.c         |  2 +-
 libgfortran/generated/maxloc0_16_r10.c        |  2 +-
 libgfortran/generated/maxloc0_16_r16.c        |  2 +-
 libgfortran/generated/maxloc0_16_r17.c        |  2 +-
 libgfortran/generated/maxloc0_16_r4.c         |  2 +-
 libgfortran/generated/maxloc0_16_r8.c         |  2 +-
 libgfortran/generated/maxloc0_4_i1.c          |  2 +-
 libgfortran/generated/maxloc0_4_i16.c         |  2 +-
 libgfortran/generated/maxloc0_4_i2.c          |  2 +-
 libgfortran/generated/maxloc0_4_i4.c          |  2 +-
 libgfortran/generated/maxloc0_4_i8.c          |  2 +-
 libgfortran/generated/maxloc0_4_m1.c          |  2 +-
 libgfortran/generated/maxloc0_4_m16.c         |  2 +-
 libgfortran/generated/maxloc0_4_m2.c          |  2 +-
 libgfortran/generated/maxloc0_4_m4.c          |  2 +-
 libgfortran/generated/maxloc0_4_m8.c          |  2 +-
 libgfortran/generated/maxloc0_4_r10.c         |  2 +-
 libgfortran/generated/maxloc0_4_r16.c         |  2 +-
 libgfortran/generated/maxloc0_4_r17.c         |  2 +-
 libgfortran/generated/maxloc0_4_r4.c          |  2 +-
 libgfortran/generated/maxloc0_4_r8.c          |  2 +-
 libgfortran/generated/maxloc0_8_i1.c          |  2 +-
 libgfortran/generated/maxloc0_8_i16.c         |  2 +-
 libgfortran/generated/maxloc0_8_i2.c          |  2 +-
 libgfortran/generated/maxloc0_8_i4.c          |  2 +-
 libgfortran/generated/maxloc0_8_i8.c          |  2 +-
 libgfortran/generated/maxloc0_8_m1.c          |  2 +-
 libgfortran/generated/maxloc0_8_m16.c         |  2 +-
 libgfortran/generated/maxloc0_8_m2.c          |  2 +-
 libgfortran/generated/maxloc0_8_m4.c          |  2 +-
 libgfortran/generated/maxloc0_8_m8.c          |  2 +-
 libgfortran/generated/maxloc0_8_r10.c         |  2 +-
 libgfortran/generated/maxloc0_8_r16.c         |  2 +-
 libgfortran/generated/maxloc0_8_r17.c         |  2 +-
 libgfortran/generated/maxloc0_8_r4.c          |  2 +-
 libgfortran/generated/maxloc0_8_r8.c          |  2 +-
 libgfortran/generated/minloc0_16_i1.c         |  5 +--
 libgfortran/generated/minloc0_16_i16.c        |  5 +--
 libgfortran/generated/minloc0_16_i2.c         |  5 +--
 libgfortran/generated/minloc0_16_i4.c         |  5 +--
 libgfortran/generated/minloc0_16_i8.c         |  5 +--
 libgfortran/generated/minloc0_16_m1.c         |  5 +--
 libgfortran/generated/minloc0_16_m16.c        |  5 +--
 libgfortran/generated/minloc0_16_m2.c         |  5 +--
 libgfortran/generated/minloc0_16_m4.c         |  5 +--
 libgfortran/generated/minloc0_16_m8.c         |  5 +--
 libgfortran/generated/minloc0_16_r10.c        |  5 +--
 libgfortran/generated/minloc0_16_r16.c        |  5 +--
 libgfortran/generated/minloc0_16_r17.c        |  5 +--
 libgfortran/generated/minloc0_16_r4.c         |  5 +--
 libgfortran/generated/minloc0_16_r8.c         |  5 +--
 libgfortran/generated/minloc0_4_i1.c          |  5 +--
 libgfortran/generated/minloc0_4_i16.c         |  5 +--
 libgfortran/generated/minloc0_4_i2.c          |  5 +--
 libgfortran/generated/minloc0_4_i4.c          |  5 +--
 libgfortran/generated/minloc0_4_i8.c          |  5 +--
 libgfortran/generated/minloc0_4_m1.c          |  5 +--
 libgfortran/generated/minloc0_4_m16.c         |  5 +--
 libgfortran/generated/minloc0_4_m2.c          |  5 +--
 libgfortran/generated/minloc0_4_m4.c          |  5 +--
 libgfortran/generated/minloc0_4_m8.c          |  5 +--
 libgfortran/generated/minloc0_4_r10.c         |  5 +--
 libgfortran/generated/minloc0_4_r16.c         |  5 +--
 libgfortran/generated/minloc0_4_r17.c         |  5 +--
 libgfortran/generated/minloc0_4_r4.c          |  5 +--
 libgfortran/generated/minloc0_4_r8.c          |  5 +--
 libgfortran/generated/minloc0_8_i1.c          |  5 +--
 libgfortran/generated/minloc0_8_i16.c         |  5 +--
 libgfortran/generated/minloc0_8_i2.c          |  5 +--
 libgfortran/generated/minloc0_8_i4.c          |  5 +--
 libgfortran/generated/minloc0_8_i8.c          |  5 +--
 libgfortran/generated/minloc0_8_m1.c          |  5 +--
 libgfortran/generated/minloc0_8_m16.c         |  5 +--
 libgfortran/generated/minloc0_8_m2.c          |  5 +--
 libgfortran/generated/minloc0_8_m4.c          |  5 +--
 libgfortran/generated/minloc0_8_m8.c          |  5 +--
 libgfortran/generated/minloc0_8_r10.c         |  5 +--
 libgfortran/generated/minloc0_8_r16.c         |  5 +--
 libgfortran/generated/minloc0_8_r17.c         |  5 +--
 libgfortran/generated/minloc0_8_r4.c          |  5 +--
 libgfortran/generated/minloc0_8_r8.c          |  5 +--
 libgfortran/m4/maxloc0.m4                     |  2 +-
 libgfortran/m4/minloc0.m4                     |  5 +--
 93 files changed, 216 insertions(+), 138 deletions(-)
 create mode 100644 gcc/testsuite/gfortran.dg/minmaxloc_mask_back.f90

diff --git a/gcc/testsuite/gfortran.dg/minmaxloc_mask_back.f90 b/gcc/testsuite/gfortran.dg/minmaxloc_mask_back.f90
new file mode 100644
index 00000000000..5d02376ccc2
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/minmaxloc_mask_back.f90
@@ -0,0 +1,32 @@
+! { dg-do run }
+!
+! PR fortran/127846 - MINLOC/MAXLOC with MASK and BACK=.true.
+!
+! Contributed by Federico Perini.
+
+program minloc_mask_back
+  implicit none
+  real(8) :: y(3,4)
+  logical :: m(3,4)
+  integer :: i, j, l
+  l = 0
+  do j = 1, 4; do i = 1, 3
+     y(i,j) = real(mod(l*7,5)+1, 8); m(i,j) = mod(l,3) /= 1; l = l + 1
+  end do; end do
+  if (any (minloc(y, mask=m, back=.true.) /= [ 3, 2 ])) then
+     do i = 1, 3
+        print '(4f4.1,6x,4l2)', y(i,:), m(i,:)
+     end do
+     print '(a,2i3,a)', 'minloc(y, mask=m, back=.true.) =', &
+          minloc(y, mask=m, back=.true.), '   expected  3  2 (m(2,4) is F)'
+     stop 1
+  end if
+  if (any (maxloc(y, mask=m, back=.true.) /= [ 3, 1 ])) then
+     do i = 1, 3
+        print '(4f4.1,6x,4l2)', y(i,:), m(i,:)
+     end do
+     print '(a,2i3,a)', 'maxloc(y, mask=m, back=.true.) =', &
+          maxloc(y, mask=m, back=.true.), '   expected  3  1 (m(2,3) is F)'
+     stop 2
+  end if
+end program minloc_mask_back
diff --git a/libgfortran/generated/maxloc0_16_i1.c b/libgfortran/generated/maxloc0_16_i1.c
index ab54fa01d12..da8d76765b0 100644
--- a/libgfortran/generated/maxloc0_16_i1.c
+++ b/libgfortran/generated/maxloc0_16_i1.c
@@ -315,6 +315,7 @@ mmaxloc0_16_i1 (gfc_array_i16 * const restrict retarray,
 		    dest[n * dstride] = count[n] + 1;
 		}
 	      base += sstride[0];
+	      mbase += mstride[0];
 	    }
 	  while (++count[0] != extent[0]);
 	else
@@ -361,7 +362,6 @@ mmaxloc0_16_i1 (gfc_array_i16 * const restrict retarray,
   }
 }
 
-
 extern void smaxloc0_16_i1 (gfc_array_i16 * const restrict, 
 	gfc_array_i1 * const restrict, GFC_LOGICAL_4 *, GFC_LOGICAL_4);
 export_proto(smaxloc0_16_i1);
diff --git a/libgfortran/generated/maxloc0_16_i16.c b/libgfortran/generated/maxloc0_16_i16.c
index 2b15b8d57e7..feafd0fd490 100644
--- a/libgfortran/generated/maxloc0_16_i16.c
+++ b/libgfortran/generated/maxloc0_16_i16.c
@@ -315,6 +315,7 @@ mmaxloc0_16_i16 (gfc_array_i16 * const restrict retarray,
 		    dest[n * dstride] = count[n] + 1;
 		}
 	      base += sstride[0];
+	      mbase += mstride[0];
 	    }
 	  while (++count[0] != extent[0]);
 	else
@@ -361,7 +362,6 @@ mmaxloc0_16_i16 (gfc_array_i16 * const restrict retarray,
   }
 }
 
-
 extern void smaxloc0_16_i16 (gfc_array_i16 * const restrict, 
 	gfc_array_i16 * const restrict, GFC_LOGICAL_4 *, GFC_LOGICAL_4);
 export_proto(smaxloc0_16_i16);
diff --git a/libgfortran/generated/maxloc0_16_i2.c b/libgfortran/generated/maxloc0_16_i2.c
index e79cd86479c..09556e1df86 100644
--- a/libgfortran/generated/maxloc0_16_i2.c
+++ b/libgfortran/generated/maxloc0_16_i2.c
@@ -315,6 +315,7 @@ mmaxloc0_16_i2 (gfc_array_i16 * const restrict retarray,
 		    dest[n * dstride] = count[n] + 1;
 		}
 	      base += sstride[0];
+	      mbase += mstride[0];
 	    }
 	  while (++count[0] != extent[0]);
 	else
@@ -361,7 +362,6 @@ mmaxloc0_16_i2 (gfc_array_i16 * const restrict retarray,
   }
 }
 
-
 extern void smaxloc0_16_i2 (gfc_array_i16 * const restrict, 
 	gfc_array_i2 * const restrict, GFC_LOGICAL_4 *, GFC_LOGICAL_4);
 export_proto(smaxloc0_16_i2);
diff --git a/libgfortran/generated/maxloc0_16_i4.c b/libgfortran/generated/maxloc0_16_i4.c
index dc7fe6593d0..48b920f0943 100644
--- a/libgfortran/generated/maxloc0_16_i4.c
+++ b/libgfortran/generated/maxloc0_16_i4.c
@@ -315,6 +315,7 @@ mmaxloc0_16_i4 (gfc_array_i16 * const restrict retarray,
 		    dest[n * dstride] = count[n] + 1;
 		}
 	      base += sstride[0];
+	      mbase += mstride[0];
 	    }
 	  while (++count[0] != extent[0]);
 	else
@@ -361,7 +362,6 @@ mmaxloc0_16_i4 (gfc_array_i16 * const restrict retarray,
   }
 }
 
-
 extern void smaxloc0_16_i4 (gfc_array_i16 * const restrict, 
 	gfc_array_i4 * const restrict, GFC_LOGICAL_4 *, GFC_LOGICAL_4);
 export_proto(smaxloc0_16_i4);
diff --git a/libgfortran/generated/maxloc0_16_i8.c b/libgfortran/generated/maxloc0_16_i8.c
index 49f43a5ca40..47840a47016 100644
--- a/libgfortran/generated/maxloc0_16_i8.c
+++ b/libgfortran/generated/maxloc0_16_i8.c
@@ -315,6 +315,7 @@ mmaxloc0_16_i8 (gfc_array_i16 * const restrict retarray,
 		    dest[n * dstride] = count[n] + 1;
 		}
 	      base += sstride[0];
+	      mbase += mstride[0];
 	    }
 	  while (++count[0] != extent[0]);
 	else
@@ -361,7 +362,6 @@ mmaxloc0_16_i8 (gfc_array_i16 * const restrict retarray,
   }
 }
 
-
 extern void smaxloc0_16_i8 (gfc_array_i16 * const restrict, 
 	gfc_array_i8 * const restrict, GFC_LOGICAL_4 *, GFC_LOGICAL_4);
 export_proto(smaxloc0_16_i8);
diff --git a/libgfortran/generated/maxloc0_16_m1.c b/libgfortran/generated/maxloc0_16_m1.c
index 289f444928f..b962cdabe92 100644
--- a/libgfortran/generated/maxloc0_16_m1.c
+++ b/libgfortran/generated/maxloc0_16_m1.c
@@ -315,6 +315,7 @@ mmaxloc0_16_m1 (gfc_array_i16 * const restrict retarray,
 		    dest[n * dstride] = count[n] + 1;
 		}
 	      base += sstride[0];
+	      mbase += mstride[0];
 	    }
 	  while (++count[0] != extent[0]);
 	else
@@ -361,7 +362,6 @@ mmaxloc0_16_m1 (gfc_array_i16 * const restrict retarray,
   }
 }
 
-
 extern void smaxloc0_16_m1 (gfc_array_i16 * const restrict, 
 	gfc_array_m1 * const restrict, GFC_LOGICAL_4 *, GFC_LOGICAL_4);
 export_proto(smaxloc0_16_m1);
diff --git a/libgfortran/generated/maxloc0_16_m16.c b/libgfortran/generated/maxloc0_16_m16.c
index 37981ea641f..be381c8a2bc 100644
--- a/libgfortran/generated/maxloc0_16_m16.c
+++ b/libgfortran/generated/maxloc0_16_m16.c
@@ -315,6 +315,7 @@ mmaxloc0_16_m16 (gfc_array_i16 * const restrict retarray,
 		    dest[n * dstride] = count[n] + 1;
 		}
 	      base += sstride[0];
+	      mbase += mstride[0];
 	    }
 	  while (++count[0] != extent[0]);
 	else
@@ -361,7 +362,6 @@ mmaxloc0_16_m16 (gfc_array_i16 * const restrict retarray,
   }
 }
 
-
 extern void smaxloc0_16_m16 (gfc_array_i16 * const restrict, 
 	gfc_array_m16 * const restrict, GFC_LOGICAL_4 *, GFC_LOGICAL_4);
 export_proto(smaxloc0_16_m16);
diff --git a/libgfortran/generated/maxloc0_16_m2.c b/libgfortran/generated/maxloc0_16_m2.c
index 83004a65cf6..d3e7b97e6c1 100644
--- a/libgfortran/generated/maxloc0_16_m2.c
+++ b/libgfortran/generated/maxloc0_16_m2.c
@@ -315,6 +315,7 @@ mmaxloc0_16_m2 (gfc_array_i16 * const restrict retarray,
 		    dest[n * dstride] = count[n] + 1;
 		}
 	      base += sstride[0];
+	      mbase += mstride[0];
 	    }
 	  while (++count[0] != extent[0]);
 	else
@@ -361,7 +362,6 @@ mmaxloc0_16_m2 (gfc_array_i16 * const restrict retarray,
   }
 }
 
-
 extern void smaxloc0_16_m2 (gfc_array_i16 * const restrict, 
 	gfc_array_m2 * const restrict, GFC_LOGICAL_4 *, GFC_LOGICAL_4);
 export_proto(smaxloc0_16_m2);
diff --git a/libgfortran/generated/maxloc0_16_m4.c b/libgfortran/generated/maxloc0_16_m4.c
index c763d727bb0..7b93446cd73 100644
--- a/libgfortran/generated/maxloc0_16_m4.c
+++ b/libgfortran/generated/maxloc0_16_m4.c
@@ -315,6 +315,7 @@ mmaxloc0_16_m4 (gfc_array_i16 * const restrict retarray,
 		    dest[n * dstride] = count[n] + 1;
 		}
 	      base += sstride[0];
+	      mbase += mstride[0];
 	    }
 	  while (++count[0] != extent[0]);
 	else
@@ -361,7 +362,6 @@ mmaxloc0_16_m4 (gfc_array_i16 * const restrict retarray,
   }
 }
 
-
 extern void smaxloc0_16_m4 (gfc_array_i16 * const restrict, 
 	gfc_array_m4 * const restrict, GFC_LOGICAL_4 *, GFC_LOGICAL_4);
 export_proto(smaxloc0_16_m4);
diff --git a/libgfortran/generated/maxloc0_16_m8.c b/libgfortran/generated/maxloc0_16_m8.c
index aa18d3e505b..6ebd0dc43ac 100644
--- a/libgfortran/generated/maxloc0_16_m8.c
+++ b/libgfortran/generated/maxloc0_16_m8.c
@@ -315,6 +315,7 @@ mmaxloc0_16_m8 (gfc_array_i16 * const restrict retarray,
 		    dest[n * dstride] = count[n] + 1;
 		}
 	      base += sstride[0];
+	      mbase += mstride[0];
 	    }
 	  while (++count[0] != extent[0]);
 	else
@@ -361,7 +362,6 @@ mmaxloc0_16_m8 (gfc_array_i16 * const restrict retarray,
   }
 }
 
-
 extern void smaxloc0_16_m8 (gfc_array_i16 * const restrict, 
 	gfc_array_m8 * const restrict, GFC_LOGICAL_4 *, GFC_LOGICAL_4);
 export_proto(smaxloc0_16_m8);
diff --git a/libgfortran/generated/maxloc0_16_r10.c b/libgfortran/generated/maxloc0_16_r10.c
index f192e7f32ee..8959e4c9811 100644
--- a/libgfortran/generated/maxloc0_16_r10.c
+++ b/libgfortran/generated/maxloc0_16_r10.c
@@ -315,6 +315,7 @@ mmaxloc0_16_r10 (gfc_array_i16 * const restrict retarray,
 		    dest[n * dstride] = count[n] + 1;
 		}
 	      base += sstride[0];
+	      mbase += mstride[0];
 	    }
 	  while (++count[0] != extent[0]);
 	else
@@ -361,7 +362,6 @@ mmaxloc0_16_r10 (gfc_array_i16 * const restrict retarray,
   }
 }
 
-
 extern void smaxloc0_16_r10 (gfc_array_i16 * const restrict, 
 	gfc_array_r10 * const restrict, GFC_LOGICAL_4 *, GFC_LOGICAL_4);
 export_proto(smaxloc0_16_r10);
diff --git a/libgfortran/generated/maxloc0_16_r16.c b/libgfortran/generated/maxloc0_16_r16.c
index d16eb546d48..8cc678f5d28 100644
--- a/libgfortran/generated/maxloc0_16_r16.c
+++ b/libgfortran/generated/maxloc0_16_r16.c
@@ -315,6 +315,7 @@ mmaxloc0_16_r16 (gfc_array_i16 * const restrict retarray,
 		    dest[n * dstride] = count[n] + 1;
 		}
 	      base += sstride[0];
+	      mbase += mstride[0];
 	    }
 	  while (++count[0] != extent[0]);
 	else
@@ -361,7 +362,6 @@ mmaxloc0_16_r16 (gfc_array_i16 * const restrict retarray,
   }
 }
 
-
 extern void smaxloc0_16_r16 (gfc_array_i16 * const restrict, 
 	gfc_array_r16 * const restrict, GFC_LOGICAL_4 *, GFC_LOGICAL_4);
 export_proto(smaxloc0_16_r16);
diff --git a/libgfortran/generated/maxloc0_16_r17.c b/libgfortran/generated/maxloc0_16_r17.c
index fbd0c30f51f..6fa3b28ff1f 100644
--- a/libgfortran/generated/maxloc0_16_r17.c
+++ b/libgfortran/generated/maxloc0_16_r17.c
@@ -315,6 +315,7 @@ mmaxloc0_16_r17 (gfc_array_i16 * const restrict retarray,
 		    dest[n * dstride] = count[n] + 1;
 		}
 	      base += sstride[0];
+	      mbase += mstride[0];
 	    }
 	  while (++count[0] != extent[0]);
 	else
@@ -361,7 +362,6 @@ mmaxloc0_16_r17 (gfc_array_i16 * const restrict retarray,
   }
 }
 
-
 extern void smaxloc0_16_r17 (gfc_array_i16 * const restrict, 
 	gfc_array_r17 * const restrict, GFC_LOGICAL_4 *, GFC_LOGICAL_4);
 export_proto(smaxloc0_16_r17);
diff --git a/libgfortran/generated/maxloc0_16_r4.c b/libgfortran/generated/maxloc0_16_r4.c
index 815fb7aacb8..6e1b44d842c 100644
--- a/libgfortran/generated/maxloc0_16_r4.c
+++ b/libgfortran/generated/maxloc0_16_r4.c
@@ -315,6 +315,7 @@ mmaxloc0_16_r4 (gfc_array_i16 * const restrict retarray,
 		    dest[n * dstride] = count[n] + 1;
 		}
 	      base += sstride[0];
+	      mbase += mstride[0];
 	    }
 	  while (++count[0] != extent[0]);
 	else
@@ -361,7 +362,6 @@ mmaxloc0_16_r4 (gfc_array_i16 * const restrict retarray,
   }
 }
 
-
 extern void smaxloc0_16_r4 (gfc_array_i16 * const restrict, 
 	gfc_array_r4 * const restrict, GFC_LOGICAL_4 *, GFC_LOGICAL_4);
 export_proto(smaxloc0_16_r4);
diff --git a/libgfortran/generated/maxloc0_16_r8.c b/libgfortran/generated/maxloc0_16_r8.c
index 730c6f1946a..244d0225e90 100644
--- a/libgfortran/generated/maxloc0_16_r8.c
+++ b/libgfortran/generated/maxloc0_16_r8.c
@@ -315,6 +315,7 @@ mmaxloc0_16_r8 (gfc_array_i16 * const restrict retarray,
 		    dest[n * dstride] = count[n] + 1;
 		}
 	      base += sstride[0];
+	      mbase += mstride[0];
 	    }
 	  while (++count[0] != extent[0]);
 	else
@@ -361,7 +362,6 @@ mmaxloc0_16_r8 (gfc_array_i16 * const restrict retarray,
   }
 }
 
-
 extern void smaxloc0_16_r8 (gfc_array_i16 * const restrict, 
 	gfc_array_r8 * const restrict, GFC_LOGICAL_4 *, GFC_LOGICAL_4);
 export_proto(smaxloc0_16_r8);
diff --git a/libgfortran/generated/maxloc0_4_i1.c b/libgfortran/generated/maxloc0_4_i1.c
index a33378711f9..13db1677739 100644
--- a/libgfortran/generated/maxloc0_4_i1.c
+++ b/libgfortran/generated/maxloc0_4_i1.c
@@ -315,6 +315,7 @@ mmaxloc0_4_i1 (gfc_array_i4 * const restrict retarray,
 		    dest[n * dstride] = count[n] + 1;
 		}
 	      base += sstride[0];
+	      mbase += mstride[0];
 	    }
 	  while (++count[0] != extent[0]);
 	else
@@ -361,7 +362,6 @@ mmaxloc0_4_i1 (gfc_array_i4 * const restrict retarray,
   }
 }
 
-
 extern void smaxloc0_4_i1 (gfc_array_i4 * const restrict, 
 	gfc_array_i1 * const restrict, GFC_LOGICAL_4 *, GFC_LOGICAL_4);
 export_proto(smaxloc0_4_i1);
diff --git a/libgfortran/generated/maxloc0_4_i16.c b/libgfortran/generated/maxloc0_4_i16.c
index b5af542084c..8a0d394a0ca 100644
--- a/libgfortran/generated/maxloc0_4_i16.c
+++ b/libgfortran/generated/maxloc0_4_i16.c
@@ -315,6 +315,7 @@ mmaxloc0_4_i16 (gfc_array_i4 * const restrict retarray,
 		    dest[n * dstride] = count[n] + 1;
 		}
 	      base += sstride[0];
+	      mbase += mstride[0];
 	    }
 	  while (++count[0] != extent[0]);
 	else
@@ -361,7 +362,6 @@ mmaxloc0_4_i16 (gfc_array_i4 * const restrict retarray,
   }
 }
 
-
 extern void smaxloc0_4_i16 (gfc_array_i4 * const restrict, 
 	gfc_array_i16 * const restrict, GFC_LOGICAL_4 *, GFC_LOGICAL_4);
 export_proto(smaxloc0_4_i16);
diff --git a/libgfortran/generated/maxloc0_4_i2.c b/libgfortran/generated/maxloc0_4_i2.c
index ba168348786..0a75351da5f 100644
--- a/libgfortran/generated/maxloc0_4_i2.c
+++ b/libgfortran/generated/maxloc0_4_i2.c
@@ -315,6 +315,7 @@ mmaxloc0_4_i2 (gfc_array_i4 * const restrict retarray,
 		    dest[n * dstride] = count[n] + 1;
 		}
 	      base += sstride[0];
+	      mbase += mstride[0];
 	    }
 	  while (++count[0] != extent[0]);
 	else
@@ -361,7 +362,6 @@ mmaxloc0_4_i2 (gfc_array_i4 * const restrict retarray,
   }
 }
 
-
 extern void smaxloc0_4_i2 (gfc_array_i4 * const restrict, 
 	gfc_array_i2 * const restrict, GFC_LOGICAL_4 *, GFC_LOGICAL_4);
 export_proto(smaxloc0_4_i2);
diff --git a/libgfortran/generated/maxloc0_4_i4.c b/libgfortran/generated/maxloc0_4_i4.c
index 471e6168bab..f6d83385908 100644
--- a/libgfortran/generated/maxloc0_4_i4.c
+++ b/libgfortran/generated/maxloc0_4_i4.c
@@ -315,6 +315,7 @@ mmaxloc0_4_i4 (gfc_array_i4 * const restrict retarray,
 		    dest[n * dstride] = count[n] + 1;
 		}
 	      base += sstride[0];
+	      mbase += mstride[0];
 	    }
 	  while (++count[0] != extent[0]);
 	else
@@ -361,7 +362,6 @@ mmaxloc0_4_i4 (gfc_array_i4 * const restrict retarray,
   }
 }
 
-
 extern void smaxloc0_4_i4 (gfc_array_i4 * const restrict, 
 	gfc_array_i4 * const restrict, GFC_LOGICAL_4 *, GFC_LOGICAL_4);
 export_proto(smaxloc0_4_i4);
diff --git a/libgfortran/generated/maxloc0_4_i8.c b/libgfortran/generated/maxloc0_4_i8.c
index e0e6dc6948d..7d7425ebeea 100644
--- a/libgfortran/generated/maxloc0_4_i8.c
+++ b/libgfortran/generated/maxloc0_4_i8.c
@@ -315,6 +315,7 @@ mmaxloc0_4_i8 (gfc_array_i4 * const restrict retarray,
 		    dest[n * dstride] = count[n] + 1;
 		}
 	      base += sstride[0];
+	      mbase += mstride[0];
 	    }
 	  while (++count[0] != extent[0]);
 	else
@@ -361,7 +362,6 @@ mmaxloc0_4_i8 (gfc_array_i4 * const restrict retarray,
   }
 }
 
-
 extern void smaxloc0_4_i8 (gfc_array_i4 * const restrict, 
 	gfc_array_i8 * const restrict, GFC_LOGICAL_4 *, GFC_LOGICAL_4);
 export_proto(smaxloc0_4_i8);
diff --git a/libgfortran/generated/maxloc0_4_m1.c b/libgfortran/generated/maxloc0_4_m1.c
index afd88cb3c68..0d001f39820 100644
--- a/libgfortran/generated/maxloc0_4_m1.c
+++ b/libgfortran/generated/maxloc0_4_m1.c
@@ -315,6 +315,7 @@ mmaxloc0_4_m1 (gfc_array_i4 * const restrict retarray,
 		    dest[n * dstride] = count[n] + 1;
 		}
 	      base += sstride[0];
+	      mbase += mstride[0];
 	    }
 	  while (++count[0] != extent[0]);
 	else
@@ -361,7 +362,6 @@ mmaxloc0_4_m1 (gfc_array_i4 * const restrict retarray,
   }
 }
 
-
 extern void smaxloc0_4_m1 (gfc_array_i4 * const restrict, 
 	gfc_array_m1 * const restrict, GFC_LOGICAL_4 *, GFC_LOGICAL_4);
 export_proto(smaxloc0_4_m1);
diff --git a/libgfortran/generated/maxloc0_4_m16.c b/libgfortran/generated/maxloc0_4_m16.c
index 9ba1a5f7308..d9b4c09aeb7 100644
--- a/libgfortran/generated/maxloc0_4_m16.c
+++ b/libgfortran/generated/maxloc0_4_m16.c
@@ -315,6 +315,7 @@ mmaxloc0_4_m16 (gfc_array_i4 * const restrict retarray,
 		    dest[n * dstride] = count[n] + 1;
 		}
 	      base += sstride[0];
+	      mbase += mstride[0];
 	    }
 	  while (++count[0] != extent[0]);
 	else
@@ -361,7 +362,6 @@ mmaxloc0_4_m16 (gfc_array_i4 * const restrict retarray,
   }
 }
 
-
 extern void smaxloc0_4_m16 (gfc_array_i4 * const restrict, 
 	gfc_array_m16 * const restrict, GFC_LOGICAL_4 *, GFC_LOGICAL_4);
 export_proto(smaxloc0_4_m16);
diff --git a/libgfortran/generated/maxloc0_4_m2.c b/libgfortran/generated/maxloc0_4_m2.c
index 4876f15822b..71f2ad958ab 100644
--- a/libgfortran/generated/maxloc0_4_m2.c
+++ b/libgfortran/generated/maxloc0_4_m2.c
@@ -315,6 +315,7 @@ mmaxloc0_4_m2 (gfc_array_i4 * const restrict retarray,
 		    dest[n * dstride] = count[n] + 1;
 		}
 	      base += sstride[0];
+	      mbase += mstride[0];
 	    }
 	  while (++count[0] != extent[0]);
 	else
@@ -361,7 +362,6 @@ mmaxloc0_4_m2 (gfc_array_i4 * const restrict retarray,
   }
 }
 
-
 extern void smaxloc0_4_m2 (gfc_array_i4 * const restrict, 
 	gfc_array_m2 * const restrict, GFC_LOGICAL_4 *, GFC_LOGICAL_4);
 export_proto(smaxloc0_4_m2);
diff --git a/libgfortran/generated/maxloc0_4_m4.c b/libgfortran/generated/maxloc0_4_m4.c
index e7b54db638b..5d3b962e6ef 100644
--- a/libgfortran/generated/maxloc0_4_m4.c
+++ b/libgfortran/generated/maxloc0_4_m4.c
@@ -315,6 +315,7 @@ mmaxloc0_4_m4 (gfc_array_i4 * const restrict retarray,
 		    dest[n * dstride] = count[n] + 1;
 		}
 	      base += sstride[0];
+	      mbase += mstride[0];
 	    }
 	  while (++count[0] != extent[0]);
 	else
@@ -361,7 +362,6 @@ mmaxloc0_4_m4 (gfc_array_i4 * const restrict retarray,
   }
 }
 
-
 extern void smaxloc0_4_m4 (gfc_array_i4 * const restrict, 
 	gfc_array_m4 * const restrict, GFC_LOGICAL_4 *, GFC_LOGICAL_4);
 export_proto(smaxloc0_4_m4);
diff --git a/libgfortran/generated/maxloc0_4_m8.c b/libgfortran/generated/maxloc0_4_m8.c
index ddd4575f94e..0489e55440d 100644
--- a/libgfortran/generated/maxloc0_4_m8.c
+++ b/libgfortran/generated/maxloc0_4_m8.c
@@ -315,6 +315,7 @@ mmaxloc0_4_m8 (gfc_array_i4 * const restrict retarray,
 		    dest[n * dstride] = count[n] + 1;
 		}
 	      base += sstride[0];
+	      mbase += mstride[0];
 	    }
 	  while (++count[0] != extent[0]);
 	else
@@ -361,7 +362,6 @@ mmaxloc0_4_m8 (gfc_array_i4 * const restrict retarray,
   }
 }
 
-
 extern void smaxloc0_4_m8 (gfc_array_i4 * const restrict, 
 	gfc_array_m8 * const restrict, GFC_LOGICAL_4 *, GFC_LOGICAL_4);
 export_proto(smaxloc0_4_m8);
diff --git a/libgfortran/generated/maxloc0_4_r10.c b/libgfortran/generated/maxloc0_4_r10.c
index 47e666b7096..2c0c0e9be23 100644
--- a/libgfortran/generated/maxloc0_4_r10.c
+++ b/libgfortran/generated/maxloc0_4_r10.c
@@ -315,6 +315,7 @@ mmaxloc0_4_r10 (gfc_array_i4 * const restrict retarray,
 		    dest[n * dstride] = count[n] + 1;
 		}
 	      base += sstride[0];
+	      mbase += mstride[0];
 	    }
 	  while (++count[0] != extent[0]);
 	else
@@ -361,7 +362,6 @@ mmaxloc0_4_r10 (gfc_array_i4 * const restrict retarray,
   }
 }
 
-
 extern void smaxloc0_4_r10 (gfc_array_i4 * const restrict, 
 	gfc_array_r10 * const restrict, GFC_LOGICAL_4 *, GFC_LOGICAL_4);
 export_proto(smaxloc0_4_r10);
diff --git a/libgfortran/generated/maxloc0_4_r16.c b/libgfortran/generated/maxloc0_4_r16.c
index 1d2132b1792..77614a4ee7c 100644
--- a/libgfortran/generated/maxloc0_4_r16.c
+++ b/libgfortran/generated/maxloc0_4_r16.c
@@ -315,6 +315,7 @@ mmaxloc0_4_r16 (gfc_array_i4 * const restrict retarray,
 		    dest[n * dstride] = count[n] + 1;
 		}
 	      base += sstride[0];
+	      mbase += mstride[0];
 	    }
 	  while (++count[0] != extent[0]);
 	else
@@ -361,7 +362,6 @@ mmaxloc0_4_r16 (gfc_array_i4 * const restrict retarray,
   }
 }
 
-
 extern void smaxloc0_4_r16 (gfc_array_i4 * const restrict, 
 	gfc_array_r16 * const restrict, GFC_LOGICAL_4 *, GFC_LOGICAL_4);
 export_proto(smaxloc0_4_r16);
diff --git a/libgfortran/generated/maxloc0_4_r17.c b/libgfortran/generated/maxloc0_4_r17.c
index 03b8f94c9bf..bf3587b9f7a 100644
--- a/libgfortran/generated/maxloc0_4_r17.c
+++ b/libgfortran/generated/maxloc0_4_r17.c
@@ -315,6 +315,7 @@ mmaxloc0_4_r17 (gfc_array_i4 * const restrict retarray,
 		    dest[n * dstride] = count[n] + 1;
 		}
 	      base += sstride[0];
+	      mbase += mstride[0];
 	    }
 	  while (++count[0] != extent[0]);
 	else
@@ -361,7 +362,6 @@ mmaxloc0_4_r17 (gfc_array_i4 * const restrict retarray,
   }
 }
 
-
 extern void smaxloc0_4_r17 (gfc_array_i4 * const restrict, 
 	gfc_array_r17 * const restrict, GFC_LOGICAL_4 *, GFC_LOGICAL_4);
 export_proto(smaxloc0_4_r17);
diff --git a/libgfortran/generated/maxloc0_4_r4.c b/libgfortran/generated/maxloc0_4_r4.c
index 73a01c6d98e..186232ad2bd 100644
--- a/libgfortran/generated/maxloc0_4_r4.c
+++ b/libgfortran/generated/maxloc0_4_r4.c
@@ -315,6 +315,7 @@ mmaxloc0_4_r4 (gfc_array_i4 * const restrict retarray,
 		    dest[n * dstride] = count[n] + 1;
 		}
 	      base += sstride[0];
+	      mbase += mstride[0];
 	    }
 	  while (++count[0] != extent[0]);
 	else
@@ -361,7 +362,6 @@ mmaxloc0_4_r4 (gfc_array_i4 * const restrict retarray,
   }
 }
 
-
 extern void smaxloc0_4_r4 (gfc_array_i4 * const restrict, 
 	gfc_array_r4 * const restrict, GFC_LOGICAL_4 *, GFC_LOGICAL_4);
 export_proto(smaxloc0_4_r4);
diff --git a/libgfortran/generated/maxloc0_4_r8.c b/libgfortran/generated/maxloc0_4_r8.c
index 7941f3427a3..309c59405eb 100644
--- a/libgfortran/generated/maxloc0_4_r8.c
+++ b/libgfortran/generated/maxloc0_4_r8.c
@@ -315,6 +315,7 @@ mmaxloc0_4_r8 (gfc_array_i4 * const restrict retarray,
 		    dest[n * dstride] = count[n] + 1;
 		}
 	      base += sstride[0];
+	      mbase += mstride[0];
 	    }
 	  while (++count[0] != extent[0]);
 	else
@@ -361,7 +362,6 @@ mmaxloc0_4_r8 (gfc_array_i4 * const restrict retarray,
   }
 }
 
-
 extern void smaxloc0_4_r8 (gfc_array_i4 * const restrict, 
 	gfc_array_r8 * const restrict, GFC_LOGICAL_4 *, GFC_LOGICAL_4);
 export_proto(smaxloc0_4_r8);
diff --git a/libgfortran/generated/maxloc0_8_i1.c b/libgfortran/generated/maxloc0_8_i1.c
index a233db2b918..0cdc898f6b3 100644
--- a/libgfortran/generated/maxloc0_8_i1.c
+++ b/libgfortran/generated/maxloc0_8_i1.c
@@ -315,6 +315,7 @@ mmaxloc0_8_i1 (gfc_array_i8 * const restrict retarray,
 		    dest[n * dstride] = count[n] + 1;
 		}
 	      base += sstride[0];
+	      mbase += mstride[0];
 	    }
 	  while (++count[0] != extent[0]);
 	else
@@ -361,7 +362,6 @@ mmaxloc0_8_i1 (gfc_array_i8 * const restrict retarray,
   }
 }
 
-
 extern void smaxloc0_8_i1 (gfc_array_i8 * const restrict, 
 	gfc_array_i1 * const restrict, GFC_LOGICAL_4 *, GFC_LOGICAL_4);
 export_proto(smaxloc0_8_i1);
diff --git a/libgfortran/generated/maxloc0_8_i16.c b/libgfortran/generated/maxloc0_8_i16.c
index 830498bae1f..084ac6f54eb 100644
--- a/libgfortran/generated/maxloc0_8_i16.c
+++ b/libgfortran/generated/maxloc0_8_i16.c
@@ -315,6 +315,7 @@ mmaxloc0_8_i16 (gfc_array_i8 * const restrict retarray,
 		    dest[n * dstride] = count[n] + 1;
 		}
 	      base += sstride[0];
+	      mbase += mstride[0];
 	    }
 	  while (++count[0] != extent[0]);
 	else
@@ -361,7 +362,6 @@ mmaxloc0_8_i16 (gfc_array_i8 * const restrict retarray,
   }
 }
 
-
 extern void smaxloc0_8_i16 (gfc_array_i8 * const restrict, 
 	gfc_array_i16 * const restrict, GFC_LOGICAL_4 *, GFC_LOGICAL_4);
 export_proto(smaxloc0_8_i16);
diff --git a/libgfortran/generated/maxloc0_8_i2.c b/libgfortran/generated/maxloc0_8_i2.c
index 2b71a8584c0..bce26f9a34b 100644
--- a/libgfortran/generated/maxloc0_8_i2.c
+++ b/libgfortran/generated/maxloc0_8_i2.c
@@ -315,6 +315,7 @@ mmaxloc0_8_i2 (gfc_array_i8 * const restrict retarray,
 		    dest[n * dstride] = count[n] + 1;
 		}
 	      base += sstride[0];
+	      mbase += mstride[0];
 	    }
 	  while (++count[0] != extent[0]);
 	else
@@ -361,7 +362,6 @@ mmaxloc0_8_i2 (gfc_array_i8 * const restrict retarray,
   }
 }
 
-
 extern void smaxloc0_8_i2 (gfc_array_i8 * const restrict, 
 	gfc_array_i2 * const restrict, GFC_LOGICAL_4 *, GFC_LOGICAL_4);
 export_proto(smaxloc0_8_i2);
diff --git a/libgfortran/generated/maxloc0_8_i4.c b/libgfortran/generated/maxloc0_8_i4.c
index 0a13ac93b75..d40eec38498 100644
--- a/libgfortran/generated/maxloc0_8_i4.c
+++ b/libgfortran/generated/maxloc0_8_i4.c
@@ -315,6 +315,7 @@ mmaxloc0_8_i4 (gfc_array_i8 * const restrict retarray,
 		    dest[n * dstride] = count[n] + 1;
 		}
 	      base += sstride[0];
+	      mbase += mstride[0];
 	    }
 	  while (++count[0] != extent[0]);
 	else
@@ -361,7 +362,6 @@ mmaxloc0_8_i4 (gfc_array_i8 * const restrict retarray,
   }
 }
 
-
 extern void smaxloc0_8_i4 (gfc_array_i8 * const restrict, 
 	gfc_array_i4 * const restrict, GFC_LOGICAL_4 *, GFC_LOGICAL_4);
 export_proto(smaxloc0_8_i4);
diff --git a/libgfortran/generated/maxloc0_8_i8.c b/libgfortran/generated/maxloc0_8_i8.c
index 59d4e68d529..f48d4097eff 100644
--- a/libgfortran/generated/maxloc0_8_i8.c
+++ b/libgfortran/generated/maxloc0_8_i8.c
@@ -315,6 +315,7 @@ mmaxloc0_8_i8 (gfc_array_i8 * const restrict retarray,
 		    dest[n * dstride] = count[n] + 1;
 		}
 	      base += sstride[0];
+	      mbase += mstride[0];
 	    }
 	  while (++count[0] != extent[0]);
 	else
@@ -361,7 +362,6 @@ mmaxloc0_8_i8 (gfc_array_i8 * const restrict retarray,
   }
 }
 
-
 extern void smaxloc0_8_i8 (gfc_array_i8 * const restrict, 
 	gfc_array_i8 * const restrict, GFC_LOGICAL_4 *, GFC_LOGICAL_4);
 export_proto(smaxloc0_8_i8);
diff --git a/libgfortran/generated/maxloc0_8_m1.c b/libgfortran/generated/maxloc0_8_m1.c
index 2029c8eae46..4785b784359 100644
--- a/libgfortran/generated/maxloc0_8_m1.c
+++ b/libgfortran/generated/maxloc0_8_m1.c
@@ -315,6 +315,7 @@ mmaxloc0_8_m1 (gfc_array_i8 * const restrict retarray,
 		    dest[n * dstride] = count[n] + 1;
 		}
 	      base += sstride[0];
+	      mbase += mstride[0];
 	    }
 	  while (++count[0] != extent[0]);
 	else
@@ -361,7 +362,6 @@ mmaxloc0_8_m1 (gfc_array_i8 * const restrict retarray,
   }
 }
 
-
 extern void smaxloc0_8_m1 (gfc_array_i8 * const restrict, 
 	gfc_array_m1 * const restrict, GFC_LOGICAL_4 *, GFC_LOGICAL_4);
 export_proto(smaxloc0_8_m1);
diff --git a/libgfortran/generated/maxloc0_8_m16.c b/libgfortran/generated/maxloc0_8_m16.c
index f68b30dc0b2..78034dc880b 100644
--- a/libgfortran/generated/maxloc0_8_m16.c
+++ b/libgfortran/generated/maxloc0_8_m16.c
@@ -315,6 +315,7 @@ mmaxloc0_8_m16 (gfc_array_i8 * const restrict retarray,
 		    dest[n * dstride] = count[n] + 1;
 		}
 	      base += sstride[0];
+	      mbase += mstride[0];
 	    }
 	  while (++count[0] != extent[0]);
 	else
@@ -361,7 +362,6 @@ mmaxloc0_8_m16 (gfc_array_i8 * const restrict retarray,
   }
 }
 
-
 extern void smaxloc0_8_m16 (gfc_array_i8 * const restrict, 
 	gfc_array_m16 * const restrict, GFC_LOGICAL_4 *, GFC_LOGICAL_4);
 export_proto(smaxloc0_8_m16);
diff --git a/libgfortran/generated/maxloc0_8_m2.c b/libgfortran/generated/maxloc0_8_m2.c
index 71c813b0d37..02c51c2a393 100644
--- a/libgfortran/generated/maxloc0_8_m2.c
+++ b/libgfortran/generated/maxloc0_8_m2.c
@@ -315,6 +315,7 @@ mmaxloc0_8_m2 (gfc_array_i8 * const restrict retarray,
 		    dest[n * dstride] = count[n] + 1;
 		}
 	      base += sstride[0];
+	      mbase += mstride[0];
 	    }
 	  while (++count[0] != extent[0]);
 	else
@@ -361,7 +362,6 @@ mmaxloc0_8_m2 (gfc_array_i8 * const restrict retarray,
   }
 }
 
-
 extern void smaxloc0_8_m2 (gfc_array_i8 * const restrict, 
 	gfc_array_m2 * const restrict, GFC_LOGICAL_4 *, GFC_LOGICAL_4);
 export_proto(smaxloc0_8_m2);
diff --git a/libgfortran/generated/maxloc0_8_m4.c b/libgfortran/generated/maxloc0_8_m4.c
index bb4f3ee3ed8..94fd47c3e25 100644
--- a/libgfortran/generated/maxloc0_8_m4.c
+++ b/libgfortran/generated/maxloc0_8_m4.c
@@ -315,6 +315,7 @@ mmaxloc0_8_m4 (gfc_array_i8 * const restrict retarray,
 		    dest[n * dstride] = count[n] + 1;
 		}
 	      base += sstride[0];
+	      mbase += mstride[0];
 	    }
 	  while (++count[0] != extent[0]);
 	else
@@ -361,7 +362,6 @@ mmaxloc0_8_m4 (gfc_array_i8 * const restrict retarray,
   }
 }
 
-
 extern void smaxloc0_8_m4 (gfc_array_i8 * const restrict, 
 	gfc_array_m4 * const restrict, GFC_LOGICAL_4 *, GFC_LOGICAL_4);
 export_proto(smaxloc0_8_m4);
diff --git a/libgfortran/generated/maxloc0_8_m8.c b/libgfortran/generated/maxloc0_8_m8.c
index 1ee1cf53cd8..a695e425cb2 100644
--- a/libgfortran/generated/maxloc0_8_m8.c
+++ b/libgfortran/generated/maxloc0_8_m8.c
@@ -315,6 +315,7 @@ mmaxloc0_8_m8 (gfc_array_i8 * const restrict retarray,
 		    dest[n * dstride] = count[n] + 1;
 		}
 	      base += sstride[0];
+	      mbase += mstride[0];
 	    }
 	  while (++count[0] != extent[0]);
 	else
@@ -361,7 +362,6 @@ mmaxloc0_8_m8 (gfc_array_i8 * const restrict retarray,
   }
 }
 
-
 extern void smaxloc0_8_m8 (gfc_array_i8 * const restrict, 
 	gfc_array_m8 * const restrict, GFC_LOGICAL_4 *, GFC_LOGICAL_4);
 export_proto(smaxloc0_8_m8);
diff --git a/libgfortran/generated/maxloc0_8_r10.c b/libgfortran/generated/maxloc0_8_r10.c
index 97eee7e20fb..d04960c9901 100644
--- a/libgfortran/generated/maxloc0_8_r10.c
+++ b/libgfortran/generated/maxloc0_8_r10.c
@@ -315,6 +315,7 @@ mmaxloc0_8_r10 (gfc_array_i8 * const restrict retarray,
 		    dest[n * dstride] = count[n] + 1;
 		}
 	      base += sstride[0];
+	      mbase += mstride[0];
 	    }
 	  while (++count[0] != extent[0]);
 	else
@@ -361,7 +362,6 @@ mmaxloc0_8_r10 (gfc_array_i8 * const restrict retarray,
   }
 }
 
-
 extern void smaxloc0_8_r10 (gfc_array_i8 * const restrict, 
 	gfc_array_r10 * const restrict, GFC_LOGICAL_4 *, GFC_LOGICAL_4);
 export_proto(smaxloc0_8_r10);
diff --git a/libgfortran/generated/maxloc0_8_r16.c b/libgfortran/generated/maxloc0_8_r16.c
index 0239b4ca7f9..af15785d638 100644
--- a/libgfortran/generated/maxloc0_8_r16.c
+++ b/libgfortran/generated/maxloc0_8_r16.c
@@ -315,6 +315,7 @@ mmaxloc0_8_r16 (gfc_array_i8 * const restrict retarray,
 		    dest[n * dstride] = count[n] + 1;
 		}
 	      base += sstride[0];
+	      mbase += mstride[0];
 	    }
 	  while (++count[0] != extent[0]);
 	else
@@ -361,7 +362,6 @@ mmaxloc0_8_r16 (gfc_array_i8 * const restrict retarray,
   }
 }
 
-
 extern void smaxloc0_8_r16 (gfc_array_i8 * const restrict, 
 	gfc_array_r16 * const restrict, GFC_LOGICAL_4 *, GFC_LOGICAL_4);
 export_proto(smaxloc0_8_r16);
diff --git a/libgfortran/generated/maxloc0_8_r17.c b/libgfortran/generated/maxloc0_8_r17.c
index c07eaf19002..529b3319a86 100644
--- a/libgfortran/generated/maxloc0_8_r17.c
+++ b/libgfortran/generated/maxloc0_8_r17.c
@@ -315,6 +315,7 @@ mmaxloc0_8_r17 (gfc_array_i8 * const restrict retarray,
 		    dest[n * dstride] = count[n] + 1;
 		}
 	      base += sstride[0];
+	      mbase += mstride[0];
 	    }
 	  while (++count[0] != extent[0]);
 	else
@@ -361,7 +362,6 @@ mmaxloc0_8_r17 (gfc_array_i8 * const restrict retarray,
   }
 }
 
-
 extern void smaxloc0_8_r17 (gfc_array_i8 * const restrict, 
 	gfc_array_r17 * const restrict, GFC_LOGICAL_4 *, GFC_LOGICAL_4);
 export_proto(smaxloc0_8_r17);
diff --git a/libgfortran/generated/maxloc0_8_r4.c b/libgfortran/generated/maxloc0_8_r4.c
index d6e71a093f8..a643ae2f2da 100644
--- a/libgfortran/generated/maxloc0_8_r4.c
+++ b/libgfortran/generated/maxloc0_8_r4.c
@@ -315,6 +315,7 @@ mmaxloc0_8_r4 (gfc_array_i8 * const restrict retarray,
 		    dest[n * dstride] = count[n] + 1;
 		}
 	      base += sstride[0];
+	      mbase += mstride[0];
 	    }
 	  while (++count[0] != extent[0]);
 	else
@@ -361,7 +362,6 @@ mmaxloc0_8_r4 (gfc_array_i8 * const restrict retarray,
   }
 }
 
-
 extern void smaxloc0_8_r4 (gfc_array_i8 * const restrict, 
 	gfc_array_r4 * const restrict, GFC_LOGICAL_4 *, GFC_LOGICAL_4);
 export_proto(smaxloc0_8_r4);
diff --git a/libgfortran/generated/maxloc0_8_r8.c b/libgfortran/generated/maxloc0_8_r8.c
index 680e65b802d..8d6d0f5ea0a 100644
--- a/libgfortran/generated/maxloc0_8_r8.c
+++ b/libgfortran/generated/maxloc0_8_r8.c
@@ -315,6 +315,7 @@ mmaxloc0_8_r8 (gfc_array_i8 * const restrict retarray,
 		    dest[n * dstride] = count[n] + 1;
 		}
 	      base += sstride[0];
+	      mbase += mstride[0];
 	    }
 	  while (++count[0] != extent[0]);
 	else
@@ -361,7 +362,6 @@ mmaxloc0_8_r8 (gfc_array_i8 * const restrict retarray,
   }
 }
 
-
 extern void smaxloc0_8_r8 (gfc_array_i8 * const restrict, 
 	gfc_array_r8 * const restrict, GFC_LOGICAL_4 *, GFC_LOGICAL_4);
 export_proto(smaxloc0_8_r8);
diff --git a/libgfortran/generated/minloc0_16_i1.c b/libgfortran/generated/minloc0_16_i1.c
index b769f285393..5eca4da644f 100644
--- a/libgfortran/generated/minloc0_16_i1.c
+++ b/libgfortran/generated/minloc0_16_i1.c
@@ -314,9 +314,10 @@ mminloc0_16_i1 (gfc_array_i16 * const restrict retarray,
 	      	  for (n = 0; n < rank; n++)
 		    dest[n * dstride] = count[n] + 1;
 	    	}
-		base += sstride[0];
+	      base += sstride[0];
+	      mbase += mstride[0];
 	    }
-	    while (++count[0] != extent[0]);
+	  while (++count[0] != extent[0]);
 	else
 	  do
 	    {
diff --git a/libgfortran/generated/minloc0_16_i16.c b/libgfortran/generated/minloc0_16_i16.c
index 9e19de4035b..c1569e14c6a 100644
--- a/libgfortran/generated/minloc0_16_i16.c
+++ b/libgfortran/generated/minloc0_16_i16.c
@@ -314,9 +314,10 @@ mminloc0_16_i16 (gfc_array_i16 * const restrict retarray,
 	      	  for (n = 0; n < rank; n++)
 		    dest[n * dstride] = count[n] + 1;
 	    	}
-		base += sstride[0];
+	      base += sstride[0];
+	      mbase += mstride[0];
 	    }
-	    while (++count[0] != extent[0]);
+	  while (++count[0] != extent[0]);
 	else
 	  do
 	    {
diff --git a/libgfortran/generated/minloc0_16_i2.c b/libgfortran/generated/minloc0_16_i2.c
index 3279402005a..fc01cb97590 100644
--- a/libgfortran/generated/minloc0_16_i2.c
+++ b/libgfortran/generated/minloc0_16_i2.c
@@ -314,9 +314,10 @@ mminloc0_16_i2 (gfc_array_i16 * const restrict retarray,
 	      	  for (n = 0; n < rank; n++)
 		    dest[n * dstride] = count[n] + 1;
 	    	}
-		base += sstride[0];
+	      base += sstride[0];
+	      mbase += mstride[0];
 	    }
-	    while (++count[0] != extent[0]);
+	  while (++count[0] != extent[0]);
 	else
 	  do
 	    {
diff --git a/libgfortran/generated/minloc0_16_i4.c b/libgfortran/generated/minloc0_16_i4.c
index 5cfcd838709..c6541b6cc0e 100644
--- a/libgfortran/generated/minloc0_16_i4.c
+++ b/libgfortran/generated/minloc0_16_i4.c
@@ -314,9 +314,10 @@ mminloc0_16_i4 (gfc_array_i16 * const restrict retarray,
 	      	  for (n = 0; n < rank; n++)
 		    dest[n * dstride] = count[n] + 1;
 	    	}
-		base += sstride[0];
+	      base += sstride[0];
+	      mbase += mstride[0];
 	    }
-	    while (++count[0] != extent[0]);
+	  while (++count[0] != extent[0]);
 	else
 	  do
 	    {
diff --git a/libgfortran/generated/minloc0_16_i8.c b/libgfortran/generated/minloc0_16_i8.c
index 34956495d03..86b73cfdd63 100644
--- a/libgfortran/generated/minloc0_16_i8.c
+++ b/libgfortran/generated/minloc0_16_i8.c
@@ -314,9 +314,10 @@ mminloc0_16_i8 (gfc_array_i16 * const restrict retarray,
 	      	  for (n = 0; n < rank; n++)
 		    dest[n * dstride] = count[n] + 1;
 	    	}
-		base += sstride[0];
+	      base += sstride[0];
+	      mbase += mstride[0];
 	    }
-	    while (++count[0] != extent[0]);
+	  while (++count[0] != extent[0]);
 	else
 	  do
 	    {
diff --git a/libgfortran/generated/minloc0_16_m1.c b/libgfortran/generated/minloc0_16_m1.c
index dfd2ccbf363..4d022eb848d 100644
--- a/libgfortran/generated/minloc0_16_m1.c
+++ b/libgfortran/generated/minloc0_16_m1.c
@@ -314,9 +314,10 @@ mminloc0_16_m1 (gfc_array_i16 * const restrict retarray,
 	      	  for (n = 0; n < rank; n++)
 		    dest[n * dstride] = count[n] + 1;
 	    	}
-		base += sstride[0];
+	      base += sstride[0];
+	      mbase += mstride[0];
 	    }
-	    while (++count[0] != extent[0]);
+	  while (++count[0] != extent[0]);
 	else
 	  do
 	    {
diff --git a/libgfortran/generated/minloc0_16_m16.c b/libgfortran/generated/minloc0_16_m16.c
index a5d777f6099..ecbb5238a31 100644
--- a/libgfortran/generated/minloc0_16_m16.c
+++ b/libgfortran/generated/minloc0_16_m16.c
@@ -314,9 +314,10 @@ mminloc0_16_m16 (gfc_array_i16 * const restrict retarray,
 	      	  for (n = 0; n < rank; n++)
 		    dest[n * dstride] = count[n] + 1;
 	    	}
-		base += sstride[0];
+	      base += sstride[0];
+	      mbase += mstride[0];
 	    }
-	    while (++count[0] != extent[0]);
+	  while (++count[0] != extent[0]);
 	else
 	  do
 	    {
diff --git a/libgfortran/generated/minloc0_16_m2.c b/libgfortran/generated/minloc0_16_m2.c
index 8ebd57f9e13..a11e0b1fd34 100644
--- a/libgfortran/generated/minloc0_16_m2.c
+++ b/libgfortran/generated/minloc0_16_m2.c
@@ -314,9 +314,10 @@ mminloc0_16_m2 (gfc_array_i16 * const restrict retarray,
 	      	  for (n = 0; n < rank; n++)
 		    dest[n * dstride] = count[n] + 1;
 	    	}
-		base += sstride[0];
+	      base += sstride[0];
+	      mbase += mstride[0];
 	    }
-	    while (++count[0] != extent[0]);
+	  while (++count[0] != extent[0]);
 	else
 	  do
 	    {
diff --git a/libgfortran/generated/minloc0_16_m4.c b/libgfortran/generated/minloc0_16_m4.c
index 12852f297b3..9c3877f3b61 100644
--- a/libgfortran/generated/minloc0_16_m4.c
+++ b/libgfortran/generated/minloc0_16_m4.c
@@ -314,9 +314,10 @@ mminloc0_16_m4 (gfc_array_i16 * const restrict retarray,
 	      	  for (n = 0; n < rank; n++)
 		    dest[n * dstride] = count[n] + 1;
 	    	}
-		base += sstride[0];
+	      base += sstride[0];
+	      mbase += mstride[0];
 	    }
-	    while (++count[0] != extent[0]);
+	  while (++count[0] != extent[0]);
 	else
 	  do
 	    {
diff --git a/libgfortran/generated/minloc0_16_m8.c b/libgfortran/generated/minloc0_16_m8.c
index ad5a76e6fe8..bbb2eb0bb4f 100644
--- a/libgfortran/generated/minloc0_16_m8.c
+++ b/libgfortran/generated/minloc0_16_m8.c
@@ -314,9 +314,10 @@ mminloc0_16_m8 (gfc_array_i16 * const restrict retarray,
 	      	  for (n = 0; n < rank; n++)
 		    dest[n * dstride] = count[n] + 1;
 	    	}
-		base += sstride[0];
+	      base += sstride[0];
+	      mbase += mstride[0];
 	    }
-	    while (++count[0] != extent[0]);
+	  while (++count[0] != extent[0]);
 	else
 	  do
 	    {
diff --git a/libgfortran/generated/minloc0_16_r10.c b/libgfortran/generated/minloc0_16_r10.c
index 26208455879..0bfd84a0ba7 100644
--- a/libgfortran/generated/minloc0_16_r10.c
+++ b/libgfortran/generated/minloc0_16_r10.c
@@ -314,9 +314,10 @@ mminloc0_16_r10 (gfc_array_i16 * const restrict retarray,
 	      	  for (n = 0; n < rank; n++)
 		    dest[n * dstride] = count[n] + 1;
 	    	}
-		base += sstride[0];
+	      base += sstride[0];
+	      mbase += mstride[0];
 	    }
-	    while (++count[0] != extent[0]);
+	  while (++count[0] != extent[0]);
 	else
 	  do
 	    {
diff --git a/libgfortran/generated/minloc0_16_r16.c b/libgfortran/generated/minloc0_16_r16.c
index f26fc34bad8..15906543804 100644
--- a/libgfortran/generated/minloc0_16_r16.c
+++ b/libgfortran/generated/minloc0_16_r16.c
@@ -314,9 +314,10 @@ mminloc0_16_r16 (gfc_array_i16 * const restrict retarray,
 	      	  for (n = 0; n < rank; n++)
 		    dest[n * dstride] = count[n] + 1;
 	    	}
-		base += sstride[0];
+	      base += sstride[0];
+	      mbase += mstride[0];
 	    }
-	    while (++count[0] != extent[0]);
+	  while (++count[0] != extent[0]);
 	else
 	  do
 	    {
diff --git a/libgfortran/generated/minloc0_16_r17.c b/libgfortran/generated/minloc0_16_r17.c
index d18fe49d48b..1d7af7633f1 100644
--- a/libgfortran/generated/minloc0_16_r17.c
+++ b/libgfortran/generated/minloc0_16_r17.c
@@ -314,9 +314,10 @@ mminloc0_16_r17 (gfc_array_i16 * const restrict retarray,
 	      	  for (n = 0; n < rank; n++)
 		    dest[n * dstride] = count[n] + 1;
 	    	}
-		base += sstride[0];
+	      base += sstride[0];
+	      mbase += mstride[0];
 	    }
-	    while (++count[0] != extent[0]);
+	  while (++count[0] != extent[0]);
 	else
 	  do
 	    {
diff --git a/libgfortran/generated/minloc0_16_r4.c b/libgfortran/generated/minloc0_16_r4.c
index 1a128493fac..e87af9511ab 100644
--- a/libgfortran/generated/minloc0_16_r4.c
+++ b/libgfortran/generated/minloc0_16_r4.c
@@ -314,9 +314,10 @@ mminloc0_16_r4 (gfc_array_i16 * const restrict retarray,
 	      	  for (n = 0; n < rank; n++)
 		    dest[n * dstride] = count[n] + 1;
 	    	}
-		base += sstride[0];
+	      base += sstride[0];
+	      mbase += mstride[0];
 	    }
-	    while (++count[0] != extent[0]);
+	  while (++count[0] != extent[0]);
 	else
 	  do
 	    {
diff --git a/libgfortran/generated/minloc0_16_r8.c b/libgfortran/generated/minloc0_16_r8.c
index d8284b78a7d..98b0fbbfce6 100644
--- a/libgfortran/generated/minloc0_16_r8.c
+++ b/libgfortran/generated/minloc0_16_r8.c
@@ -314,9 +314,10 @@ mminloc0_16_r8 (gfc_array_i16 * const restrict retarray,
 	      	  for (n = 0; n < rank; n++)
 		    dest[n * dstride] = count[n] + 1;
 	    	}
-		base += sstride[0];
+	      base += sstride[0];
+	      mbase += mstride[0];
 	    }
-	    while (++count[0] != extent[0]);
+	  while (++count[0] != extent[0]);
 	else
 	  do
 	    {
diff --git a/libgfortran/generated/minloc0_4_i1.c b/libgfortran/generated/minloc0_4_i1.c
index 1e96d950ffa..7d8bb11c3ef 100644
--- a/libgfortran/generated/minloc0_4_i1.c
+++ b/libgfortran/generated/minloc0_4_i1.c
@@ -314,9 +314,10 @@ mminloc0_4_i1 (gfc_array_i4 * const restrict retarray,
 	      	  for (n = 0; n < rank; n++)
 		    dest[n * dstride] = count[n] + 1;
 	    	}
-		base += sstride[0];
+	      base += sstride[0];
+	      mbase += mstride[0];
 	    }
-	    while (++count[0] != extent[0]);
+	  while (++count[0] != extent[0]);
 	else
 	  do
 	    {
diff --git a/libgfortran/generated/minloc0_4_i16.c b/libgfortran/generated/minloc0_4_i16.c
index 0a70e9fcb92..ee6a7af1494 100644
--- a/libgfortran/generated/minloc0_4_i16.c
+++ b/libgfortran/generated/minloc0_4_i16.c
@@ -314,9 +314,10 @@ mminloc0_4_i16 (gfc_array_i4 * const restrict retarray,
 	      	  for (n = 0; n < rank; n++)
 		    dest[n * dstride] = count[n] + 1;
 	    	}
-		base += sstride[0];
+	      base += sstride[0];
+	      mbase += mstride[0];
 	    }
-	    while (++count[0] != extent[0]);
+	  while (++count[0] != extent[0]);
 	else
 	  do
 	    {
diff --git a/libgfortran/generated/minloc0_4_i2.c b/libgfortran/generated/minloc0_4_i2.c
index 497f6620b16..84deb721ac0 100644
--- a/libgfortran/generated/minloc0_4_i2.c
+++ b/libgfortran/generated/minloc0_4_i2.c
@@ -314,9 +314,10 @@ mminloc0_4_i2 (gfc_array_i4 * const restrict retarray,
 	      	  for (n = 0; n < rank; n++)
 		    dest[n * dstride] = count[n] + 1;
 	    	}
-		base += sstride[0];
+	      base += sstride[0];
+	      mbase += mstride[0];
 	    }
-	    while (++count[0] != extent[0]);
+	  while (++count[0] != extent[0]);
 	else
 	  do
 	    {
diff --git a/libgfortran/generated/minloc0_4_i4.c b/libgfortran/generated/minloc0_4_i4.c
index b5645fb34b8..9e71952ee38 100644
--- a/libgfortran/generated/minloc0_4_i4.c
+++ b/libgfortran/generated/minloc0_4_i4.c
@@ -314,9 +314,10 @@ mminloc0_4_i4 (gfc_array_i4 * const restrict retarray,
 	      	  for (n = 0; n < rank; n++)
 		    dest[n * dstride] = count[n] + 1;
 	    	}
-		base += sstride[0];
+	      base += sstride[0];
+	      mbase += mstride[0];
 	    }
-	    while (++count[0] != extent[0]);
+	  while (++count[0] != extent[0]);
 	else
 	  do
 	    {
diff --git a/libgfortran/generated/minloc0_4_i8.c b/libgfortran/generated/minloc0_4_i8.c
index af7bc7e7a8f..a4741771d5c 100644
--- a/libgfortran/generated/minloc0_4_i8.c
+++ b/libgfortran/generated/minloc0_4_i8.c
@@ -314,9 +314,10 @@ mminloc0_4_i8 (gfc_array_i4 * const restrict retarray,
 	      	  for (n = 0; n < rank; n++)
 		    dest[n * dstride] = count[n] + 1;
 	    	}
-		base += sstride[0];
+	      base += sstride[0];
+	      mbase += mstride[0];
 	    }
-	    while (++count[0] != extent[0]);
+	  while (++count[0] != extent[0]);
 	else
 	  do
 	    {
diff --git a/libgfortran/generated/minloc0_4_m1.c b/libgfortran/generated/minloc0_4_m1.c
index 9346ca81742..0da1233c1e8 100644
--- a/libgfortran/generated/minloc0_4_m1.c
+++ b/libgfortran/generated/minloc0_4_m1.c
@@ -314,9 +314,10 @@ mminloc0_4_m1 (gfc_array_i4 * const restrict retarray,
 	      	  for (n = 0; n < rank; n++)
 		    dest[n * dstride] = count[n] + 1;
 	    	}
-		base += sstride[0];
+	      base += sstride[0];
+	      mbase += mstride[0];
 	    }
-	    while (++count[0] != extent[0]);
+	  while (++count[0] != extent[0]);
 	else
 	  do
 	    {
diff --git a/libgfortran/generated/minloc0_4_m16.c b/libgfortran/generated/minloc0_4_m16.c
index 6ea32520954..1d92dfc93a5 100644
--- a/libgfortran/generated/minloc0_4_m16.c
+++ b/libgfortran/generated/minloc0_4_m16.c
@@ -314,9 +314,10 @@ mminloc0_4_m16 (gfc_array_i4 * const restrict retarray,
 	      	  for (n = 0; n < rank; n++)
 		    dest[n * dstride] = count[n] + 1;
 	    	}
-		base += sstride[0];
+	      base += sstride[0];
+	      mbase += mstride[0];
 	    }
-	    while (++count[0] != extent[0]);
+	  while (++count[0] != extent[0]);
 	else
 	  do
 	    {
diff --git a/libgfortran/generated/minloc0_4_m2.c b/libgfortran/generated/minloc0_4_m2.c
index 8e4b8c95cbd..2debf567e4b 100644
--- a/libgfortran/generated/minloc0_4_m2.c
+++ b/libgfortran/generated/minloc0_4_m2.c
@@ -314,9 +314,10 @@ mminloc0_4_m2 (gfc_array_i4 * const restrict retarray,
 	      	  for (n = 0; n < rank; n++)
 		    dest[n * dstride] = count[n] + 1;
 	    	}
-		base += sstride[0];
+	      base += sstride[0];
+	      mbase += mstride[0];
 	    }
-	    while (++count[0] != extent[0]);
+	  while (++count[0] != extent[0]);
 	else
 	  do
 	    {
diff --git a/libgfortran/generated/minloc0_4_m4.c b/libgfortran/generated/minloc0_4_m4.c
index 3b2def4a007..e8f7690fbef 100644
--- a/libgfortran/generated/minloc0_4_m4.c
+++ b/libgfortran/generated/minloc0_4_m4.c
@@ -314,9 +314,10 @@ mminloc0_4_m4 (gfc_array_i4 * const restrict retarray,
 	      	  for (n = 0; n < rank; n++)
 		    dest[n * dstride] = count[n] + 1;
 	    	}
-		base += sstride[0];
+	      base += sstride[0];
+	      mbase += mstride[0];
 	    }
-	    while (++count[0] != extent[0]);
+	  while (++count[0] != extent[0]);
 	else
 	  do
 	    {
diff --git a/libgfortran/generated/minloc0_4_m8.c b/libgfortran/generated/minloc0_4_m8.c
index 4359663b61f..5cbf1fba3e8 100644
--- a/libgfortran/generated/minloc0_4_m8.c
+++ b/libgfortran/generated/minloc0_4_m8.c
@@ -314,9 +314,10 @@ mminloc0_4_m8 (gfc_array_i4 * const restrict retarray,
 	      	  for (n = 0; n < rank; n++)
 		    dest[n * dstride] = count[n] + 1;
 	    	}
-		base += sstride[0];
+	      base += sstride[0];
+	      mbase += mstride[0];
 	    }
-	    while (++count[0] != extent[0]);
+	  while (++count[0] != extent[0]);
 	else
 	  do
 	    {
diff --git a/libgfortran/generated/minloc0_4_r10.c b/libgfortran/generated/minloc0_4_r10.c
index 48bd739803d..debcf4b632f 100644
--- a/libgfortran/generated/minloc0_4_r10.c
+++ b/libgfortran/generated/minloc0_4_r10.c
@@ -314,9 +314,10 @@ mminloc0_4_r10 (gfc_array_i4 * const restrict retarray,
 	      	  for (n = 0; n < rank; n++)
 		    dest[n * dstride] = count[n] + 1;
 	    	}
-		base += sstride[0];
+	      base += sstride[0];
+	      mbase += mstride[0];
 	    }
-	    while (++count[0] != extent[0]);
+	  while (++count[0] != extent[0]);
 	else
 	  do
 	    {
diff --git a/libgfortran/generated/minloc0_4_r16.c b/libgfortran/generated/minloc0_4_r16.c
index 7abee92d70d..e1c744cf49f 100644
--- a/libgfortran/generated/minloc0_4_r16.c
+++ b/libgfortran/generated/minloc0_4_r16.c
@@ -314,9 +314,10 @@ mminloc0_4_r16 (gfc_array_i4 * const restrict retarray,
 	      	  for (n = 0; n < rank; n++)
 		    dest[n * dstride] = count[n] + 1;
 	    	}
-		base += sstride[0];
+	      base += sstride[0];
+	      mbase += mstride[0];
 	    }
-	    while (++count[0] != extent[0]);
+	  while (++count[0] != extent[0]);
 	else
 	  do
 	    {
diff --git a/libgfortran/generated/minloc0_4_r17.c b/libgfortran/generated/minloc0_4_r17.c
index 00162d945fd..01db36257b2 100644
--- a/libgfortran/generated/minloc0_4_r17.c
+++ b/libgfortran/generated/minloc0_4_r17.c
@@ -314,9 +314,10 @@ mminloc0_4_r17 (gfc_array_i4 * const restrict retarray,
 	      	  for (n = 0; n < rank; n++)
 		    dest[n * dstride] = count[n] + 1;
 	    	}
-		base += sstride[0];
+	      base += sstride[0];
+	      mbase += mstride[0];
 	    }
-	    while (++count[0] != extent[0]);
+	  while (++count[0] != extent[0]);
 	else
 	  do
 	    {
diff --git a/libgfortran/generated/minloc0_4_r4.c b/libgfortran/generated/minloc0_4_r4.c
index 00ec3bbc868..737f7cb950e 100644
--- a/libgfortran/generated/minloc0_4_r4.c
+++ b/libgfortran/generated/minloc0_4_r4.c
@@ -314,9 +314,10 @@ mminloc0_4_r4 (gfc_array_i4 * const restrict retarray,
 	      	  for (n = 0; n < rank; n++)
 		    dest[n * dstride] = count[n] + 1;
 	    	}
-		base += sstride[0];
+	      base += sstride[0];
+	      mbase += mstride[0];
 	    }
-	    while (++count[0] != extent[0]);
+	  while (++count[0] != extent[0]);
 	else
 	  do
 	    {
diff --git a/libgfortran/generated/minloc0_4_r8.c b/libgfortran/generated/minloc0_4_r8.c
index 129290a0c84..657484a1f24 100644
--- a/libgfortran/generated/minloc0_4_r8.c
+++ b/libgfortran/generated/minloc0_4_r8.c
@@ -314,9 +314,10 @@ mminloc0_4_r8 (gfc_array_i4 * const restrict retarray,
 	      	  for (n = 0; n < rank; n++)
 		    dest[n * dstride] = count[n] + 1;
 	    	}
-		base += sstride[0];
+	      base += sstride[0];
+	      mbase += mstride[0];
 	    }
-	    while (++count[0] != extent[0]);
+	  while (++count[0] != extent[0]);
 	else
 	  do
 	    {
diff --git a/libgfortran/generated/minloc0_8_i1.c b/libgfortran/generated/minloc0_8_i1.c
index d0b4e902bbd..cfa36b5ad2b 100644
--- a/libgfortran/generated/minloc0_8_i1.c
+++ b/libgfortran/generated/minloc0_8_i1.c
@@ -314,9 +314,10 @@ mminloc0_8_i1 (gfc_array_i8 * const restrict retarray,
 	      	  for (n = 0; n < rank; n++)
 		    dest[n * dstride] = count[n] + 1;
 	    	}
-		base += sstride[0];
+	      base += sstride[0];
+	      mbase += mstride[0];
 	    }
-	    while (++count[0] != extent[0]);
+	  while (++count[0] != extent[0]);
 	else
 	  do
 	    {
diff --git a/libgfortran/generated/minloc0_8_i16.c b/libgfortran/generated/minloc0_8_i16.c
index 7bb8853555c..a12ab053953 100644
--- a/libgfortran/generated/minloc0_8_i16.c
+++ b/libgfortran/generated/minloc0_8_i16.c
@@ -314,9 +314,10 @@ mminloc0_8_i16 (gfc_array_i8 * const restrict retarray,
 	      	  for (n = 0; n < rank; n++)
 		    dest[n * dstride] = count[n] + 1;
 	    	}
-		base += sstride[0];
+	      base += sstride[0];
+	      mbase += mstride[0];
 	    }
-	    while (++count[0] != extent[0]);
+	  while (++count[0] != extent[0]);
 	else
 	  do
 	    {
diff --git a/libgfortran/generated/minloc0_8_i2.c b/libgfortran/generated/minloc0_8_i2.c
index 875338e3012..17765908411 100644
--- a/libgfortran/generated/minloc0_8_i2.c
+++ b/libgfortran/generated/minloc0_8_i2.c
@@ -314,9 +314,10 @@ mminloc0_8_i2 (gfc_array_i8 * const restrict retarray,
 	      	  for (n = 0; n < rank; n++)
 		    dest[n * dstride] = count[n] + 1;
 	    	}
-		base += sstride[0];
+	      base += sstride[0];
+	      mbase += mstride[0];
 	    }
-	    while (++count[0] != extent[0]);
+	  while (++count[0] != extent[0]);
 	else
 	  do
 	    {
diff --git a/libgfortran/generated/minloc0_8_i4.c b/libgfortran/generated/minloc0_8_i4.c
index 3fcefcdae0e..a85a08c2124 100644
--- a/libgfortran/generated/minloc0_8_i4.c
+++ b/libgfortran/generated/minloc0_8_i4.c
@@ -314,9 +314,10 @@ mminloc0_8_i4 (gfc_array_i8 * const restrict retarray,
 	      	  for (n = 0; n < rank; n++)
 		    dest[n * dstride] = count[n] + 1;
 	    	}
-		base += sstride[0];
+	      base += sstride[0];
+	      mbase += mstride[0];
 	    }
-	    while (++count[0] != extent[0]);
+	  while (++count[0] != extent[0]);
 	else
 	  do
 	    {
diff --git a/libgfortran/generated/minloc0_8_i8.c b/libgfortran/generated/minloc0_8_i8.c
index 7c3f727d5d8..90533b6e8e3 100644
--- a/libgfortran/generated/minloc0_8_i8.c
+++ b/libgfortran/generated/minloc0_8_i8.c
@@ -314,9 +314,10 @@ mminloc0_8_i8 (gfc_array_i8 * const restrict retarray,
 	      	  for (n = 0; n < rank; n++)
 		    dest[n * dstride] = count[n] + 1;
 	    	}
-		base += sstride[0];
+	      base += sstride[0];
+	      mbase += mstride[0];
 	    }
-	    while (++count[0] != extent[0]);
+	  while (++count[0] != extent[0]);
 	else
 	  do
 	    {
diff --git a/libgfortran/generated/minloc0_8_m1.c b/libgfortran/generated/minloc0_8_m1.c
index 5bd6070b16c..b1305999e3c 100644
--- a/libgfortran/generated/minloc0_8_m1.c
+++ b/libgfortran/generated/minloc0_8_m1.c
@@ -314,9 +314,10 @@ mminloc0_8_m1 (gfc_array_i8 * const restrict retarray,
 	      	  for (n = 0; n < rank; n++)
 		    dest[n * dstride] = count[n] + 1;
 	    	}
-		base += sstride[0];
+	      base += sstride[0];
+	      mbase += mstride[0];
 	    }
-	    while (++count[0] != extent[0]);
+	  while (++count[0] != extent[0]);
 	else
 	  do
 	    {
diff --git a/libgfortran/generated/minloc0_8_m16.c b/libgfortran/generated/minloc0_8_m16.c
index c8a705205a0..6fc1d06b052 100644
--- a/libgfortran/generated/minloc0_8_m16.c
+++ b/libgfortran/generated/minloc0_8_m16.c
@@ -314,9 +314,10 @@ mminloc0_8_m16 (gfc_array_i8 * const restrict retarray,
 	      	  for (n = 0; n < rank; n++)
 		    dest[n * dstride] = count[n] + 1;
 	    	}
-		base += sstride[0];
+	      base += sstride[0];
+	      mbase += mstride[0];
 	    }
-	    while (++count[0] != extent[0]);
+	  while (++count[0] != extent[0]);
 	else
 	  do
 	    {
diff --git a/libgfortran/generated/minloc0_8_m2.c b/libgfortran/generated/minloc0_8_m2.c
index f6501975ce5..428594dab10 100644
--- a/libgfortran/generated/minloc0_8_m2.c
+++ b/libgfortran/generated/minloc0_8_m2.c
@@ -314,9 +314,10 @@ mminloc0_8_m2 (gfc_array_i8 * const restrict retarray,
 	      	  for (n = 0; n < rank; n++)
 		    dest[n * dstride] = count[n] + 1;
 	    	}
-		base += sstride[0];
+	      base += sstride[0];
+	      mbase += mstride[0];
 	    }
-	    while (++count[0] != extent[0]);
+	  while (++count[0] != extent[0]);
 	else
 	  do
 	    {
diff --git a/libgfortran/generated/minloc0_8_m4.c b/libgfortran/generated/minloc0_8_m4.c
index 50a86ea0c97..81df40cb9eb 100644
--- a/libgfortran/generated/minloc0_8_m4.c
+++ b/libgfortran/generated/minloc0_8_m4.c
@@ -314,9 +314,10 @@ mminloc0_8_m4 (gfc_array_i8 * const restrict retarray,
 	      	  for (n = 0; n < rank; n++)
 		    dest[n * dstride] = count[n] + 1;
 	    	}
-		base += sstride[0];
+	      base += sstride[0];
+	      mbase += mstride[0];
 	    }
-	    while (++count[0] != extent[0]);
+	  while (++count[0] != extent[0]);
 	else
 	  do
 	    {
diff --git a/libgfortran/generated/minloc0_8_m8.c b/libgfortran/generated/minloc0_8_m8.c
index 54bc8ab01ac..221c692173f 100644
--- a/libgfortran/generated/minloc0_8_m8.c
+++ b/libgfortran/generated/minloc0_8_m8.c
@@ -314,9 +314,10 @@ mminloc0_8_m8 (gfc_array_i8 * const restrict retarray,
 	      	  for (n = 0; n < rank; n++)
 		    dest[n * dstride] = count[n] + 1;
 	    	}
-		base += sstride[0];
+	      base += sstride[0];
+	      mbase += mstride[0];
 	    }
-	    while (++count[0] != extent[0]);
+	  while (++count[0] != extent[0]);
 	else
 	  do
 	    {
diff --git a/libgfortran/generated/minloc0_8_r10.c b/libgfortran/generated/minloc0_8_r10.c
index f3f302b9187..9ad7e2d5c4a 100644
--- a/libgfortran/generated/minloc0_8_r10.c
+++ b/libgfortran/generated/minloc0_8_r10.c
@@ -314,9 +314,10 @@ mminloc0_8_r10 (gfc_array_i8 * const restrict retarray,
 	      	  for (n = 0; n < rank; n++)
 		    dest[n * dstride] = count[n] + 1;
 	    	}
-		base += sstride[0];
+	      base += sstride[0];
+	      mbase += mstride[0];
 	    }
-	    while (++count[0] != extent[0]);
+	  while (++count[0] != extent[0]);
 	else
 	  do
 	    {
diff --git a/libgfortran/generated/minloc0_8_r16.c b/libgfortran/generated/minloc0_8_r16.c
index e05a1eec8fd..12aa9ecfb8e 100644
--- a/libgfortran/generated/minloc0_8_r16.c
+++ b/libgfortran/generated/minloc0_8_r16.c
@@ -314,9 +314,10 @@ mminloc0_8_r16 (gfc_array_i8 * const restrict retarray,
 	      	  for (n = 0; n < rank; n++)
 		    dest[n * dstride] = count[n] + 1;
 	    	}
-		base += sstride[0];
+	      base += sstride[0];
+	      mbase += mstride[0];
 	    }
-	    while (++count[0] != extent[0]);
+	  while (++count[0] != extent[0]);
 	else
 	  do
 	    {
diff --git a/libgfortran/generated/minloc0_8_r17.c b/libgfortran/generated/minloc0_8_r17.c
index 23502a0de85..ef20ac74b0a 100644
--- a/libgfortran/generated/minloc0_8_r17.c
+++ b/libgfortran/generated/minloc0_8_r17.c
@@ -314,9 +314,10 @@ mminloc0_8_r17 (gfc_array_i8 * const restrict retarray,
 	      	  for (n = 0; n < rank; n++)
 		    dest[n * dstride] = count[n] + 1;
 	    	}
-		base += sstride[0];
+	      base += sstride[0];
+	      mbase += mstride[0];
 	    }
-	    while (++count[0] != extent[0]);
+	  while (++count[0] != extent[0]);
 	else
 	  do
 	    {
diff --git a/libgfortran/generated/minloc0_8_r4.c b/libgfortran/generated/minloc0_8_r4.c
index 88c895798d6..1ea99b97d9e 100644
--- a/libgfortran/generated/minloc0_8_r4.c
+++ b/libgfortran/generated/minloc0_8_r4.c
@@ -314,9 +314,10 @@ mminloc0_8_r4 (gfc_array_i8 * const restrict retarray,
 	      	  for (n = 0; n < rank; n++)
 		    dest[n * dstride] = count[n] + 1;
 	    	}
-		base += sstride[0];
+	      base += sstride[0];
+	      mbase += mstride[0];
 	    }
-	    while (++count[0] != extent[0]);
+	  while (++count[0] != extent[0]);
 	else
 	  do
 	    {
diff --git a/libgfortran/generated/minloc0_8_r8.c b/libgfortran/generated/minloc0_8_r8.c
index a8826688ce5..e87eaaec46e 100644
--- a/libgfortran/generated/minloc0_8_r8.c
+++ b/libgfortran/generated/minloc0_8_r8.c
@@ -314,9 +314,10 @@ mminloc0_8_r8 (gfc_array_i8 * const restrict retarray,
 	      	  for (n = 0; n < rank; n++)
 		    dest[n * dstride] = count[n] + 1;
 	    	}
-		base += sstride[0];
+	      base += sstride[0];
+	      mbase += mstride[0];
 	    }
-	    while (++count[0] != extent[0]);
+	  while (++count[0] != extent[0]);
 	else
 	  do
 	    {
diff --git a/libgfortran/m4/maxloc0.m4 b/libgfortran/m4/maxloc0.m4
index 45663db15da..b0b94402b59 100644
--- a/libgfortran/m4/maxloc0.m4
+++ b/libgfortran/m4/maxloc0.m4
@@ -131,6 +131,7 @@ MASKED_FOREACH_FUNCTION(
 		    dest[n * dstride] = count[n] + 1;
 		}
 	      base += sstride[0];
+	      mbase += mstride[0];
 	    }
 	  while (++count[0] != extent[0]);
 	else
@@ -142,6 +143,5 @@ MASKED_FOREACH_FUNCTION(
 		  for (n = 0; n < rank; n++)
 		    dest[n * dstride] = count[n] + 1;
 	        }')
-
 SCALAR_FOREACH_FUNCTION(`0')
 #endif
diff --git a/libgfortran/m4/minloc0.m4 b/libgfortran/m4/minloc0.m4
index c7aed686452..31871d89848 100644
--- a/libgfortran/m4/minloc0.m4
+++ b/libgfortran/m4/minloc0.m4
@@ -130,9 +130,10 @@ MASKED_FOREACH_FUNCTION(
 	      	  for (n = 0; n < rank; n++)
 		    dest[n * dstride] = count[n] + 1;
 	    	}
-		base += sstride[0];
+	      base += sstride[0];
+	      mbase += mstride[0];
 	    }
-	    while (++count[0] != extent[0]);
+	  while (++count[0] != extent[0]);
 	else
 	  do
 	    {
-- 
2.51.0

Reply via email to