Use pointer sized array indices.

Message ID 1514564021-3546-1-git-send-email-blomqvist.janne@gmail.com
State New
Headers show
Series
  • Use pointer sized array indices.
Related show

Commit Message

Janne Blomqvist Dec. 29, 2017, 4:13 p.m.
Using pointer sized variables (e.g. size_t / ptrdiff_t) when the
variables are used as array indices allows accessing larger arrays,
and can be a slight performance improvement due to no need for sign or
zero extending, or masking.

Regtested on x86_64-pc-linux-gnu, Ok for trunk?

libgfortran/ChangeLog:

2017-12-29  Janne Blomqvist  <jb@gcc.gnu.org>

	* generated/cshift1_16.c (cshift1): Regenerated.
	* generated/cshift1_4.c (cshift1): Regenerated.
	* generated/cshift1_8.c (cshift1): Regenerated.
	* generated/eoshift1_16.c (eoshift1): Regenerated.
	* generated/eoshift1_4.c (eoshift1): Regenerated.
	* generated/eoshift1_8.c (eoshift1): Regenerated.
	* generated/eoshift3_16.c (eoshift3): Regenerated.
	* generated/eoshift3_4.c (eoshift3): Regenerated.
	* generated/eoshift3_8.c (eoshift3): Regenerated.
	* generated/in_pack_c10.c (internal_pack_c10): Regenerated.
	* generated/in_pack_c16.c (internal_pack_c16): Regenerated.
	* generated/in_pack_c4.c (internal_pack_c4): Regenerated.
	* generated/in_pack_c8.c (internal_pack_c8): Regenerated.
	* generated/in_pack_i1.c (internal_pack_1): Regenerated.
	* generated/in_pack_i16.c (internal_pack_16): Regenerated.
	* generated/in_pack_i2.c (internal_pack_2): Regenerated.
	* generated/in_pack_i4.c (internal_pack_4): Regenerated.
	* generated/in_pack_i8.c (internal_pack_8): Regenerated.
	* generated/in_pack_r10.c (internal_pack_r10): Regenerated.
	* generated/in_pack_r16.c (internal_pack_r16): Regenerated.
	* generated/in_pack_r4.c (internal_pack_r4): Regenerated.
	* generated/in_pack_r8.c (internal_pack_r8): Regenerated.
	* generated/in_unpack_c10.c (internal_unpack_c10): Regenerated.
	* generated/in_unpack_c16.c (internal_unpack_c16): Regenerated.
	* generated/in_unpack_c4.c (internal_unpack_c4): Regenerated.
	* generated/in_unpack_c8.c (internal_unpack_c8): Regenerated.
	* generated/in_unpack_i1.c (internal_unpack_1): Regenerated.
	* generated/in_unpack_i16.c (internal_unpack_16): Regenerated.
	* generated/in_unpack_i2.c (internal_unpack_2): Regenerated.
	* generated/in_unpack_i4.c (internal_unpack_4): Regenerated.
	* generated/in_unpack_i8.c (internal_unpack_8): Regenerated.
	* generated/in_unpack_r10.c (internal_unpack_r10): Regenerated.
	* generated/in_unpack_r16.c (internal_unpack_r16): Regenerated.
	* generated/in_unpack_r4.c (internal_unpack_r4): Regenerated.
	* generated/in_unpack_r8.c (internal_unpack_r8): Regenerated.
	* generated/reshape_c10.c (reshape_c10): Regenerated.
	* generated/reshape_c16.c (reshape_c16): Regenerated.
	* generated/reshape_c4.c (reshape_c4): Regenerated.
	* generated/reshape_c8.c (reshape_c8): Regenerated.
	* generated/reshape_i16.c (reshape_16): Regenerated.
	* generated/reshape_i4.c (reshape_4): Regenerated.
	* generated/reshape_i8.c (reshape_8): Regenerated.
	* generated/reshape_r10.c (reshape_r10): Regenerated.
	* generated/reshape_r16.c (reshape_r16): Regenerated.
	* generated/reshape_r4.c (reshape_r4): Regenerated.
	* generated/reshape_r8.c (reshape_r8): Regenerated.
	* generated/shape_i1.c (shape_1): Regenerated.
	* generated/shape_i16.c (shape_16): Regenerated.
	* generated/shape_i2.c (shape_2): Regenerated.
	* generated/shape_i4.c (shape_4): Regenerated.
	* generated/shape_i8.c (shape_8): Regenerated.
	* generated/spread_c10.c (spread_scalar_c10): Regenerated.
	* generated/spread_c16.c (spread_scalar_c16): Regenerated.
	* generated/spread_c4.c (spread_scalar_c4): Regenerated.
	* generated/spread_c8.c (spread_scalar_c8): Regenerated.
	* generated/spread_i1.c (spread_scalar_i1): Regenerated.
	* generated/spread_i16.c (spread_scalar_i16): Regenerated.
	* generated/spread_i2.c (spread_scalar_i2): Regenerated.
	* generated/spread_i4.c (spread_scalar_i4): Regenerated.
	* generated/spread_i8.c (spread_scalar_i8): Regenerated.
	* generated/spread_r10.c (spread_scalar_r10): Regenerated.
	* generated/spread_r16.c (spread_scalar_r16): Regenerated.
	* generated/spread_r4.c (spread_scalar_r4): Regenerated.
	* generated/spread_r8.c (spread_scalar_r8): Regenerated.
	* intrinsics/random.c (jump): Use size_t for array index in loop.
	(getosrandom): Likewise.
	(arandom_r4): Make n an index_type.
	(arandom_r8): Likewise.
	(arandom_r10): Likewise.
	(arandom_r16): Likewise.
	(scramble_seed): Use size_t for array index in loop.
	* m4/cshift1.m4: Make i an index_type.
	* m4/eoshift1.m4: Likewise.
	* m4/eoshift3.m4: Likewise.
	* m4/in_pack.m4: Make n an index_type.
	* m4/in_unpack.m4: Likewise.
	* m4/reshape.m4: Make n and dim index_type's.
	* m4/shape.m4: Make n an index_type.
	* m4/spread.m4: Likewise, use index_type argument rather than
	copying to int.
	* runtime/bounds.c (bounds_ifunction_return): Make n an
	index_type.
	* runtime/in_pack_generic.c (internal_pack): Likewise.
	* runtime/in_unpack_generic.c (internal_unpack): Make n and size
	index_type's.
---
 libgfortran/generated/cshift1_16.c      |  4 +---
 libgfortran/generated/cshift1_4.c       |  4 +---
 libgfortran/generated/cshift1_8.c       |  4 +---
 libgfortran/generated/eoshift1_16.c     |  4 +---
 libgfortran/generated/eoshift1_4.c      |  4 +---
 libgfortran/generated/eoshift1_8.c      |  4 +---
 libgfortran/generated/eoshift3_16.c     |  4 +---
 libgfortran/generated/eoshift3_4.c      |  4 +---
 libgfortran/generated/eoshift3_8.c      |  4 +---
 libgfortran/generated/in_pack_c10.c     |  5 ++---
 libgfortran/generated/in_pack_c16.c     |  5 ++---
 libgfortran/generated/in_pack_c4.c      |  5 ++---
 libgfortran/generated/in_pack_c8.c      |  5 ++---
 libgfortran/generated/in_pack_i1.c      |  5 ++---
 libgfortran/generated/in_pack_i16.c     |  5 ++---
 libgfortran/generated/in_pack_i2.c      |  5 ++---
 libgfortran/generated/in_pack_i4.c      |  5 ++---
 libgfortran/generated/in_pack_i8.c      |  5 ++---
 libgfortran/generated/in_pack_r10.c     |  5 ++---
 libgfortran/generated/in_pack_r16.c     |  5 ++---
 libgfortran/generated/in_pack_r4.c      |  5 ++---
 libgfortran/generated/in_pack_r8.c      |  5 ++---
 libgfortran/generated/in_unpack_c10.c   |  5 ++---
 libgfortran/generated/in_unpack_c16.c   |  5 ++---
 libgfortran/generated/in_unpack_c4.c    |  5 ++---
 libgfortran/generated/in_unpack_c8.c    |  5 ++---
 libgfortran/generated/in_unpack_i1.c    |  5 ++---
 libgfortran/generated/in_unpack_i16.c   |  5 ++---
 libgfortran/generated/in_unpack_i2.c    |  5 ++---
 libgfortran/generated/in_unpack_i4.c    |  5 ++---
 libgfortran/generated/in_unpack_i8.c    |  5 ++---
 libgfortran/generated/in_unpack_r10.c   |  5 ++---
 libgfortran/generated/in_unpack_r16.c   |  5 ++---
 libgfortran/generated/in_unpack_r4.c    |  5 ++---
 libgfortran/generated/in_unpack_r8.c    |  5 ++---
 libgfortran/generated/reshape_c10.c     | 27 +++++++++++++--------------
 libgfortran/generated/reshape_c16.c     | 27 +++++++++++++--------------
 libgfortran/generated/reshape_c4.c      | 27 +++++++++++++--------------
 libgfortran/generated/reshape_c8.c      | 27 +++++++++++++--------------
 libgfortran/generated/reshape_i16.c     | 27 +++++++++++++--------------
 libgfortran/generated/reshape_i4.c      | 27 +++++++++++++--------------
 libgfortran/generated/reshape_i8.c      | 27 +++++++++++++--------------
 libgfortran/generated/reshape_r10.c     | 27 +++++++++++++--------------
 libgfortran/generated/reshape_r16.c     | 27 +++++++++++++--------------
 libgfortran/generated/reshape_r4.c      | 27 +++++++++++++--------------
 libgfortran/generated/reshape_r8.c      | 27 +++++++++++++--------------
 libgfortran/generated/shape_i1.c        |  6 ++----
 libgfortran/generated/shape_i16.c       |  6 ++----
 libgfortran/generated/shape_i2.c        |  6 ++----
 libgfortran/generated/shape_i4.c        |  6 ++----
 libgfortran/generated/shape_i8.c        |  6 ++----
 libgfortran/generated/spread_c10.c      |  6 ++----
 libgfortran/generated/spread_c16.c      |  6 ++----
 libgfortran/generated/spread_c4.c       |  6 ++----
 libgfortran/generated/spread_c8.c       |  6 ++----
 libgfortran/generated/spread_i1.c       |  6 ++----
 libgfortran/generated/spread_i16.c      |  6 ++----
 libgfortran/generated/spread_i2.c       |  6 ++----
 libgfortran/generated/spread_i4.c       |  6 ++----
 libgfortran/generated/spread_i8.c       |  6 ++----
 libgfortran/generated/spread_r10.c      |  6 ++----
 libgfortran/generated/spread_r16.c      |  6 ++----
 libgfortran/generated/spread_r4.c       |  6 ++----
 libgfortran/generated/spread_r8.c       |  6 ++----
 libgfortran/intrinsics/random.c         | 27 +++++++++++----------------
 libgfortran/m4/cshift1.m4               |  4 +---
 libgfortran/m4/eoshift1.m4              |  4 +---
 libgfortran/m4/eoshift3.m4              |  4 +---
 libgfortran/m4/in_pack.m4               |  5 ++---
 libgfortran/m4/in_unpack.m4             |  5 ++---
 libgfortran/m4/reshape.m4               | 27 +++++++++++++--------------
 libgfortran/m4/shape.m4                 |  6 ++----
 libgfortran/m4/spread.m4                |  6 ++----
 libgfortran/runtime/bounds.c            |  5 ++---
 libgfortran/runtime/in_pack_generic.c   |  5 ++---
 libgfortran/runtime/in_unpack_generic.c |  7 +++----
 76 files changed, 282 insertions(+), 394 deletions(-)

-- 
2.7.4

Comments

Thomas Koenig Dec. 29, 2017, 5:17 p.m. | #1
Hi Janne,

> Using pointer sized variables (e.g. size_t / ptrdiff_t) when the

> variables are used as array indices allows accessing larger arrays,

> and can be a slight performance improvement due to no need for sign or

> zero extending, or masking.


Unless I have missed something, all the examples are for cases where
the array is of maximum size GFC_MAX_DIMENSIONS.  This is why they
were left as int in the first place (because it is unlikely we will have
arrays of more than 2^31-1 dimensions soon :-).

Do you really think this change is necessary? If not, I'd rather avoid
such a change.

Regards

	Thomas
Janne Blomqvist Dec. 29, 2017, 6:28 p.m. | #2
On Fri, Dec 29, 2017 at 7:17 PM, Thomas Koenig <tkoenig@netcologne.de> wrote:
> Hi Janne,

>

>> Using pointer sized variables (e.g. size_t / ptrdiff_t) when the

>> variables are used as array indices allows accessing larger arrays,

>> and can be a slight performance improvement due to no need for sign or

>> zero extending, or masking.

>

>

> Unless I have missed something, all the examples are for cases where

> the array is of maximum size GFC_MAX_DIMENSIONS.


Many, but not all.

> This is why they

> were left as int in the first place (because it is unlikely we will have

> arrays of more than 2^31-1 dimensions soon :-).

>

> Do you really think this change is necessary? If not, I'd rather avoid

> such a change.


I'm not planning on supporting > 2**31-1 dimensions, no. :)

But even if we know that the maximum value is always going to be
smaller, by using pointer-sized variables the compiler can generate
slightly more efficient code.

See e.g. https://godbolt.org/g/oAvw5L ; in the functions with a loop,
the ones which use pointer-sized indices have shorter preambles as
well as loop bodies. And for the simple functions that just index an
array, by using pointer-sized indices there is no need to zero the
upper half of the registers.

I mean, it's not a huge improvement, but it might be a tiny one in some cases.

Also, by moving the induction variable from the beginning of the
function into the loop header, it makes it easier for both readers and
the compiler to see the scope of the variable.

-- 
Janne Blomqvist
Janne Blomqvist Jan. 17, 2018, 6:02 p.m. | #3
PING

On Fri, Dec 29, 2017 at 8:28 PM, Janne Blomqvist
<blomqvist.janne@gmail.com> wrote:
> On Fri, Dec 29, 2017 at 7:17 PM, Thomas Koenig <tkoenig@netcologne.de> wrote:

>> Hi Janne,

>>

>>> Using pointer sized variables (e.g. size_t / ptrdiff_t) when the

>>> variables are used as array indices allows accessing larger arrays,

>>> and can be a slight performance improvement due to no need for sign or

>>> zero extending, or masking.

>>

>>

>> Unless I have missed something, all the examples are for cases where

>> the array is of maximum size GFC_MAX_DIMENSIONS.

>

> Many, but not all.

>

>> This is why they

>> were left as int in the first place (because it is unlikely we will have

>> arrays of more than 2^31-1 dimensions soon :-).

>>

>> Do you really think this change is necessary? If not, I'd rather avoid

>> such a change.

>

> I'm not planning on supporting > 2**31-1 dimensions, no. :)

>

> But even if we know that the maximum value is always going to be

> smaller, by using pointer-sized variables the compiler can generate

> slightly more efficient code.

>

> See e.g. https://godbolt.org/g/oAvw5L ; in the functions with a loop,

> the ones which use pointer-sized indices have shorter preambles as

> well as loop bodies. And for the simple functions that just index an

> array, by using pointer-sized indices there is no need to zero the

> upper half of the registers.

>

> I mean, it's not a huge improvement, but it might be a tiny one in some cases.

>

> Also, by moving the induction variable from the beginning of the

> function into the loop header, it makes it easier for both readers and

> the compiler to see the scope of the variable.

>

> --

> Janne Blomqvist




-- 
Janne Blomqvist
Janne Blomqvist Jan. 30, 2018, 4:26 p.m. | #4
PING**2

On Wed, Jan 17, 2018 at 8:02 PM, Janne Blomqvist
<blomqvist.janne@gmail.com> wrote:
> PING

>

> On Fri, Dec 29, 2017 at 8:28 PM, Janne Blomqvist

> <blomqvist.janne@gmail.com> wrote:

>> On Fri, Dec 29, 2017 at 7:17 PM, Thomas Koenig <tkoenig@netcologne.de> wrote:

>>> Hi Janne,

>>>

>>>> Using pointer sized variables (e.g. size_t / ptrdiff_t) when the

>>>> variables are used as array indices allows accessing larger arrays,

>>>> and can be a slight performance improvement due to no need for sign or

>>>> zero extending, or masking.

>>>

>>>

>>> Unless I have missed something, all the examples are for cases where

>>> the array is of maximum size GFC_MAX_DIMENSIONS.

>>

>> Many, but not all.

>>

>>> This is why they

>>> were left as int in the first place (because it is unlikely we will have

>>> arrays of more than 2^31-1 dimensions soon :-).

>>>

>>> Do you really think this change is necessary? If not, I'd rather avoid

>>> such a change.

>>

>> I'm not planning on supporting > 2**31-1 dimensions, no. :)

>>

>> But even if we know that the maximum value is always going to be

>> smaller, by using pointer-sized variables the compiler can generate

>> slightly more efficient code.

>>

>> See e.g. https://godbolt.org/g/oAvw5L ; in the functions with a loop,

>> the ones which use pointer-sized indices have shorter preambles as

>> well as loop bodies. And for the simple functions that just index an

>> array, by using pointer-sized indices there is no need to zero the

>> upper half of the registers.

>>

>> I mean, it's not a huge improvement, but it might be a tiny one in some cases.

>>

>> Also, by moving the induction variable from the beginning of the

>> function into the loop header, it makes it easier for both readers and

>> the compiler to see the scope of the variable.

>>

>> --

>> Janne Blomqvist

>

>

>

> --

> Janne Blomqvist




-- 
Janne Blomqvist
Thomas Koenig Jan. 30, 2018, 6:40 p.m. | #5
Hi Janne,

> PING**2


OK.

Regards, Thomas

Patch

diff --git a/libgfortran/generated/cshift1_16.c b/libgfortran/generated/cshift1_16.c
index eb7a83b..f91af8a 100644
--- a/libgfortran/generated/cshift1_16.c
+++ b/libgfortran/generated/cshift1_16.c
@@ -77,12 +77,10 @@  cshift1 (gfc_array_char * const restrict ret,
 
   if (ret->base_addr == NULL)
     {
-      int i;
-
       ret->base_addr = xmallocarray (arraysize, size);
       ret->offset = 0;
       ret->dtype = array->dtype;
-      for (i = 0; i < GFC_DESCRIPTOR_RANK (array); i++)
+      for (index_type i = 0; i < GFC_DESCRIPTOR_RANK (array); i++)
         {
 	  index_type ub, str;
 
diff --git a/libgfortran/generated/cshift1_4.c b/libgfortran/generated/cshift1_4.c
index b753f23..d3e8fae 100644
--- a/libgfortran/generated/cshift1_4.c
+++ b/libgfortran/generated/cshift1_4.c
@@ -77,12 +77,10 @@  cshift1 (gfc_array_char * const restrict ret,
 
   if (ret->base_addr == NULL)
     {
-      int i;
-
       ret->base_addr = xmallocarray (arraysize, size);
       ret->offset = 0;
       ret->dtype = array->dtype;
-      for (i = 0; i < GFC_DESCRIPTOR_RANK (array); i++)
+      for (index_type i = 0; i < GFC_DESCRIPTOR_RANK (array); i++)
         {
 	  index_type ub, str;
 
diff --git a/libgfortran/generated/cshift1_8.c b/libgfortran/generated/cshift1_8.c
index 1acfd38..83c182d 100644
--- a/libgfortran/generated/cshift1_8.c
+++ b/libgfortran/generated/cshift1_8.c
@@ -77,12 +77,10 @@  cshift1 (gfc_array_char * const restrict ret,
 
   if (ret->base_addr == NULL)
     {
-      int i;
-
       ret->base_addr = xmallocarray (arraysize, size);
       ret->offset = 0;
       ret->dtype = array->dtype;
-      for (i = 0; i < GFC_DESCRIPTOR_RANK (array); i++)
+      for (index_type i = 0; i < GFC_DESCRIPTOR_RANK (array); i++)
         {
 	  index_type ub, str;
 
diff --git a/libgfortran/generated/eoshift1_16.c b/libgfortran/generated/eoshift1_16.c
index fe2e8ef..3fb4a3d 100644
--- a/libgfortran/generated/eoshift1_16.c
+++ b/libgfortran/generated/eoshift1_16.c
@@ -84,11 +84,9 @@  eoshift1 (gfc_array_char * const restrict ret,
   arraysize = size0 ((array_t *) array);
   if (ret->base_addr == NULL)
     {
-      int i;
-
       ret->offset = 0;
       ret->dtype = array->dtype;
-      for (i = 0; i < GFC_DESCRIPTOR_RANK (array); i++)
+      for (index_type i = 0; i < GFC_DESCRIPTOR_RANK (array); i++)
         {
 	  index_type ub, str;
 
diff --git a/libgfortran/generated/eoshift1_4.c b/libgfortran/generated/eoshift1_4.c
index a90fc21..ec3ad44 100644
--- a/libgfortran/generated/eoshift1_4.c
+++ b/libgfortran/generated/eoshift1_4.c
@@ -84,11 +84,9 @@  eoshift1 (gfc_array_char * const restrict ret,
   arraysize = size0 ((array_t *) array);
   if (ret->base_addr == NULL)
     {
-      int i;
-
       ret->offset = 0;
       ret->dtype = array->dtype;
-      for (i = 0; i < GFC_DESCRIPTOR_RANK (array); i++)
+      for (index_type i = 0; i < GFC_DESCRIPTOR_RANK (array); i++)
         {
 	  index_type ub, str;
 
diff --git a/libgfortran/generated/eoshift1_8.c b/libgfortran/generated/eoshift1_8.c
index 8be1e05..8228cd9 100644
--- a/libgfortran/generated/eoshift1_8.c
+++ b/libgfortran/generated/eoshift1_8.c
@@ -84,11 +84,9 @@  eoshift1 (gfc_array_char * const restrict ret,
   arraysize = size0 ((array_t *) array);
   if (ret->base_addr == NULL)
     {
-      int i;
-
       ret->offset = 0;
       ret->dtype = array->dtype;
-      for (i = 0; i < GFC_DESCRIPTOR_RANK (array); i++)
+      for (index_type i = 0; i < GFC_DESCRIPTOR_RANK (array); i++)
         {
 	  index_type ub, str;
 
diff --git a/libgfortran/generated/eoshift3_16.c b/libgfortran/generated/eoshift3_16.c
index 621fd6f..c5aca1a 100644
--- a/libgfortran/generated/eoshift3_16.c
+++ b/libgfortran/generated/eoshift3_16.c
@@ -85,12 +85,10 @@  eoshift3 (gfc_array_char * const restrict ret,
 
   if (ret->base_addr == NULL)
     {
-      int i;
-
       ret->base_addr = xmallocarray (arraysize, size);
       ret->offset = 0;
       ret->dtype = array->dtype;
-      for (i = 0; i < GFC_DESCRIPTOR_RANK (array); i++)
+      for (index_type i = 0; i < GFC_DESCRIPTOR_RANK (array); i++)
         {
 	  index_type ub, str;
 
diff --git a/libgfortran/generated/eoshift3_4.c b/libgfortran/generated/eoshift3_4.c
index ac4fd67..3003131 100644
--- a/libgfortran/generated/eoshift3_4.c
+++ b/libgfortran/generated/eoshift3_4.c
@@ -85,12 +85,10 @@  eoshift3 (gfc_array_char * const restrict ret,
 
   if (ret->base_addr == NULL)
     {
-      int i;
-
       ret->base_addr = xmallocarray (arraysize, size);
       ret->offset = 0;
       ret->dtype = array->dtype;
-      for (i = 0; i < GFC_DESCRIPTOR_RANK (array); i++)
+      for (index_type i = 0; i < GFC_DESCRIPTOR_RANK (array); i++)
         {
 	  index_type ub, str;
 
diff --git a/libgfortran/generated/eoshift3_8.c b/libgfortran/generated/eoshift3_8.c
index 7e9d8b4..bba8458 100644
--- a/libgfortran/generated/eoshift3_8.c
+++ b/libgfortran/generated/eoshift3_8.c
@@ -85,12 +85,10 @@  eoshift3 (gfc_array_char * const restrict ret,
 
   if (ret->base_addr == NULL)
     {
-      int i;
-
       ret->base_addr = xmallocarray (arraysize, size);
       ret->offset = 0;
       ret->dtype = array->dtype;
-      for (i = 0; i < GFC_DESCRIPTOR_RANK (array); i++)
+      for (index_type i = 0; i < GFC_DESCRIPTOR_RANK (array); i++)
         {
 	  index_type ub, str;
 
diff --git a/libgfortran/generated/in_pack_c10.c b/libgfortran/generated/in_pack_c10.c
index f46cfb5..cd99f27 100644
--- a/libgfortran/generated/in_pack_c10.c
+++ b/libgfortran/generated/in_pack_c10.c
@@ -43,7 +43,6 @@  internal_pack_c10 (gfc_array_c10 * source)
   const GFC_COMPLEX_10 *src;
   GFC_COMPLEX_10 * restrict dest;
   GFC_COMPLEX_10 *destptr;
-  int n;
   int packed;
 
   /* TODO: Investigate how we can figure out if this is a temporary
@@ -52,7 +51,7 @@  internal_pack_c10 (gfc_array_c10 * source)
   dim = GFC_DESCRIPTOR_RANK (source);
   ssize = 1;
   packed = 1;
-  for (n = 0; n < dim; n++)
+  for (index_type n = 0; n < dim; n++)
     {
       count[n] = 0;
       stride[n] = GFC_DESCRIPTOR_STRIDE(source,n);
@@ -88,7 +87,7 @@  internal_pack_c10 (gfc_array_c10 * source)
       src += stride0;
       count[0]++;
       /* Advance to the next source element.  */
-      n = 0;
+      index_type n = 0;
       while (count[n] == extent[n])
         {
           /* When we get to the end of a dimension, reset it and increment
diff --git a/libgfortran/generated/in_pack_c16.c b/libgfortran/generated/in_pack_c16.c
index d742644..5fd4970 100644
--- a/libgfortran/generated/in_pack_c16.c
+++ b/libgfortran/generated/in_pack_c16.c
@@ -43,7 +43,6 @@  internal_pack_c16 (gfc_array_c16 * source)
   const GFC_COMPLEX_16 *src;
   GFC_COMPLEX_16 * restrict dest;
   GFC_COMPLEX_16 *destptr;
-  int n;
   int packed;
 
   /* TODO: Investigate how we can figure out if this is a temporary
@@ -52,7 +51,7 @@  internal_pack_c16 (gfc_array_c16 * source)
   dim = GFC_DESCRIPTOR_RANK (source);
   ssize = 1;
   packed = 1;
-  for (n = 0; n < dim; n++)
+  for (index_type n = 0; n < dim; n++)
     {
       count[n] = 0;
       stride[n] = GFC_DESCRIPTOR_STRIDE(source,n);
@@ -88,7 +87,7 @@  internal_pack_c16 (gfc_array_c16 * source)
       src += stride0;
       count[0]++;
       /* Advance to the next source element.  */
-      n = 0;
+      index_type n = 0;
       while (count[n] == extent[n])
         {
           /* When we get to the end of a dimension, reset it and increment
diff --git a/libgfortran/generated/in_pack_c4.c b/libgfortran/generated/in_pack_c4.c
index 8bf1a7e..2215169 100644
--- a/libgfortran/generated/in_pack_c4.c
+++ b/libgfortran/generated/in_pack_c4.c
@@ -43,7 +43,6 @@  internal_pack_c4 (gfc_array_c4 * source)
   const GFC_COMPLEX_4 *src;
   GFC_COMPLEX_4 * restrict dest;
   GFC_COMPLEX_4 *destptr;
-  int n;
   int packed;
 
   /* TODO: Investigate how we can figure out if this is a temporary
@@ -52,7 +51,7 @@  internal_pack_c4 (gfc_array_c4 * source)
   dim = GFC_DESCRIPTOR_RANK (source);
   ssize = 1;
   packed = 1;
-  for (n = 0; n < dim; n++)
+  for (index_type n = 0; n < dim; n++)
     {
       count[n] = 0;
       stride[n] = GFC_DESCRIPTOR_STRIDE(source,n);
@@ -88,7 +87,7 @@  internal_pack_c4 (gfc_array_c4 * source)
       src += stride0;
       count[0]++;
       /* Advance to the next source element.  */
-      n = 0;
+      index_type n = 0;
       while (count[n] == extent[n])
         {
           /* When we get to the end of a dimension, reset it and increment
diff --git a/libgfortran/generated/in_pack_c8.c b/libgfortran/generated/in_pack_c8.c
index db3d3de..e855645 100644
--- a/libgfortran/generated/in_pack_c8.c
+++ b/libgfortran/generated/in_pack_c8.c
@@ -43,7 +43,6 @@  internal_pack_c8 (gfc_array_c8 * source)
   const GFC_COMPLEX_8 *src;
   GFC_COMPLEX_8 * restrict dest;
   GFC_COMPLEX_8 *destptr;
-  int n;
   int packed;
 
   /* TODO: Investigate how we can figure out if this is a temporary
@@ -52,7 +51,7 @@  internal_pack_c8 (gfc_array_c8 * source)
   dim = GFC_DESCRIPTOR_RANK (source);
   ssize = 1;
   packed = 1;
-  for (n = 0; n < dim; n++)
+  for (index_type n = 0; n < dim; n++)
     {
       count[n] = 0;
       stride[n] = GFC_DESCRIPTOR_STRIDE(source,n);
@@ -88,7 +87,7 @@  internal_pack_c8 (gfc_array_c8 * source)
       src += stride0;
       count[0]++;
       /* Advance to the next source element.  */
-      n = 0;
+      index_type n = 0;
       while (count[n] == extent[n])
         {
           /* When we get to the end of a dimension, reset it and increment
diff --git a/libgfortran/generated/in_pack_i1.c b/libgfortran/generated/in_pack_i1.c
index a85546f..bf80644 100644
--- a/libgfortran/generated/in_pack_i1.c
+++ b/libgfortran/generated/in_pack_i1.c
@@ -43,7 +43,6 @@  internal_pack_1 (gfc_array_i1 * source)
   const GFC_INTEGER_1 *src;
   GFC_INTEGER_1 * restrict dest;
   GFC_INTEGER_1 *destptr;
-  int n;
   int packed;
 
   /* TODO: Investigate how we can figure out if this is a temporary
@@ -52,7 +51,7 @@  internal_pack_1 (gfc_array_i1 * source)
   dim = GFC_DESCRIPTOR_RANK (source);
   ssize = 1;
   packed = 1;
-  for (n = 0; n < dim; n++)
+  for (index_type n = 0; n < dim; n++)
     {
       count[n] = 0;
       stride[n] = GFC_DESCRIPTOR_STRIDE(source,n);
@@ -88,7 +87,7 @@  internal_pack_1 (gfc_array_i1 * source)
       src += stride0;
       count[0]++;
       /* Advance to the next source element.  */
-      n = 0;
+      index_type n = 0;
       while (count[n] == extent[n])
         {
           /* When we get to the end of a dimension, reset it and increment
diff --git a/libgfortran/generated/in_pack_i16.c b/libgfortran/generated/in_pack_i16.c
index d11e9b5..41fcc98 100644
--- a/libgfortran/generated/in_pack_i16.c
+++ b/libgfortran/generated/in_pack_i16.c
@@ -43,7 +43,6 @@  internal_pack_16 (gfc_array_i16 * source)
   const GFC_INTEGER_16 *src;
   GFC_INTEGER_16 * restrict dest;
   GFC_INTEGER_16 *destptr;
-  int n;
   int packed;
 
   /* TODO: Investigate how we can figure out if this is a temporary
@@ -52,7 +51,7 @@  internal_pack_16 (gfc_array_i16 * source)
   dim = GFC_DESCRIPTOR_RANK (source);
   ssize = 1;
   packed = 1;
-  for (n = 0; n < dim; n++)
+  for (index_type n = 0; n < dim; n++)
     {
       count[n] = 0;
       stride[n] = GFC_DESCRIPTOR_STRIDE(source,n);
@@ -88,7 +87,7 @@  internal_pack_16 (gfc_array_i16 * source)
       src += stride0;
       count[0]++;
       /* Advance to the next source element.  */
-      n = 0;
+      index_type n = 0;
       while (count[n] == extent[n])
         {
           /* When we get to the end of a dimension, reset it and increment
diff --git a/libgfortran/generated/in_pack_i2.c b/libgfortran/generated/in_pack_i2.c
index 027e3f2..e460992 100644
--- a/libgfortran/generated/in_pack_i2.c
+++ b/libgfortran/generated/in_pack_i2.c
@@ -43,7 +43,6 @@  internal_pack_2 (gfc_array_i2 * source)
   const GFC_INTEGER_2 *src;
   GFC_INTEGER_2 * restrict dest;
   GFC_INTEGER_2 *destptr;
-  int n;
   int packed;
 
   /* TODO: Investigate how we can figure out if this is a temporary
@@ -52,7 +51,7 @@  internal_pack_2 (gfc_array_i2 * source)
   dim = GFC_DESCRIPTOR_RANK (source);
   ssize = 1;
   packed = 1;
-  for (n = 0; n < dim; n++)
+  for (index_type n = 0; n < dim; n++)
     {
       count[n] = 0;
       stride[n] = GFC_DESCRIPTOR_STRIDE(source,n);
@@ -88,7 +87,7 @@  internal_pack_2 (gfc_array_i2 * source)
       src += stride0;
       count[0]++;
       /* Advance to the next source element.  */
-      n = 0;
+      index_type n = 0;
       while (count[n] == extent[n])
         {
           /* When we get to the end of a dimension, reset it and increment
diff --git a/libgfortran/generated/in_pack_i4.c b/libgfortran/generated/in_pack_i4.c
index 47e9388..1e06f6e 100644
--- a/libgfortran/generated/in_pack_i4.c
+++ b/libgfortran/generated/in_pack_i4.c
@@ -43,7 +43,6 @@  internal_pack_4 (gfc_array_i4 * source)
   const GFC_INTEGER_4 *src;
   GFC_INTEGER_4 * restrict dest;
   GFC_INTEGER_4 *destptr;
-  int n;
   int packed;
 
   /* TODO: Investigate how we can figure out if this is a temporary
@@ -52,7 +51,7 @@  internal_pack_4 (gfc_array_i4 * source)
   dim = GFC_DESCRIPTOR_RANK (source);
   ssize = 1;
   packed = 1;
-  for (n = 0; n < dim; n++)
+  for (index_type n = 0; n < dim; n++)
     {
       count[n] = 0;
       stride[n] = GFC_DESCRIPTOR_STRIDE(source,n);
@@ -88,7 +87,7 @@  internal_pack_4 (gfc_array_i4 * source)
       src += stride0;
       count[0]++;
       /* Advance to the next source element.  */
-      n = 0;
+      index_type n = 0;
       while (count[n] == extent[n])
         {
           /* When we get to the end of a dimension, reset it and increment
diff --git a/libgfortran/generated/in_pack_i8.c b/libgfortran/generated/in_pack_i8.c
index 19bb022..ce0b49a 100644
--- a/libgfortran/generated/in_pack_i8.c
+++ b/libgfortran/generated/in_pack_i8.c
@@ -43,7 +43,6 @@  internal_pack_8 (gfc_array_i8 * source)
   const GFC_INTEGER_8 *src;
   GFC_INTEGER_8 * restrict dest;
   GFC_INTEGER_8 *destptr;
-  int n;
   int packed;
 
   /* TODO: Investigate how we can figure out if this is a temporary
@@ -52,7 +51,7 @@  internal_pack_8 (gfc_array_i8 * source)
   dim = GFC_DESCRIPTOR_RANK (source);
   ssize = 1;
   packed = 1;
-  for (n = 0; n < dim; n++)
+  for (index_type n = 0; n < dim; n++)
     {
       count[n] = 0;
       stride[n] = GFC_DESCRIPTOR_STRIDE(source,n);
@@ -88,7 +87,7 @@  internal_pack_8 (gfc_array_i8 * source)
       src += stride0;
       count[0]++;
       /* Advance to the next source element.  */
-      n = 0;
+      index_type n = 0;
       while (count[n] == extent[n])
         {
           /* When we get to the end of a dimension, reset it and increment
diff --git a/libgfortran/generated/in_pack_r10.c b/libgfortran/generated/in_pack_r10.c
index 0a2da94..2841676 100644
--- a/libgfortran/generated/in_pack_r10.c
+++ b/libgfortran/generated/in_pack_r10.c
@@ -43,7 +43,6 @@  internal_pack_r10 (gfc_array_r10 * source)
   const GFC_REAL_10 *src;
   GFC_REAL_10 * restrict dest;
   GFC_REAL_10 *destptr;
-  int n;
   int packed;
 
   /* TODO: Investigate how we can figure out if this is a temporary
@@ -52,7 +51,7 @@  internal_pack_r10 (gfc_array_r10 * source)
   dim = GFC_DESCRIPTOR_RANK (source);
   ssize = 1;
   packed = 1;
-  for (n = 0; n < dim; n++)
+  for (index_type n = 0; n < dim; n++)
     {
       count[n] = 0;
       stride[n] = GFC_DESCRIPTOR_STRIDE(source,n);
@@ -88,7 +87,7 @@  internal_pack_r10 (gfc_array_r10 * source)
       src += stride0;
       count[0]++;
       /* Advance to the next source element.  */
-      n = 0;
+      index_type n = 0;
       while (count[n] == extent[n])
         {
           /* When we get to the end of a dimension, reset it and increment
diff --git a/libgfortran/generated/in_pack_r16.c b/libgfortran/generated/in_pack_r16.c
index 9c93c53..46cb9da 100644
--- a/libgfortran/generated/in_pack_r16.c
+++ b/libgfortran/generated/in_pack_r16.c
@@ -43,7 +43,6 @@  internal_pack_r16 (gfc_array_r16 * source)
   const GFC_REAL_16 *src;
   GFC_REAL_16 * restrict dest;
   GFC_REAL_16 *destptr;
-  int n;
   int packed;
 
   /* TODO: Investigate how we can figure out if this is a temporary
@@ -52,7 +51,7 @@  internal_pack_r16 (gfc_array_r16 * source)
   dim = GFC_DESCRIPTOR_RANK (source);
   ssize = 1;
   packed = 1;
-  for (n = 0; n < dim; n++)
+  for (index_type n = 0; n < dim; n++)
     {
       count[n] = 0;
       stride[n] = GFC_DESCRIPTOR_STRIDE(source,n);
@@ -88,7 +87,7 @@  internal_pack_r16 (gfc_array_r16 * source)
       src += stride0;
       count[0]++;
       /* Advance to the next source element.  */
-      n = 0;
+      index_type n = 0;
       while (count[n] == extent[n])
         {
           /* When we get to the end of a dimension, reset it and increment
diff --git a/libgfortran/generated/in_pack_r4.c b/libgfortran/generated/in_pack_r4.c
index 64f283d..77ce271 100644
--- a/libgfortran/generated/in_pack_r4.c
+++ b/libgfortran/generated/in_pack_r4.c
@@ -43,7 +43,6 @@  internal_pack_r4 (gfc_array_r4 * source)
   const GFC_REAL_4 *src;
   GFC_REAL_4 * restrict dest;
   GFC_REAL_4 *destptr;
-  int n;
   int packed;
 
   /* TODO: Investigate how we can figure out if this is a temporary
@@ -52,7 +51,7 @@  internal_pack_r4 (gfc_array_r4 * source)
   dim = GFC_DESCRIPTOR_RANK (source);
   ssize = 1;
   packed = 1;
-  for (n = 0; n < dim; n++)
+  for (index_type n = 0; n < dim; n++)
     {
       count[n] = 0;
       stride[n] = GFC_DESCRIPTOR_STRIDE(source,n);
@@ -88,7 +87,7 @@  internal_pack_r4 (gfc_array_r4 * source)
       src += stride0;
       count[0]++;
       /* Advance to the next source element.  */
-      n = 0;
+      index_type n = 0;
       while (count[n] == extent[n])
         {
           /* When we get to the end of a dimension, reset it and increment
diff --git a/libgfortran/generated/in_pack_r8.c b/libgfortran/generated/in_pack_r8.c
index f4d2922..600b5ae 100644
--- a/libgfortran/generated/in_pack_r8.c
+++ b/libgfortran/generated/in_pack_r8.c
@@ -43,7 +43,6 @@  internal_pack_r8 (gfc_array_r8 * source)
   const GFC_REAL_8 *src;
   GFC_REAL_8 * restrict dest;
   GFC_REAL_8 *destptr;
-  int n;
   int packed;
 
   /* TODO: Investigate how we can figure out if this is a temporary
@@ -52,7 +51,7 @@  internal_pack_r8 (gfc_array_r8 * source)
   dim = GFC_DESCRIPTOR_RANK (source);
   ssize = 1;
   packed = 1;
-  for (n = 0; n < dim; n++)
+  for (index_type n = 0; n < dim; n++)
     {
       count[n] = 0;
       stride[n] = GFC_DESCRIPTOR_STRIDE(source,n);
@@ -88,7 +87,7 @@  internal_pack_r8 (gfc_array_r8 * source)
       src += stride0;
       count[0]++;
       /* Advance to the next source element.  */
-      n = 0;
+      index_type n = 0;
       while (count[n] == extent[n])
         {
           /* When we get to the end of a dimension, reset it and increment
diff --git a/libgfortran/generated/in_unpack_c10.c b/libgfortran/generated/in_unpack_c10.c
index 4fd792d..0358090 100644
--- a/libgfortran/generated/in_unpack_c10.c
+++ b/libgfortran/generated/in_unpack_c10.c
@@ -39,7 +39,6 @@  internal_unpack_c10 (gfc_array_c10 * d, const GFC_COMPLEX_10 * src)
   index_type dim;
   index_type dsize;
   GFC_COMPLEX_10 * restrict dest;
-  int n;
 
   dest = d->base_addr;
   if (src == dest || !src)
@@ -47,7 +46,7 @@  internal_unpack_c10 (gfc_array_c10 * d, const GFC_COMPLEX_10 * src)
 
   dim = GFC_DESCRIPTOR_RANK (d);
   dsize = 1;
-  for (n = 0; n < dim; n++)
+  for (index_type n = 0; n < dim; n++)
     {
       count[n] = 0;
       stride[n] = GFC_DESCRIPTOR_STRIDE(d,n);
@@ -77,7 +76,7 @@  internal_unpack_c10 (gfc_array_c10 * d, const GFC_COMPLEX_10 * src)
       dest += stride0;
       count[0]++;
       /* Advance to the next source element.  */
-      n = 0;
+      index_type n = 0;
       while (count[n] == extent[n])
         {
           /* When we get to the end of a dimension, reset it and increment
diff --git a/libgfortran/generated/in_unpack_c16.c b/libgfortran/generated/in_unpack_c16.c
index c0d9333..dd7adff 100644
--- a/libgfortran/generated/in_unpack_c16.c
+++ b/libgfortran/generated/in_unpack_c16.c
@@ -39,7 +39,6 @@  internal_unpack_c16 (gfc_array_c16 * d, const GFC_COMPLEX_16 * src)
   index_type dim;
   index_type dsize;
   GFC_COMPLEX_16 * restrict dest;
-  int n;
 
   dest = d->base_addr;
   if (src == dest || !src)
@@ -47,7 +46,7 @@  internal_unpack_c16 (gfc_array_c16 * d, const GFC_COMPLEX_16 * src)
 
   dim = GFC_DESCRIPTOR_RANK (d);
   dsize = 1;
-  for (n = 0; n < dim; n++)
+  for (index_type n = 0; n < dim; n++)
     {
       count[n] = 0;
       stride[n] = GFC_DESCRIPTOR_STRIDE(d,n);
@@ -77,7 +76,7 @@  internal_unpack_c16 (gfc_array_c16 * d, const GFC_COMPLEX_16 * src)
       dest += stride0;
       count[0]++;
       /* Advance to the next source element.  */
-      n = 0;
+      index_type n = 0;
       while (count[n] == extent[n])
         {
           /* When we get to the end of a dimension, reset it and increment
diff --git a/libgfortran/generated/in_unpack_c4.c b/libgfortran/generated/in_unpack_c4.c
index b971212..d0d249d 100644
--- a/libgfortran/generated/in_unpack_c4.c
+++ b/libgfortran/generated/in_unpack_c4.c
@@ -39,7 +39,6 @@  internal_unpack_c4 (gfc_array_c4 * d, const GFC_COMPLEX_4 * src)
   index_type dim;
   index_type dsize;
   GFC_COMPLEX_4 * restrict dest;
-  int n;
 
   dest = d->base_addr;
   if (src == dest || !src)
@@ -47,7 +46,7 @@  internal_unpack_c4 (gfc_array_c4 * d, const GFC_COMPLEX_4 * src)
 
   dim = GFC_DESCRIPTOR_RANK (d);
   dsize = 1;
-  for (n = 0; n < dim; n++)
+  for (index_type n = 0; n < dim; n++)
     {
       count[n] = 0;
       stride[n] = GFC_DESCRIPTOR_STRIDE(d,n);
@@ -77,7 +76,7 @@  internal_unpack_c4 (gfc_array_c4 * d, const GFC_COMPLEX_4 * src)
       dest += stride0;
       count[0]++;
       /* Advance to the next source element.  */
-      n = 0;
+      index_type n = 0;
       while (count[n] == extent[n])
         {
           /* When we get to the end of a dimension, reset it and increment
diff --git a/libgfortran/generated/in_unpack_c8.c b/libgfortran/generated/in_unpack_c8.c
index 76b2d56..6fbddf1 100644
--- a/libgfortran/generated/in_unpack_c8.c
+++ b/libgfortran/generated/in_unpack_c8.c
@@ -39,7 +39,6 @@  internal_unpack_c8 (gfc_array_c8 * d, const GFC_COMPLEX_8 * src)
   index_type dim;
   index_type dsize;
   GFC_COMPLEX_8 * restrict dest;
-  int n;
 
   dest = d->base_addr;
   if (src == dest || !src)
@@ -47,7 +46,7 @@  internal_unpack_c8 (gfc_array_c8 * d, const GFC_COMPLEX_8 * src)
 
   dim = GFC_DESCRIPTOR_RANK (d);
   dsize = 1;
-  for (n = 0; n < dim; n++)
+  for (index_type n = 0; n < dim; n++)
     {
       count[n] = 0;
       stride[n] = GFC_DESCRIPTOR_STRIDE(d,n);
@@ -77,7 +76,7 @@  internal_unpack_c8 (gfc_array_c8 * d, const GFC_COMPLEX_8 * src)
       dest += stride0;
       count[0]++;
       /* Advance to the next source element.  */
-      n = 0;
+      index_type n = 0;
       while (count[n] == extent[n])
         {
           /* When we get to the end of a dimension, reset it and increment
diff --git a/libgfortran/generated/in_unpack_i1.c b/libgfortran/generated/in_unpack_i1.c
index 9ad7c25..afeb38f 100644
--- a/libgfortran/generated/in_unpack_i1.c
+++ b/libgfortran/generated/in_unpack_i1.c
@@ -39,7 +39,6 @@  internal_unpack_1 (gfc_array_i1 * d, const GFC_INTEGER_1 * src)
   index_type dim;
   index_type dsize;
   GFC_INTEGER_1 * restrict dest;
-  int n;
 
   dest = d->base_addr;
   if (src == dest || !src)
@@ -47,7 +46,7 @@  internal_unpack_1 (gfc_array_i1 * d, const GFC_INTEGER_1 * src)
 
   dim = GFC_DESCRIPTOR_RANK (d);
   dsize = 1;
-  for (n = 0; n < dim; n++)
+  for (index_type n = 0; n < dim; n++)
     {
       count[n] = 0;
       stride[n] = GFC_DESCRIPTOR_STRIDE(d,n);
@@ -77,7 +76,7 @@  internal_unpack_1 (gfc_array_i1 * d, const GFC_INTEGER_1 * src)
       dest += stride0;
       count[0]++;
       /* Advance to the next source element.  */
-      n = 0;
+      index_type n = 0;
       while (count[n] == extent[n])
         {
           /* When we get to the end of a dimension, reset it and increment
diff --git a/libgfortran/generated/in_unpack_i16.c b/libgfortran/generated/in_unpack_i16.c
index 801e1de..eba2840 100644
--- a/libgfortran/generated/in_unpack_i16.c
+++ b/libgfortran/generated/in_unpack_i16.c
@@ -39,7 +39,6 @@  internal_unpack_16 (gfc_array_i16 * d, const GFC_INTEGER_16 * src)
   index_type dim;
   index_type dsize;
   GFC_INTEGER_16 * restrict dest;
-  int n;
 
   dest = d->base_addr;
   if (src == dest || !src)
@@ -47,7 +46,7 @@  internal_unpack_16 (gfc_array_i16 * d, const GFC_INTEGER_16 * src)
 
   dim = GFC_DESCRIPTOR_RANK (d);
   dsize = 1;
-  for (n = 0; n < dim; n++)
+  for (index_type n = 0; n < dim; n++)
     {
       count[n] = 0;
       stride[n] = GFC_DESCRIPTOR_STRIDE(d,n);
@@ -77,7 +76,7 @@  internal_unpack_16 (gfc_array_i16 * d, const GFC_INTEGER_16 * src)
       dest += stride0;
       count[0]++;
       /* Advance to the next source element.  */
-      n = 0;
+      index_type n = 0;
       while (count[n] == extent[n])
         {
           /* When we get to the end of a dimension, reset it and increment
diff --git a/libgfortran/generated/in_unpack_i2.c b/libgfortran/generated/in_unpack_i2.c
index 6c4a043..6a7e689 100644
--- a/libgfortran/generated/in_unpack_i2.c
+++ b/libgfortran/generated/in_unpack_i2.c
@@ -39,7 +39,6 @@  internal_unpack_2 (gfc_array_i2 * d, const GFC_INTEGER_2 * src)
   index_type dim;
   index_type dsize;
   GFC_INTEGER_2 * restrict dest;
-  int n;
 
   dest = d->base_addr;
   if (src == dest || !src)
@@ -47,7 +46,7 @@  internal_unpack_2 (gfc_array_i2 * d, const GFC_INTEGER_2 * src)
 
   dim = GFC_DESCRIPTOR_RANK (d);
   dsize = 1;
-  for (n = 0; n < dim; n++)
+  for (index_type n = 0; n < dim; n++)
     {
       count[n] = 0;
       stride[n] = GFC_DESCRIPTOR_STRIDE(d,n);
@@ -77,7 +76,7 @@  internal_unpack_2 (gfc_array_i2 * d, const GFC_INTEGER_2 * src)
       dest += stride0;
       count[0]++;
       /* Advance to the next source element.  */
-      n = 0;
+      index_type n = 0;
       while (count[n] == extent[n])
         {
           /* When we get to the end of a dimension, reset it and increment
diff --git a/libgfortran/generated/in_unpack_i4.c b/libgfortran/generated/in_unpack_i4.c
index d36087c..30a43c5 100644
--- a/libgfortran/generated/in_unpack_i4.c
+++ b/libgfortran/generated/in_unpack_i4.c
@@ -39,7 +39,6 @@  internal_unpack_4 (gfc_array_i4 * d, const GFC_INTEGER_4 * src)
   index_type dim;
   index_type dsize;
   GFC_INTEGER_4 * restrict dest;
-  int n;
 
   dest = d->base_addr;
   if (src == dest || !src)
@@ -47,7 +46,7 @@  internal_unpack_4 (gfc_array_i4 * d, const GFC_INTEGER_4 * src)
 
   dim = GFC_DESCRIPTOR_RANK (d);
   dsize = 1;
-  for (n = 0; n < dim; n++)
+  for (index_type n = 0; n < dim; n++)
     {
       count[n] = 0;
       stride[n] = GFC_DESCRIPTOR_STRIDE(d,n);
@@ -77,7 +76,7 @@  internal_unpack_4 (gfc_array_i4 * d, const GFC_INTEGER_4 * src)
       dest += stride0;
       count[0]++;
       /* Advance to the next source element.  */
-      n = 0;
+      index_type n = 0;
       while (count[n] == extent[n])
         {
           /* When we get to the end of a dimension, reset it and increment
diff --git a/libgfortran/generated/in_unpack_i8.c b/libgfortran/generated/in_unpack_i8.c
index 367fbdb..be62fc7 100644
--- a/libgfortran/generated/in_unpack_i8.c
+++ b/libgfortran/generated/in_unpack_i8.c
@@ -39,7 +39,6 @@  internal_unpack_8 (gfc_array_i8 * d, const GFC_INTEGER_8 * src)
   index_type dim;
   index_type dsize;
   GFC_INTEGER_8 * restrict dest;
-  int n;
 
   dest = d->base_addr;
   if (src == dest || !src)
@@ -47,7 +46,7 @@  internal_unpack_8 (gfc_array_i8 * d, const GFC_INTEGER_8 * src)
 
   dim = GFC_DESCRIPTOR_RANK (d);
   dsize = 1;
-  for (n = 0; n < dim; n++)
+  for (index_type n = 0; n < dim; n++)
     {
       count[n] = 0;
       stride[n] = GFC_DESCRIPTOR_STRIDE(d,n);
@@ -77,7 +76,7 @@  internal_unpack_8 (gfc_array_i8 * d, const GFC_INTEGER_8 * src)
       dest += stride0;
       count[0]++;
       /* Advance to the next source element.  */
-      n = 0;
+      index_type n = 0;
       while (count[n] == extent[n])
         {
           /* When we get to the end of a dimension, reset it and increment
diff --git a/libgfortran/generated/in_unpack_r10.c b/libgfortran/generated/in_unpack_r10.c
index bdde745..7e74820 100644
--- a/libgfortran/generated/in_unpack_r10.c
+++ b/libgfortran/generated/in_unpack_r10.c
@@ -39,7 +39,6 @@  internal_unpack_r10 (gfc_array_r10 * d, const GFC_REAL_10 * src)
   index_type dim;
   index_type dsize;
   GFC_REAL_10 * restrict dest;
-  int n;
 
   dest = d->base_addr;
   if (src == dest || !src)
@@ -47,7 +46,7 @@  internal_unpack_r10 (gfc_array_r10 * d, const GFC_REAL_10 * src)
 
   dim = GFC_DESCRIPTOR_RANK (d);
   dsize = 1;
-  for (n = 0; n < dim; n++)
+  for (index_type n = 0; n < dim; n++)
     {
       count[n] = 0;
       stride[n] = GFC_DESCRIPTOR_STRIDE(d,n);
@@ -77,7 +76,7 @@  internal_unpack_r10 (gfc_array_r10 * d, const GFC_REAL_10 * src)
       dest += stride0;
       count[0]++;
       /* Advance to the next source element.  */
-      n = 0;
+      index_type n = 0;
       while (count[n] == extent[n])
         {
           /* When we get to the end of a dimension, reset it and increment
diff --git a/libgfortran/generated/in_unpack_r16.c b/libgfortran/generated/in_unpack_r16.c
index 4cc3c7f..7799ce6 100644
--- a/libgfortran/generated/in_unpack_r16.c
+++ b/libgfortran/generated/in_unpack_r16.c
@@ -39,7 +39,6 @@  internal_unpack_r16 (gfc_array_r16 * d, const GFC_REAL_16 * src)
   index_type dim;
   index_type dsize;
   GFC_REAL_16 * restrict dest;
-  int n;
 
   dest = d->base_addr;
   if (src == dest || !src)
@@ -47,7 +46,7 @@  internal_unpack_r16 (gfc_array_r16 * d, const GFC_REAL_16 * src)
 
   dim = GFC_DESCRIPTOR_RANK (d);
   dsize = 1;
-  for (n = 0; n < dim; n++)
+  for (index_type n = 0; n < dim; n++)
     {
       count[n] = 0;
       stride[n] = GFC_DESCRIPTOR_STRIDE(d,n);
@@ -77,7 +76,7 @@  internal_unpack_r16 (gfc_array_r16 * d, const GFC_REAL_16 * src)
       dest += stride0;
       count[0]++;
       /* Advance to the next source element.  */
-      n = 0;
+      index_type n = 0;
       while (count[n] == extent[n])
         {
           /* When we get to the end of a dimension, reset it and increment
diff --git a/libgfortran/generated/in_unpack_r4.c b/libgfortran/generated/in_unpack_r4.c
index f87d1c5..f22e885 100644
--- a/libgfortran/generated/in_unpack_r4.c
+++ b/libgfortran/generated/in_unpack_r4.c
@@ -39,7 +39,6 @@  internal_unpack_r4 (gfc_array_r4 * d, const GFC_REAL_4 * src)
   index_type dim;
   index_type dsize;
   GFC_REAL_4 * restrict dest;
-  int n;
 
   dest = d->base_addr;
   if (src == dest || !src)
@@ -47,7 +46,7 @@  internal_unpack_r4 (gfc_array_r4 * d, const GFC_REAL_4 * src)
 
   dim = GFC_DESCRIPTOR_RANK (d);
   dsize = 1;
-  for (n = 0; n < dim; n++)
+  for (index_type n = 0; n < dim; n++)
     {
       count[n] = 0;
       stride[n] = GFC_DESCRIPTOR_STRIDE(d,n);
@@ -77,7 +76,7 @@  internal_unpack_r4 (gfc_array_r4 * d, const GFC_REAL_4 * src)
       dest += stride0;
       count[0]++;
       /* Advance to the next source element.  */
-      n = 0;
+      index_type n = 0;
       while (count[n] == extent[n])
         {
           /* When we get to the end of a dimension, reset it and increment
diff --git a/libgfortran/generated/in_unpack_r8.c b/libgfortran/generated/in_unpack_r8.c
index f6c56e6..526c397 100644
--- a/libgfortran/generated/in_unpack_r8.c
+++ b/libgfortran/generated/in_unpack_r8.c
@@ -39,7 +39,6 @@  internal_unpack_r8 (gfc_array_r8 * d, const GFC_REAL_8 * src)
   index_type dim;
   index_type dsize;
   GFC_REAL_8 * restrict dest;
-  int n;
 
   dest = d->base_addr;
   if (src == dest || !src)
@@ -47,7 +46,7 @@  internal_unpack_r8 (gfc_array_r8 * d, const GFC_REAL_8 * src)
 
   dim = GFC_DESCRIPTOR_RANK (d);
   dsize = 1;
-  for (n = 0; n < dim; n++)
+  for (index_type n = 0; n < dim; n++)
     {
       count[n] = 0;
       stride[n] = GFC_DESCRIPTOR_STRIDE(d,n);
@@ -77,7 +76,7 @@  internal_unpack_r8 (gfc_array_r8 * d, const GFC_REAL_8 * src)
       dest += stride0;
       count[0]++;
       /* Advance to the next source element.  */
-      n = 0;
+      index_type n = 0;
       while (count[n] == extent[n])
         {
           /* When we get to the end of a dimension, reset it and increment
diff --git a/libgfortran/generated/reshape_c10.c b/libgfortran/generated/reshape_c10.c
index ce6c9a2..0bf09bd 100644
--- a/libgfortran/generated/reshape_c10.c
+++ b/libgfortran/generated/reshape_c10.c
@@ -72,8 +72,6 @@  reshape_c10 (gfc_array_c10 * const restrict ret,
   const GFC_COMPLEX_10 *pptr;
 
   const GFC_COMPLEX_10 *src;
-  int n;
-  int dim;
   int sempty, pempty, shape_empty;
   index_type shape_data[GFC_MAX_DIMENSIONS];
 
@@ -87,7 +85,7 @@  reshape_c10 (gfc_array_c10 * const restrict ret,
 
   shape_empty = 0;
 
-  for (n = 0; n < rdim; n++)
+  for (index_type n = 0; n < rdim; n++)
     {
       shape_data[n] = shape->base_addr[n * GFC_DESCRIPTOR_STRIDE(shape,0)];
       if (shape_data[n] <= 0)
@@ -102,7 +100,7 @@  reshape_c10 (gfc_array_c10 * const restrict ret,
       index_type alloc_size;
 
       rs = 1;
-      for (n = 0; n < rdim; n++)
+      for (index_type n = 0; n < rdim; n++)
 	{
 	  rex = shape_data[n];
 
@@ -129,7 +127,7 @@  reshape_c10 (gfc_array_c10 * const restrict ret,
       pdim = GFC_DESCRIPTOR_RANK (pad);
       psize = 1;
       pempty = 0;
-      for (n = 0; n < pdim; n++)
+      for (index_type n = 0; n < pdim; n++)
         {
           pcount[n] = 0;
           pstride[n] = GFC_DESCRIPTOR_STRIDE(pad,n);
@@ -160,7 +158,7 @@  reshape_c10 (gfc_array_c10 * const restrict ret,
       index_type ret_extent, source_extent;
 
       rs = 1;
-      for (n = 0; n < rdim; n++)
+      for (index_type n = 0; n < rdim; n++)
 	{
 	  rs *= shape_data[n];
 	  ret_extent = GFC_DESCRIPTOR_EXTENT(ret,n);
@@ -173,7 +171,7 @@  reshape_c10 (gfc_array_c10 * const restrict ret,
 
       source_extent = 1;
       sdim = GFC_DESCRIPTOR_RANK (source);
-      for (n = 0; n < sdim; n++)
+      for (index_type n = 0; n < sdim; n++)
 	{
 	  index_type se;
 	  se = GFC_DESCRIPTOR_EXTENT(source,n);
@@ -190,10 +188,10 @@  reshape_c10 (gfc_array_c10 * const restrict ret,
 	  int seen[GFC_MAX_DIMENSIONS];
 	  index_type v;
 
-	  for (n = 0; n < rdim; n++)
+	  for (index_type n = 0; n < rdim; n++)
 	    seen[n] = 0;
 
-	  for (n = 0; n < rdim; n++)
+	  for (index_type n = 0; n < rdim; n++)
 	    {
 	      v = order->base_addr[n * GFC_DESCRIPTOR_STRIDE(order,0)] - 1;
 
@@ -211,8 +209,9 @@  reshape_c10 (gfc_array_c10 * const restrict ret,
     }
 
   rsize = 1;
-  for (n = 0; n < rdim; n++)
+  for (index_type n = 0; n < rdim; n++)
     {
+      index_type dim;
       if (order)
         dim = order->base_addr[n * GFC_DESCRIPTOR_STRIDE(order,0)] - 1;
       else
@@ -243,7 +242,7 @@  reshape_c10 (gfc_array_c10 * const restrict ret,
 
   ssize = 1;
   sempty = 0;
-  for (n = 0; n < sdim; n++)
+  for (index_type n = 0; n < sdim; n++)
     {
       scount[n] = 0;
       sstride[n] = GFC_DESCRIPTOR_STRIDE(source,n);
@@ -283,7 +282,7 @@  reshape_c10 (gfc_array_c10 * const restrict ret,
       src = pptr;
       sptr = pptr;
       sdim = pdim;
-      for (dim = 0; dim < pdim; dim++)
+      for (index_type dim = 0; dim < pdim; dim++)
 	{
 	  scount[dim] = pcount[dim];
 	  sextent[dim] = pextent[dim];
@@ -303,7 +302,7 @@  reshape_c10 (gfc_array_c10 * const restrict ret,
       scount[0]++;
 
       /* Advance to the next destination element.  */
-      n = 0;
+      index_type n = 0;
       while (rcount[n] == rextent[n])
         {
           /* When we get to the end of a dimension, reset it and increment
@@ -343,7 +342,7 @@  reshape_c10 (gfc_array_c10 * const restrict ret,
                   /* Switch to the pad array.  */
                   sptr = NULL;
                   sdim = pdim;
-                  for (dim = 0; dim < pdim; dim++)
+                  for (index_type dim = 0; dim < pdim; dim++)
                     {
                       scount[dim] = pcount[dim];
                       sextent[dim] = pextent[dim];
diff --git a/libgfortran/generated/reshape_c16.c b/libgfortran/generated/reshape_c16.c
index 4ca6722..80a2adf 100644
--- a/libgfortran/generated/reshape_c16.c
+++ b/libgfortran/generated/reshape_c16.c
@@ -72,8 +72,6 @@  reshape_c16 (gfc_array_c16 * const restrict ret,
   const GFC_COMPLEX_16 *pptr;
 
   const GFC_COMPLEX_16 *src;
-  int n;
-  int dim;
   int sempty, pempty, shape_empty;
   index_type shape_data[GFC_MAX_DIMENSIONS];
 
@@ -87,7 +85,7 @@  reshape_c16 (gfc_array_c16 * const restrict ret,
 
   shape_empty = 0;
 
-  for (n = 0; n < rdim; n++)
+  for (index_type n = 0; n < rdim; n++)
     {
       shape_data[n] = shape->base_addr[n * GFC_DESCRIPTOR_STRIDE(shape,0)];
       if (shape_data[n] <= 0)
@@ -102,7 +100,7 @@  reshape_c16 (gfc_array_c16 * const restrict ret,
       index_type alloc_size;
 
       rs = 1;
-      for (n = 0; n < rdim; n++)
+      for (index_type n = 0; n < rdim; n++)
 	{
 	  rex = shape_data[n];
 
@@ -129,7 +127,7 @@  reshape_c16 (gfc_array_c16 * const restrict ret,
       pdim = GFC_DESCRIPTOR_RANK (pad);
       psize = 1;
       pempty = 0;
-      for (n = 0; n < pdim; n++)
+      for (index_type n = 0; n < pdim; n++)
         {
           pcount[n] = 0;
           pstride[n] = GFC_DESCRIPTOR_STRIDE(pad,n);
@@ -160,7 +158,7 @@  reshape_c16 (gfc_array_c16 * const restrict ret,
       index_type ret_extent, source_extent;
 
       rs = 1;
-      for (n = 0; n < rdim; n++)
+      for (index_type n = 0; n < rdim; n++)
 	{
 	  rs *= shape_data[n];
 	  ret_extent = GFC_DESCRIPTOR_EXTENT(ret,n);
@@ -173,7 +171,7 @@  reshape_c16 (gfc_array_c16 * const restrict ret,
 
       source_extent = 1;
       sdim = GFC_DESCRIPTOR_RANK (source);
-      for (n = 0; n < sdim; n++)
+      for (index_type n = 0; n < sdim; n++)
 	{
 	  index_type se;
 	  se = GFC_DESCRIPTOR_EXTENT(source,n);
@@ -190,10 +188,10 @@  reshape_c16 (gfc_array_c16 * const restrict ret,
 	  int seen[GFC_MAX_DIMENSIONS];
 	  index_type v;
 
-	  for (n = 0; n < rdim; n++)
+	  for (index_type n = 0; n < rdim; n++)
 	    seen[n] = 0;
 
-	  for (n = 0; n < rdim; n++)
+	  for (index_type n = 0; n < rdim; n++)
 	    {
 	      v = order->base_addr[n * GFC_DESCRIPTOR_STRIDE(order,0)] - 1;
 
@@ -211,8 +209,9 @@  reshape_c16 (gfc_array_c16 * const restrict ret,
     }
 
   rsize = 1;
-  for (n = 0; n < rdim; n++)
+  for (index_type n = 0; n < rdim; n++)
     {
+      index_type dim;
       if (order)
         dim = order->base_addr[n * GFC_DESCRIPTOR_STRIDE(order,0)] - 1;
       else
@@ -243,7 +242,7 @@  reshape_c16 (gfc_array_c16 * const restrict ret,
 
   ssize = 1;
   sempty = 0;
-  for (n = 0; n < sdim; n++)
+  for (index_type n = 0; n < sdim; n++)
     {
       scount[n] = 0;
       sstride[n] = GFC_DESCRIPTOR_STRIDE(source,n);
@@ -283,7 +282,7 @@  reshape_c16 (gfc_array_c16 * const restrict ret,
       src = pptr;
       sptr = pptr;
       sdim = pdim;
-      for (dim = 0; dim < pdim; dim++)
+      for (index_type dim = 0; dim < pdim; dim++)
 	{
 	  scount[dim] = pcount[dim];
 	  sextent[dim] = pextent[dim];
@@ -303,7 +302,7 @@  reshape_c16 (gfc_array_c16 * const restrict ret,
       scount[0]++;
 
       /* Advance to the next destination element.  */
-      n = 0;
+      index_type n = 0;
       while (rcount[n] == rextent[n])
         {
           /* When we get to the end of a dimension, reset it and increment
@@ -343,7 +342,7 @@  reshape_c16 (gfc_array_c16 * const restrict ret,
                   /* Switch to the pad array.  */
                   sptr = NULL;
                   sdim = pdim;
-                  for (dim = 0; dim < pdim; dim++)
+                  for (index_type dim = 0; dim < pdim; dim++)
                     {
                       scount[dim] = pcount[dim];
                       sextent[dim] = pextent[dim];
diff --git a/libgfortran/generated/reshape_c4.c b/libgfortran/generated/reshape_c4.c
index dc1b8ee..c1db8a5 100644
--- a/libgfortran/generated/reshape_c4.c
+++ b/libgfortran/generated/reshape_c4.c
@@ -72,8 +72,6 @@  reshape_c4 (gfc_array_c4 * const restrict ret,
   const GFC_COMPLEX_4 *pptr;
 
   const GFC_COMPLEX_4 *src;
-  int n;
-  int dim;
   int sempty, pempty, shape_empty;
   index_type shape_data[GFC_MAX_DIMENSIONS];
 
@@ -87,7 +85,7 @@  reshape_c4 (gfc_array_c4 * const restrict ret,
 
   shape_empty = 0;
 
-  for (n = 0; n < rdim; n++)
+  for (index_type n = 0; n < rdim; n++)
     {
       shape_data[n] = shape->base_addr[n * GFC_DESCRIPTOR_STRIDE(shape,0)];
       if (shape_data[n] <= 0)
@@ -102,7 +100,7 @@  reshape_c4 (gfc_array_c4 * const restrict ret,
       index_type alloc_size;
 
       rs = 1;
-      for (n = 0; n < rdim; n++)
+      for (index_type n = 0; n < rdim; n++)
 	{
 	  rex = shape_data[n];
 
@@ -129,7 +127,7 @@  reshape_c4 (gfc_array_c4 * const restrict ret,
       pdim = GFC_DESCRIPTOR_RANK (pad);
       psize = 1;
       pempty = 0;
-      for (n = 0; n < pdim; n++)
+      for (index_type n = 0; n < pdim; n++)
         {
           pcount[n] = 0;
           pstride[n] = GFC_DESCRIPTOR_STRIDE(pad,n);
@@ -160,7 +158,7 @@  reshape_c4 (gfc_array_c4 * const restrict ret,
       index_type ret_extent, source_extent;
 
       rs = 1;
-      for (n = 0; n < rdim; n++)
+      for (index_type n = 0; n < rdim; n++)
 	{
 	  rs *= shape_data[n];
 	  ret_extent = GFC_DESCRIPTOR_EXTENT(ret,n);
@@ -173,7 +171,7 @@  reshape_c4 (gfc_array_c4 * const restrict ret,
 
       source_extent = 1;
       sdim = GFC_DESCRIPTOR_RANK (source);
-      for (n = 0; n < sdim; n++)
+      for (index_type n = 0; n < sdim; n++)
 	{
 	  index_type se;
 	  se = GFC_DESCRIPTOR_EXTENT(source,n);
@@ -190,10 +188,10 @@  reshape_c4 (gfc_array_c4 * const restrict ret,
 	  int seen[GFC_MAX_DIMENSIONS];
 	  index_type v;
 
-	  for (n = 0; n < rdim; n++)
+	  for (index_type n = 0; n < rdim; n++)
 	    seen[n] = 0;
 
-	  for (n = 0; n < rdim; n++)
+	  for (index_type n = 0; n < rdim; n++)
 	    {
 	      v = order->base_addr[n * GFC_DESCRIPTOR_STRIDE(order,0)] - 1;
 
@@ -211,8 +209,9 @@  reshape_c4 (gfc_array_c4 * const restrict ret,
     }
 
   rsize = 1;
-  for (n = 0; n < rdim; n++)
+  for (index_type n = 0; n < rdim; n++)
     {
+      index_type dim;
       if (order)
         dim = order->base_addr[n * GFC_DESCRIPTOR_STRIDE(order,0)] - 1;
       else
@@ -243,7 +242,7 @@  reshape_c4 (gfc_array_c4 * const restrict ret,
 
   ssize = 1;
   sempty = 0;
-  for (n = 0; n < sdim; n++)
+  for (index_type n = 0; n < sdim; n++)
     {
       scount[n] = 0;
       sstride[n] = GFC_DESCRIPTOR_STRIDE(source,n);
@@ -283,7 +282,7 @@  reshape_c4 (gfc_array_c4 * const restrict ret,
       src = pptr;
       sptr = pptr;
       sdim = pdim;
-      for (dim = 0; dim < pdim; dim++)
+      for (index_type dim = 0; dim < pdim; dim++)
 	{
 	  scount[dim] = pcount[dim];
 	  sextent[dim] = pextent[dim];
@@ -303,7 +302,7 @@  reshape_c4 (gfc_array_c4 * const restrict ret,
       scount[0]++;
 
       /* Advance to the next destination element.  */
-      n = 0;
+      index_type n = 0;
       while (rcount[n] == rextent[n])
         {
           /* When we get to the end of a dimension, reset it and increment
@@ -343,7 +342,7 @@  reshape_c4 (gfc_array_c4 * const restrict ret,
                   /* Switch to the pad array.  */
                   sptr = NULL;
                   sdim = pdim;
-                  for (dim = 0; dim < pdim; dim++)
+                  for (index_type dim = 0; dim < pdim; dim++)
                     {
                       scount[dim] = pcount[dim];
                       sextent[dim] = pextent[dim];
diff --git a/libgfortran/generated/reshape_c8.c b/libgfortran/generated/reshape_c8.c
index 88d03d7..b0ecc89 100644
--- a/libgfortran/generated/reshape_c8.c
+++ b/libgfortran/generated/reshape_c8.c
@@ -72,8 +72,6 @@  reshape_c8 (gfc_array_c8 * const restrict ret,
   const GFC_COMPLEX_8 *pptr;
 
   const GFC_COMPLEX_8 *src;
-  int n;
-  int dim;
   int sempty, pempty, shape_empty;
   index_type shape_data[GFC_MAX_DIMENSIONS];
 
@@ -87,7 +85,7 @@  reshape_c8 (gfc_array_c8 * const restrict ret,
 
   shape_empty = 0;
 
-  for (n = 0; n < rdim; n++)
+  for (index_type n = 0; n < rdim; n++)
     {
       shape_data[n] = shape->base_addr[n * GFC_DESCRIPTOR_STRIDE(shape,0)];
       if (shape_data[n] <= 0)
@@ -102,7 +100,7 @@  reshape_c8 (gfc_array_c8 * const restrict ret,
       index_type alloc_size;
 
       rs = 1;
-      for (n = 0; n < rdim; n++)
+      for (index_type n = 0; n < rdim; n++)
 	{
 	  rex = shape_data[n];
 
@@ -129,7 +127,7 @@  reshape_c8 (gfc_array_c8 * const restrict ret,
       pdim = GFC_DESCRIPTOR_RANK (pad);
       psize = 1;
       pempty = 0;
-      for (n = 0; n < pdim; n++)
+      for (index_type n = 0; n < pdim; n++)
         {
           pcount[n] = 0;
           pstride[n] = GFC_DESCRIPTOR_STRIDE(pad,n);
@@ -160,7 +158,7 @@  reshape_c8 (gfc_array_c8 * const restrict ret,
       index_type ret_extent, source_extent;
 
       rs = 1;
-      for (n = 0; n < rdim; n++)
+      for (index_type n = 0; n < rdim; n++)
 	{
 	  rs *= shape_data[n];
 	  ret_extent = GFC_DESCRIPTOR_EXTENT(ret,n);
@@ -173,7 +171,7 @@  reshape_c8 (gfc_array_c8 * const restrict ret,
 
       source_extent = 1;
       sdim = GFC_DESCRIPTOR_RANK (source);
-      for (n = 0; n < sdim; n++)
+      for (index_type n = 0; n < sdim; n++)
 	{
 	  index_type se;
 	  se = GFC_DESCRIPTOR_EXTENT(source,n);
@@ -190,10 +188,10 @@  reshape_c8 (gfc_array_c8 * const restrict ret,
 	  int seen[GFC_MAX_DIMENSIONS];
 	  index_type v;
 
-	  for (n = 0; n < rdim; n++)
+	  for (index_type n = 0; n < rdim; n++)
 	    seen[n] = 0;
 
-	  for (n = 0; n < rdim; n++)
+	  for (index_type n = 0; n < rdim; n++)
 	    {
 	      v = order->base_addr[n * GFC_DESCRIPTOR_STRIDE(order,0)] - 1;
 
@@ -211,8 +209,9 @@  reshape_c8 (gfc_array_c8 * const restrict ret,
     }
 
   rsize = 1;
-  for (n = 0; n < rdim; n++)
+  for (index_type n = 0; n < rdim; n++)
     {
+      index_type dim;
       if (order)
         dim = order->base_addr[n * GFC_DESCRIPTOR_STRIDE(order,0)] - 1;
       else
@@ -243,7 +242,7 @@  reshape_c8 (gfc_array_c8 * const restrict ret,
 
   ssize = 1;
   sempty = 0;
-  for (n = 0; n < sdim; n++)
+  for (index_type n = 0; n < sdim; n++)
     {
       scount[n] = 0;
       sstride[n] = GFC_DESCRIPTOR_STRIDE(source,n);
@@ -283,7 +282,7 @@  reshape_c8 (gfc_array_c8 * const restrict ret,
       src = pptr;
       sptr = pptr;
       sdim = pdim;
-      for (dim = 0; dim < pdim; dim++)
+      for (index_type dim = 0; dim < pdim; dim++)
 	{
 	  scount[dim] = pcount[dim];
 	  sextent[dim] = pextent[dim];
@@ -303,7 +302,7 @@  reshape_c8 (gfc_array_c8 * const restrict ret,
       scount[0]++;
 
       /* Advance to the next destination element.  */
-      n = 0;
+      index_type n = 0;
       while (rcount[n] == rextent[n])
         {
           /* When we get to the end of a dimension, reset it and increment
@@ -343,7 +342,7 @@  reshape_c8 (gfc_array_c8 * const restrict ret,
                   /* Switch to the pad array.  */
                   sptr = NULL;
                   sdim = pdim;
-                  for (dim = 0; dim < pdim; dim++)
+                  for (index_type dim = 0; dim < pdim; dim++)
                     {
                       scount[dim] = pcount[dim];
                       sextent[dim] = pextent[dim];
diff --git a/libgfortran/generated/reshape_i16.c b/libgfortran/generated/reshape_i16.c
index fd5e8e7..e0fcb30 100644
--- a/libgfortran/generated/reshape_i16.c
+++ b/libgfortran/generated/reshape_i16.c
@@ -72,8 +72,6 @@  reshape_16 (gfc_array_i16 * const restrict ret,
   const GFC_INTEGER_16 *pptr;
 
   const GFC_INTEGER_16 *src;
-  int n;
-  int dim;
   int sempty, pempty, shape_empty;
   index_type shape_data[GFC_MAX_DIMENSIONS];
 
@@ -87,7 +85,7 @@  reshape_16 (gfc_array_i16 * const restrict ret,
 
   shape_empty = 0;
 
-  for (n = 0; n < rdim; n++)
+  for (index_type n = 0; n < rdim; n++)
     {
       shape_data[n] = shape->base_addr[n * GFC_DESCRIPTOR_STRIDE(shape,0)];
       if (shape_data[n] <= 0)
@@ -102,7 +100,7 @@  reshape_16 (gfc_array_i16 * const restrict ret,
       index_type alloc_size;
 
       rs = 1;
-      for (n = 0; n < rdim; n++)
+      for (index_type n = 0; n < rdim; n++)
 	{
 	  rex = shape_data[n];
 
@@ -129,7 +127,7 @@  reshape_16 (gfc_array_i16 * const restrict ret,
       pdim = GFC_DESCRIPTOR_RANK (pad);
       psize = 1;
       pempty = 0;
-      for (n = 0; n < pdim; n++)
+      for (index_type n = 0; n < pdim; n++)
         {
           pcount[n] = 0;
           pstride[n] = GFC_DESCRIPTOR_STRIDE(pad,n);
@@ -160,7 +158,7 @@  reshape_16 (gfc_array_i16 * const restrict ret,
       index_type ret_extent, source_extent;
 
       rs = 1;
-      for (n = 0; n < rdim; n++)
+      for (index_type n = 0; n < rdim; n++)
 	{
 	  rs *= shape_data[n];
 	  ret_extent = GFC_DESCRIPTOR_EXTENT(ret,n);
@@ -173,7 +171,7 @@  reshape_16 (gfc_array_i16 * const restrict ret,
 
       source_extent = 1;
       sdim = GFC_DESCRIPTOR_RANK (source);
-      for (n = 0; n < sdim; n++)
+      for (index_type n = 0; n < sdim; n++)
 	{
 	  index_type se;
 	  se = GFC_DESCRIPTOR_EXTENT(source,n);
@@ -190,10 +188,10 @@  reshape_16 (gfc_array_i16 * const restrict ret,
 	  int seen[GFC_MAX_DIMENSIONS];
 	  index_type v;
 
-	  for (n = 0; n < rdim; n++)
+	  for (index_type n = 0; n < rdim; n++)
 	    seen[n] = 0;
 
-	  for (n = 0; n < rdim; n++)
+	  for (index_type n = 0; n < rdim; n++)
 	    {
 	      v = order->base_addr[n * GFC_DESCRIPTOR_STRIDE(order,0)] - 1;
 
@@ -211,8 +209,9 @@  reshape_16 (gfc_array_i16 * const restrict ret,
     }
 
   rsize = 1;
-  for (n = 0; n < rdim; n++)
+  for (index_type n = 0; n < rdim; n++)
     {
+      index_type dim;
       if (order)
         dim = order->base_addr[n * GFC_DESCRIPTOR_STRIDE(order,0)] - 1;
       else
@@ -243,7 +242,7 @@  reshape_16 (gfc_array_i16 * const restrict ret,
 
   ssize = 1;
   sempty = 0;
-  for (n = 0; n < sdim; n++)
+  for (index_type n = 0; n < sdim; n++)
     {
       scount[n] = 0;
       sstride[n] = GFC_DESCRIPTOR_STRIDE(source,n);
@@ -283,7 +282,7 @@  reshape_16 (gfc_array_i16 * const restrict ret,
       src = pptr;
       sptr = pptr;
       sdim = pdim;
-      for (dim = 0; dim < pdim; dim++)
+      for (index_type dim = 0; dim < pdim; dim++)
 	{
 	  scount[dim] = pcount[dim];
 	  sextent[dim] = pextent[dim];
@@ -303,7 +302,7 @@  reshape_16 (gfc_array_i16 * const restrict ret,
       scount[0]++;
 
       /* Advance to the next destination element.  */
-      n = 0;
+      index_type n = 0;
       while (rcount[n] == rextent[n])
         {
           /* When we get to the end of a dimension, reset it and increment
@@ -343,7 +342,7 @@  reshape_16 (gfc_array_i16 * const restrict ret,
                   /* Switch to the pad array.  */
                   sptr = NULL;
                   sdim = pdim;
-                  for (dim = 0; dim < pdim; dim++)
+                  for (index_type dim = 0; dim < pdim; dim++)
                     {
                       scount[dim] = pcount[dim];
                       sextent[dim] = pextent[dim];
diff --git a/libgfortran/generated/reshape_i4.c b/libgfortran/generated/reshape_i4.c
index 149d185..ed4b3d3 100644
--- a/libgfortran/generated/reshape_i4.c
+++ b/libgfortran/generated/reshape_i4.c
@@ -72,8 +72,6 @@  reshape_4 (gfc_array_i4 * const restrict ret,
   const GFC_INTEGER_4 *pptr;
 
   const GFC_INTEGER_4 *src;
-  int n;
-  int dim;
   int sempty, pempty, shape_empty;
   index_type shape_data[GFC_MAX_DIMENSIONS];
 
@@ -87,7 +85,7 @@  reshape_4 (gfc_array_i4 * const restrict ret,
 
   shape_empty = 0;
 
-  for (n = 0; n < rdim; n++)
+  for (index_type n = 0; n < rdim; n++)
     {
       shape_data[n] = shape->base_addr[n * GFC_DESCRIPTOR_STRIDE(shape,0)];
       if (shape_data[n] <= 0)
@@ -102,7 +100,7 @@  reshape_4 (gfc_array_i4 * const restrict ret,
       index_type alloc_size;
 
       rs = 1;
-      for (n = 0; n < rdim; n++)
+      for (index_type n = 0; n < rdim; n++)
 	{
 	  rex = shape_data[n];
 
@@ -129,7 +127,7 @@  reshape_4 (gfc_array_i4 * const restrict ret,
       pdim = GFC_DESCRIPTOR_RANK (pad);
       psize = 1;
       pempty = 0;
-      for (n = 0; n < pdim; n++)
+      for (index_type n = 0; n < pdim; n++)
         {
           pcount[n] = 0;
           pstride[n] = GFC_DESCRIPTOR_STRIDE(pad,n);
@@ -160,7 +158,7 @@  reshape_4 (gfc_array_i4 * const restrict ret,
       index_type ret_extent, source_extent;
 
       rs = 1;
-      for (n = 0; n < rdim; n++)
+      for (index_type n = 0; n < rdim; n++)
 	{
 	  rs *= shape_data[n];
 	  ret_extent = GFC_DESCRIPTOR_EXTENT(ret,n);
@@ -173,7 +171,7 @@  reshape_4 (gfc_array_i4 * const restrict ret,
 
       source_extent = 1;
       sdim = GFC_DESCRIPTOR_RANK (source);
-      for (n = 0; n < sdim; n++)
+      for (index_type n = 0; n < sdim; n++)
 	{
 	  index_type se;
 	  se = GFC_DESCRIPTOR_EXTENT(source,n);
@@ -190,10 +188,10 @@  reshape_4 (gfc_array_i4 * const restrict ret,
 	  int seen[GFC_MAX_DIMENSIONS];
 	  index_type v;
 
-	  for (n = 0; n < rdim; n++)
+	  for (index_type n = 0; n < rdim; n++)
 	    seen[n] = 0;
 
-	  for (n = 0; n < rdim; n++)
+	  for (index_type n = 0; n < rdim; n++)
 	    {
 	      v = order->base_addr[n * GFC_DESCRIPTOR_STRIDE(order,0)] - 1;
 
@@ -211,8 +209,9 @@  reshape_4 (gfc_array_i4 * const restrict ret,
     }
 
   rsize = 1;
-  for (n = 0; n < rdim; n++)
+  for (index_type n = 0; n < rdim; n++)
     {
+      index_type dim;
       if (order)
         dim = order->base_addr[n * GFC_DESCRIPTOR_STRIDE(order,0)] - 1;
       else
@@ -243,7 +242,7 @@  reshape_4 (gfc_array_i4 * const restrict ret,
 
   ssize = 1;
   sempty = 0;
-  for (n = 0; n < sdim; n++)
+  for (index_type n = 0; n < sdim; n++)
     {
       scount[n] = 0;
       sstride[n] = GFC_DESCRIPTOR_STRIDE(source,n);
@@ -283,7 +282,7 @@  reshape_4 (gfc_array_i4 * const restrict ret,
       src = pptr;
       sptr = pptr;
       sdim = pdim;
-      for (dim = 0; dim < pdim; dim++)
+      for (index_type dim = 0; dim < pdim; dim++)
 	{
 	  scount[dim] = pcount[dim];
 	  sextent[dim] = pextent[dim];
@@ -303,7 +302,7 @@  reshape_4 (gfc_array_i4 * const restrict ret,
       scount[0]++;
 
       /* Advance to the next destination element.  */
-      n = 0;
+      index_type n = 0;
       while (rcount[n] == rextent[n])
         {
           /* When we get to the end of a dimension, reset it and increment
@@ -343,7 +342,7 @@  reshape_4 (gfc_array_i4 * const restrict ret,
                   /* Switch to the pad array.  */
                   sptr = NULL;
                   sdim = pdim;
-                  for (dim = 0; dim < pdim; dim++)
+                  for (index_type dim = 0; dim < pdim; dim++)
                     {
                       scount[dim] = pcount[dim];
                       sextent[dim] = pextent[dim];
diff --git a/libgfortran/generated/reshape_i8.c b/libgfortran/generated/reshape_i8.c
index a4c95a2..60ea347 100644
--- a/libgfortran/generated/reshape_i8.c
+++ b/libgfortran/generated/reshape_i8.c
@@ -72,8 +72,6 @@  reshape_8 (gfc_array_i8 * const restrict ret,
   const GFC_INTEGER_8 *pptr;
 
   const GFC_INTEGER_8 *src;
-  int n;
-  int dim;
   int sempty, pempty, shape_empty;
   index_type shape_data[GFC_MAX_DIMENSIONS];
 
@@ -87,7 +85,7 @@  reshape_8 (gfc_array_i8 * const restrict ret,
 
   shape_empty = 0;
 
-  for (n = 0; n < rdim; n++)
+  for (index_type n = 0; n < rdim; n++)
     {
       shape_data[n] = shape->base_addr[n * GFC_DESCRIPTOR_STRIDE(shape,0)];
       if (shape_data[n] <= 0)
@@ -102,7 +100,7 @@  reshape_8 (gfc_array_i8 * const restrict ret,
       index_type alloc_size;
 
       rs = 1;
-      for (n = 0; n < rdim; n++)
+      for (index_type n = 0; n < rdim; n++)
 	{
 	  rex = shape_data[n];
 
@@ -129,7 +127,7 @@  reshape_8 (gfc_array_i8 * const restrict ret,
       pdim = GFC_DESCRIPTOR_RANK (pad);
       psize = 1;
       pempty = 0;
-      for (n = 0; n < pdim; n++)
+      for (index_type n = 0; n < pdim; n++)
         {
           pcount[n] = 0;
           pstride[n] = GFC_DESCRIPTOR_STRIDE(pad,n);
@@ -160,7 +158,7 @@  reshape_8 (gfc_array_i8 * const restrict ret,
       index_type ret_extent, source_extent;
 
       rs = 1;
-      for (n = 0; n < rdim; n++)
+      for (index_type n = 0; n < rdim; n++)
 	{
 	  rs *= shape_data[n];
 	  ret_extent = GFC_DESCRIPTOR_EXTENT(ret,n);
@@ -173,7 +171,7 @@  reshape_8 (gfc_array_i8 * const restrict ret,
 
       source_extent = 1;
       sdim = GFC_DESCRIPTOR_RANK (source);
-      for (n = 0; n < sdim; n++)
+      for (index_type n = 0; n < sdim; n++)
 	{
 	  index_type se;
 	  se = GFC_DESCRIPTOR_EXTENT(source,n);
@@ -190,10 +188,10 @@  reshape_8 (gfc_array_i8 * const restrict ret,
 	  int seen[GFC_MAX_DIMENSIONS];
 	  index_type v;
 
-	  for (n = 0; n < rdim; n++)
+	  for (index_type n = 0; n < rdim; n++)
 	    seen[n] = 0;
 
-	  for (n = 0; n < rdim; n++)
+	  for (index_type n = 0; n < rdim; n++)
 	    {
 	      v = order->base_addr[n * GFC_DESCRIPTOR_STRIDE(order,0)] - 1;
 
@@ -211,8 +209,9 @@  reshape_8 (gfc_array_i8 * const restrict ret,
     }
 
   rsize = 1;
-  for (n = 0; n < rdim; n++)
+  for (index_type n = 0; n < rdim; n++)
     {
+      index_type dim;
       if (order)
         dim = order->base_addr[n * GFC_DESCRIPTOR_STRIDE(order,0)] - 1;
       else
@@ -243,7 +242,7 @@  reshape_8 (gfc_array_i8 * const restrict ret,
 
   ssize = 1;
   sempty = 0;
-  for (n = 0; n < sdim; n++)
+  for (index_type n = 0; n < sdim; n++)
     {
       scount[n] = 0;
       sstride[n] = GFC_DESCRIPTOR_STRIDE(source,n);
@@ -283,7 +282,7 @@  reshape_8 (gfc_array_i8 * const restrict ret,
       src = pptr;
       sptr = pptr;
       sdim = pdim;
-      for (dim = 0; dim < pdim; dim++)
+      for (index_type dim = 0; dim < pdim; dim++)
 	{
 	  scount[dim] = pcount[dim];
 	  sextent[dim] = pextent[dim];
@@ -303,7 +302,7 @@  reshape_8 (gfc_array_i8 * const restrict ret,
       scount[0]++;
 
       /* Advance to the next destination element.  */
-      n = 0;
+      index_type n = 0;
       while (rcount[n] == rextent[n])
         {
           /* When we get to the end of a dimension, reset it and increment
@@ -343,7 +342,7 @@  reshape_8 (gfc_array_i8 * const restrict ret,
                   /* Switch to the pad array.  */
                   sptr = NULL;
                   sdim = pdim;
-                  for (dim = 0; dim < pdim; dim++)
+                  for (index_type dim = 0; dim < pdim; dim++)
                     {
                       scount[dim] = pcount[dim];
                       sextent[dim] = pextent[dim];
diff --git a/libgfortran/generated/reshape_r10.c b/libgfortran/generated/reshape_r10.c
index 47e803f..98f36f4 100644
--- a/libgfortran/generated/reshape_r10.c
+++ b/libgfortran/generated/reshape_r10.c
@@ -72,8 +72,6 @@  reshape_r10 (gfc_array_r10 * const restrict ret,
   const GFC_REAL_10 *pptr;
 
   const GFC_REAL_10 *src;
-  int n;
-  int dim;
   int sempty, pempty, shape_empty;
   index_type shape_data[GFC_MAX_DIMENSIONS];
 
@@ -87,7 +85,7 @@  reshape_r10 (gfc_array_r10 * const restrict ret,
 
   shape_empty = 0;
 
-  for (n = 0; n < rdim; n++)
+  for (index_type n = 0; n < rdim; n++)
     {
       shape_data[n] = shape->base_addr[n * GFC_DESCRIPTOR_STRIDE(shape,0)];
       if (shape_data[n] <= 0)
@@ -102,7 +100,7 @@  reshape_r10 (gfc_array_r10 * const restrict ret,
       index_type alloc_size;
 
       rs = 1;
-      for (n = 0; n < rdim; n++)
+      for (index_type n = 0; n < rdim; n++)
 	{
 	  rex = shape_data[n];
 
@@ -129,7 +127,7 @@  reshape_r10 (gfc_array_r10 * const restrict ret,
       pdim = GFC_DESCRIPTOR_RANK (pad);
       psize = 1;
       pempty = 0;
-      for (n = 0; n < pdim; n++)
+      for (index_type n = 0; n < pdim; n++)
         {
           pcount[n] = 0;
           pstride[n] = GFC_DESCRIPTOR_STRIDE(pad,n);
@@ -160,7 +158,7 @@  reshape_r10 (gfc_array_r10 * const restrict ret,
       index_type ret_extent, source_extent;
 
       rs = 1;
-      for (n = 0; n < rdim; n++)
+      for (index_type n = 0; n < rdim; n++)
 	{
 	  rs *= shape_data[n];
 	  ret_extent = GFC_DESCRIPTOR_EXTENT(ret,n);
@@ -173,7 +171,7 @@  reshape_r10 (gfc_array_r10 * const restrict ret,
 
       source_extent = 1;
       sdim = GFC_DESCRIPTOR_RANK (source);
-      for (n = 0; n < sdim; n++)
+      for (index_type n = 0; n < sdim; n++)
 	{
 	  index_type se;
 	  se = GFC_DESCRIPTOR_EXTENT(source,n);
@@ -190,10 +188,10 @@  reshape_r10 (gfc_array_r10 * const restrict ret,
 	  int seen[GFC_MAX_DIMENSIONS];
 	  index_type v;
 
-	  for (n = 0; n < rdim; n++)
+	  for (index_type n = 0; n < rdim; n++)
 	    seen[n] = 0;
 
-	  for (n = 0; n < rdim; n++)
+	  for (index_type n = 0; n < rdim; n++)
 	    {
 	      v = order->base_addr[n * GFC_DESCRIPTOR_STRIDE(order,0)] - 1;
 
@@ -211,8 +209,9 @@  reshape_r10 (gfc_array_r10 * const restrict ret,
     }
 
   rsize = 1;
-  for (n = 0; n < rdim; n++)
+  for (index_type n = 0; n < rdim; n++)
     {
+      index_type dim;
       if (order)
         dim = order->base_addr[n * GFC_DESCRIPTOR_STRIDE(order,0)] - 1;
       else
@@ -243,7 +242,7 @@  reshape_r10 (gfc_array_r10 * const restrict ret,
 
   ssize = 1;
   sempty = 0;
-  for (n = 0; n < sdim; n++)
+  for (index_type n = 0; n < sdim; n++)
     {
       scount[n] = 0;
       sstride[n] = GFC_DESCRIPTOR_STRIDE(source,n);
@@ -283,7 +282,7 @@  reshape_r10 (gfc_array_r10 * const restrict ret,
       src = pptr;
       sptr = pptr;
       sdim = pdim;
-      for (dim = 0; dim < pdim; dim++)
+      for (index_type dim = 0; dim < pdim; dim++)
 	{
 	  scount[dim] = pcount[dim];
 	  sextent[dim] = pextent[dim];
@@ -303,7 +302,7 @@  reshape_r10 (gfc_array_r10 * const restrict ret,
       scount[0]++;
 
       /* Advance to the next destination element.  */
-      n = 0;
+      index_type n = 0;
       while (rcount[n] == rextent[n])
         {
           /* When we get to the end of a dimension, reset it and increment
@@ -343,7 +342,7 @@  reshape_r10 (gfc_array_r10 * const restrict ret,
                   /* Switch to the pad array.  */
                   sptr = NULL;
                   sdim = pdim;
-                  for (dim = 0; dim < pdim; dim++)
+                  for (index_type dim = 0; dim < pdim; dim++)
                     {
                       scount[dim] = pcount[dim];
                       sextent[dim] = pextent[dim];
diff --git a/libgfortran/generated/reshape_r16.c b/libgfortran/generated/reshape_r16.c
index c210dfd..96fe1eb 100644
--- a/libgfortran/generated/reshape_r16.c
+++ b/libgfortran/generated/reshape_r16.c
@@ -72,8 +72,6 @@  reshape_r16 (gfc_array_r16 * const restrict ret,
   const GFC_REAL_16 *pptr;
 
   const GFC_REAL_16 *src;
-  int n;
-  int dim;
   int sempty, pempty, shape_empty;
   index_type shape_data[GFC_MAX_DIMENSIONS];
 
@@ -87,7 +85,7 @@  reshape_r16 (gfc_array_r16 * const restrict ret,
 
   shape_empty = 0;
 
-  for (n = 0; n < rdim; n++)
+  for (index_type n = 0; n < rdim; n++)
     {
       shape_data[n] = shape->base_addr[n * GFC_DESCRIPTOR_STRIDE(shape,0)];
       if (shape_data[n] <= 0)
@@ -102,7 +100,7 @@  reshape_r16 (gfc_array_r16 * const restrict ret,
       index_type alloc_size;
 
       rs = 1;
-      for (n = 0; n < rdim; n++)
+      for (index_type n = 0; n < rdim; n++)
 	{
 	  rex = shape_data[n];
 
@@ -129,7 +127,7 @@  reshape_r16 (gfc_array_r16 * const restrict ret,
       pdim = GFC_DESCRIPTOR_RANK (pad);
       psize = 1;
       pempty = 0;
-      for (n = 0; n < pdim; n++)
+      for (index_type n = 0; n < pdim; n++)
         {
           pcount[n] = 0;
           pstride[n] = GFC_DESCRIPTOR_STRIDE(pad,n);
@@ -160,7 +158,7 @@  reshape_r16 (gfc_array_r16 * const restrict ret,
       index_type ret_extent, source_extent;
 
       rs = 1;
-      for (n = 0; n < rdim; n++)
+      for (index_type n = 0; n < rdim; n++)
 	{
 	  rs *= shape_data[n];
 	  ret_extent = GFC_DESCRIPTOR_EXTENT(ret,n);
@@ -173,7 +171,7 @@  reshape_r16 (gfc_array_r16 * const restrict ret,
 
       source_extent = 1;
       sdim = GFC_DESCRIPTOR_RANK (source);
-      for (n = 0; n < sdim; n++)
+      for (index_type n = 0; n < sdim; n++)
 	{
 	  index_type se;
 	  se = GFC_DESCRIPTOR_EXTENT(source,n);
@@ -190,10 +188,10 @@  reshape_r16 (gfc_array_r16 * const restrict ret,
 	  int seen[GFC_MAX_DIMENSIONS];
 	  index_type v;
 
-	  for (n = 0; n < rdim; n++)
+	  for (index_type n = 0; n < rdim; n++)
 	    seen[n] = 0;
 
-	  for (n = 0; n < rdim; n++)
+	  for (index_type n = 0; n < rdim; n++)
 	    {
 	      v = order->base_addr[n * GFC_DESCRIPTOR_STRIDE(order,0)] - 1;
 
@@ -211,8 +209,9 @@  reshape_r16 (gfc_array_r16 * const restrict ret,
     }
 
   rsize = 1;
-  for (n = 0; n < rdim; n++)
+  for (index_type n = 0; n < rdim; n++)
     {
+      index_type dim;
       if (order)
         dim = order->base_addr[n * GFC_DESCRIPTOR_STRIDE(order,0)] - 1;
       else
@@ -243,7 +242,7 @@  reshape_r16 (gfc_array_r16 * const restrict ret,
 
   ssize = 1;
   sempty = 0;
-  for (n = 0; n < sdim; n++)
+  for (index_type n = 0; n < sdim; n++)
     {
       scount[n] = 0;
       sstride[n] = GFC_DESCRIPTOR_STRIDE(source,n);
@@ -283,7 +282,7 @@  reshape_r16 (gfc_array_r16 * const restrict ret,
       src = pptr;
       sptr = pptr;
       sdim = pdim;
-      for (dim = 0; dim < pdim; dim++)
+      for (index_type dim = 0; dim < pdim; dim++)
 	{
 	  scount[dim] = pcount[dim];
 	  sextent[dim] = pextent[dim];
@@ -303,7 +302,7 @@  reshape_r16 (gfc_array_r16 * const restrict ret,
       scount[0]++;
 
       /* Advance to the next destination element.  */
-      n = 0;
+      index_type n = 0;
       while (rcount[n] == rextent[n])
         {
           /* When we get to the end of a dimension, reset it and increment
@@ -343,7 +342,7 @@  reshape_r16 (gfc_array_r16 * const restrict ret,
                   /* Switch to the pad array.  */
                   sptr = NULL;
                   sdim = pdim;
-                  for (dim = 0; dim < pdim; dim++)
+                  for (index_type dim = 0; dim < pdim; dim++)
                     {
                       scount[dim] = pcount[dim];
                       sextent[dim] = pextent[dim];
diff --git a/libgfortran/generated/reshape_r4.c b/libgfortran/generated/reshape_r4.c
index a4f9b07..2a3d0cf 100644
--- a/libgfortran/generated/reshape_r4.c
+++ b/libgfortran/generated/reshape_r4.c
@@ -72,8 +72,6 @@  reshape_r4 (gfc_array_r4 * const restrict ret,
   const GFC_REAL_4 *pptr;
 
   const GFC_REAL_4 *src;
-  int n;
-  int dim;
   int sempty, pempty, shape_empty;
   index_type shape_data[GFC_MAX_DIMENSIONS];
 
@@ -87,7 +85,7 @@  reshape_r4 (gfc_array_r4 * const restrict ret,
 
   shape_empty = 0;
 
-  for (n = 0; n < rdim; n++)
+  for (index_type n = 0; n < rdim; n++)
     {
       shape_data[n] = shape->base_addr[n * GFC_DESCRIPTOR_STRIDE(shape,0)];
       if (shape_data[n] <= 0)
@@ -102,7 +100,7 @@  reshape_r4 (gfc_array_r4 * const restrict ret,
       index_type alloc_size;
 
       rs = 1;
-      for (n = 0; n < rdim; n++)
+      for (index_type n = 0; n < rdim; n++)
 	{
 	  rex = shape_data[n];
 
@@ -129,7 +127,7 @@  reshape_r4 (gfc_array_r4 * const restrict ret,
       pdim = GFC_DESCRIPTOR_RANK (pad);
       psize = 1;
       pempty = 0;
-      for (n = 0; n < pdim; n++)
+      for (index_type n = 0; n < pdim; n++)
         {
           pcount[n] = 0;
           pstride[n] = GFC_DESCRIPTOR_STRIDE(pad,n);
@@ -160,7 +158,7 @@  reshape_r4 (gfc_array_r4 * const restrict ret,
       index_type ret_extent, source_extent;
 
       rs = 1;
-      for (n = 0; n < rdim; n++)
+      for (index_type n = 0; n < rdim; n++)
 	{
 	  rs *= shape_data[n];
 	  ret_extent = GFC_DESCRIPTOR_EXTENT(ret,n);
@@ -173,7 +171,7 @@  reshape_r4 (gfc_array_r4 * const restrict ret,
 
       source_extent = 1;
       sdim = GFC_DESCRIPTOR_RANK (source);
-      for (n = 0; n < sdim; n++)
+      for (index_type n = 0; n < sdim; n++)
 	{
 	  index_type se;
 	  se = GFC_DESCRIPTOR_EXTENT(source,n);
@@ -190,10 +188,10 @@  reshape_r4 (gfc_array_r4 * const restrict ret,
 	  int seen[GFC_MAX_DIMENSIONS];
 	  index_type v;
 
-	  for (n = 0; n < rdim; n++)
+	  for (index_type n = 0; n < rdim; n++)
 	    seen[n] = 0;
 
-	  for (n = 0; n < rdim; n++)
+	  for (index_type n = 0; n < rdim; n++)
 	    {
 	      v = order->base_addr[n * GFC_DESCRIPTOR_STRIDE(order,0)] - 1;
 
@@ -211,8 +209,9 @@  reshape_r4 (gfc_array_r4 * const restrict ret,
     }
 
   rsize = 1;
-  for (n = 0; n < rdim; n++)
+  for (index_type n = 0; n < rdim; n++)
     {
+      index_type dim;
       if (order)
         dim = order->base_addr[n * GFC_DESCRIPTOR_STRIDE(order,0)] - 1;
       else
@@ -243,7 +242,7 @@  reshape_r4 (gfc_array_r4 * const restrict ret,
 
   ssize = 1;
   sempty = 0;
-  for (n = 0; n < sdim; n++)
+  for (index_type n = 0; n < sdim; n++)
     {
       scount[n] = 0;
       sstride[n] = GFC_DESCRIPTOR_STRIDE(source,n);
@@ -283,7 +282,7 @@  reshape_r4 (gfc_array_r4 * const restrict ret,
       src = pptr;
       sptr = pptr;
       sdim = pdim;
-      for (dim = 0; dim < pdim; dim++)
+      for (index_type dim = 0; dim < pdim; dim++)
 	{
 	  scount[dim] = pcount[dim];
 	  sextent[dim] = pextent[dim];
@@ -303,7 +302,7 @@  reshape_r4 (gfc_array_r4 * const restrict ret,
       scount[0]++;
 
       /* Advance to the next destination element.  */
-      n = 0;
+      index_type n = 0;
       while (rcount[n] == rextent[n])
         {
           /* When we get to the end of a dimension, reset it and increment
@@ -343,7 +342,7 @@  reshape_r4 (gfc_array_r4 * const restrict ret,
                   /* Switch to the pad array.  */
                   sptr = NULL;
                   sdim = pdim;
-                  for (dim = 0; dim < pdim; dim++)
+                  for (index_type dim = 0; dim < pdim; dim++)
                     {
                       scount[dim] = pcount[dim];
                       sextent[dim] = pextent[dim];
diff --git a/libgfortran/generated/reshape_r8.c b/libgfortran/generated/reshape_r8.c
index 955463c..b88fd63 100644
--- a/libgfortran/generated/reshape_r8.c
+++ b/libgfortran/generated/reshape_r8.c
@@ -72,8 +72,6 @@  reshape_r8 (gfc_array_r8 * const restrict ret,
   const GFC_REAL_8 *pptr;
 
   const GFC_REAL_8 *src;
-  int n;
-  int dim;
   int sempty, pempty, shape_empty;
   index_type shape_data[GFC_MAX_DIMENSIONS];
 
@@ -87,7 +85,7 @@  reshape_r8 (gfc_array_r8 * const restrict ret,
 
   shape_empty = 0;
 
-  for (n = 0; n < rdim; n++)
+  for (index_type n = 0; n < rdim; n++)
     {
       shape_data[n] = shape->base_addr[n * GFC_DESCRIPTOR_STRIDE(shape,0)];
       if (shape_data[n] <= 0)
@@ -102,7 +100,7 @@  reshape_r8 (gfc_array_r8 * const restrict ret,
       index_type alloc_size;
 
       rs = 1;
-      for (n = 0; n < rdim; n++)
+      for (index_type n = 0; n < rdim; n++)
 	{
 	  rex = shape_data[n];
 
@@ -129,7 +127,7 @@  reshape_r8 (gfc_array_r8 * const restrict ret,
       pdim = GFC_DESCRIPTOR_RANK (pad);
       psize = 1;
       pempty = 0;
-      for (n = 0; n < pdim; n++)
+      for (index_type n = 0; n < pdim; n++)
         {
           pcount[n] = 0;
           pstride[n] = GFC_DESCRIPTOR_STRIDE(pad,n);
@@ -160,7 +158,7 @@  reshape_r8 (gfc_array_r8 * const restrict ret,
       index_type ret_extent, source_extent;
 
       rs = 1;
-      for (n = 0; n < rdim; n++)
+      for (index_type n = 0; n < rdim; n++)
 	{
 	  rs *= shape_data[n];
 	  ret_extent = GFC_DESCRIPTOR_EXTENT(ret,n);
@@ -173,7 +171,7 @@  reshape_r8 (gfc_array_r8 * const restrict ret,
 
       source_extent = 1;
       sdim = GFC_DESCRIPTOR_RANK (source);
-      for (n = 0; n < sdim; n++)
+      for (index_type n = 0; n < sdim; n++)
 	{
 	  index_type se;
 	  se = GFC_DESCRIPTOR_EXTENT(source,n);
@@ -190,10 +188,10 @@  reshape_r8 (gfc_array_r8 * const restrict ret,
 	  int seen[GFC_MAX_DIMENSIONS];
 	  index_type v;
 
-	  for (n = 0; n < rdim; n++)
+	  for (index_type n = 0; n < rdim; n++)
 	    seen[n] = 0;
 
-	  for (n = 0; n < rdim; n++)
+	  for (index_type n = 0; n < rdim; n++)
 	    {
 	      v = order->base_addr[n * GFC_DESCRIPTOR_STRIDE(order,0)] - 1;
 
@@ -211,8 +209,9 @@  reshape_r8 (gfc_array_r8 * const restrict ret,
     }
 
   rsize = 1;
-  for (n = 0; n < rdim; n++)
+  for (index_type n = 0; n < rdim; n++)
     {
+      index_type dim;
       if (order)
         dim = order->base_addr[n * GFC_DESCRIPTOR_STRIDE(order,0)] - 1;
       else
@@ -243,7 +242,7 @@  reshape_r8 (gfc_array_r8 * const restrict ret,
 
   ssize = 1;
   sempty = 0;
-  for (n = 0; n < sdim; n++)
+  for (index_type n = 0; n < sdim; n++)
     {
       scount[n] = 0;
       sstride[n] = GFC_DESCRIPTOR_STRIDE(source,n);
@@ -283,7 +282,7 @@  reshape_r8 (gfc_array_r8 * const restrict ret,
       src = pptr;
       sptr = pptr;
       sdim = pdim;
-      for (dim = 0; dim < pdim; dim++)
+      for (index_type dim = 0; dim < pdim; dim++)
 	{
 	  scount[dim] = pcount[dim];
 	  sextent[dim] = pextent[dim];
@@ -303,7 +302,7 @@  reshape_r8 (gfc_array_r8 * const restrict ret,
       scount[0]++;
 
       /* Advance to the next destination element.  */
-      n = 0;
+      index_type n = 0;
       while (rcount[n] == rextent[n])
         {
           /* When we get to the end of a dimension, reset it and increment
@@ -343,7 +342,7 @@  reshape_r8 (gfc_array_r8 * const restrict ret,
                   /* Switch to the pad array.  */
                   sptr = NULL;
                   sdim = pdim;
-                  for (dim = 0; dim < pdim; dim++)
+                  for (index_type dim = 0; dim < pdim; dim++)
                     {
                       scount[dim] = pcount[dim];
                       sextent[dim] = pextent[dim];
diff --git a/libgfortran/generated/shape_i1.c b/libgfortran/generated/shape_i1.c
index f93adf2..6779f60 100644
--- a/libgfortran/generated/shape_i1.c
+++ b/libgfortran/generated/shape_i1.c
@@ -36,12 +36,10 @@  void
 shape_1 (gfc_array_i1 * const restrict ret, 
 	const array_t * const restrict array)
 {
-  int n;
   index_type stride;
   index_type extent;
-  int rank;
 
-  rank = GFC_DESCRIPTOR_RANK (array);
+  int rank = GFC_DESCRIPTOR_RANK (array);
 
   if (ret->base_addr == NULL)
     {
@@ -55,7 +53,7 @@  shape_1 (gfc_array_i1 * const restrict ret,
   if (GFC_DESCRIPTOR_EXTENT(ret,0) < 1)
     return;
 
-  for (n = 0; n < rank; n++)
+  for (index_type n = 0; n < rank; n++)
     {
       extent = GFC_DESCRIPTOR_EXTENT(array,n);
       ret->base_addr[n * stride] = extent > 0 ? extent : 0 ;
diff --git a/libgfortran/generated/shape_i16.c b/libgfortran/generated/shape_i16.c
index fade4f0..75272ce 100644
--- a/libgfortran/generated/shape_i16.c
+++ b/libgfortran/generated/shape_i16.c
@@ -36,12 +36,10 @@  void
 shape_16 (gfc_array_i16 * const restrict ret, 
 	const array_t * const restrict array)
 {
-  int n;
   index_type stride;
   index_type extent;
-  int rank;
 
-  rank = GFC_DESCRIPTOR_RANK (array);
+  int rank = GFC_DESCRIPTOR_RANK (array);
 
   if (ret->base_addr == NULL)
     {
@@ -55,7 +53,7 @@  shape_16 (gfc_array_i16 * const restrict ret,
   if (GFC_DESCRIPTOR_EXTENT(ret,0) < 1)
     return;
 
-  for (n = 0; n < rank; n++)
+  for (index_type n = 0; n < rank; n++)
     {
       extent = GFC_DESCRIPTOR_EXTENT(array,n);
       ret->base_addr[n * stride] = extent > 0 ? extent : 0 ;
diff --git a/libgfortran/generated/shape_i2.c b/libgfortran/generated/shape_i2.c
index db477eb..7334a14 100644
--- a/libgfortran/generated/shape_i2.c
+++ b/libgfortran/generated/shape_i2.c
@@ -36,12 +36,10 @@  void
 shape_2 (gfc_array_i2 * const restrict ret, 
 	const array_t * const restrict array)
 {
-  int n;
   index_type stride;
   index_type extent;
-  int rank;
 
-  rank = GFC_DESCRIPTOR_RANK (array);
+  int rank = GFC_DESCRIPTOR_RANK (array);
 
   if (ret->base_addr == NULL)
     {
@@ -55,7 +53,7 @@  shape_2 (gfc_array_i2 * const restrict ret,
   if (GFC_DESCRIPTOR_EXTENT(ret,0) < 1)
     return;
 
-  for (n = 0; n < rank; n++)
+  for (index_type n = 0; n < rank; n++)
     {
       extent = GFC_DESCRIPTOR_EXTENT(array,n);
       ret->base_addr[n * stride] = extent > 0 ? extent : 0 ;
diff --git a/libgfortran/generated/shape_i4.c b/libgfortran/generated/shape_i4.c
index bef5508..b42d6b4 100644
--- a/libgfortran/generated/shape_i4.c
+++ b/libgfortran/generated/shape_i4.c
@@ -36,12 +36,10 @@  void
 shape_4 (gfc_array_i4 * const restrict ret, 
 	const array_t * const restrict array)
 {
-  int n;
   index_type stride;
   index_type extent;
-  int rank;
 
-  rank = GFC_DESCRIPTOR_RANK (array);
+  int rank = GFC_DESCRIPTOR_RANK (array);
 
   if (ret->base_addr == NULL)
     {
@@ -55,7 +53,7 @@  shape_4 (gfc_array_i4 * const restrict ret,
   if (GFC_DESCRIPTOR_EXTENT(ret,0) < 1)
     return;
 
-  for (n = 0; n < rank; n++)
+  for (index_type n = 0; n < rank; n++)
     {
       extent = GFC_DESCRIPTOR_EXTENT(array,n);
       ret->base_addr[n * stride] = extent > 0 ? extent : 0 ;
diff --git a/libgfortran/generated/shape_i8.c b/libgfortran/generated/shape_i8.c
index 1866dee..b82f967 100644
--- a/libgfortran/generated/shape_i8.c
+++ b/libgfortran/generated/shape_i8.c
@@ -36,12 +36,10 @@  void
 shape_8 (gfc_array_i8 * const restrict ret, 
 	const array_t * const restrict array)
 {
-  int n;
   index_type stride;
   index_type extent;
-  int rank;
 
-  rank = GFC_DESCRIPTOR_RANK (array);
+  int rank = GFC_DESCRIPTOR_RANK (array);
 
   if (ret->base_addr == NULL)
     {
@@ -55,7 +53,7 @@  shape_8 (gfc_array_i8 * const restrict ret,
   if (GFC_DESCRIPTOR_EXTENT(ret,0) < 1)
     return;
 
-  for (n = 0; n < rank; n++)
+  for (index_type n = 0; n < rank; n++)
     {
       extent = GFC_DESCRIPTOR_EXTENT(array,n);
       ret->base_addr[n * stride] = extent > 0 ? extent : 0 ;
diff --git a/libgfortran/generated/spread_c10.c b/libgfortran/generated/spread_c10.c
index 2c2b71fd..93bd169 100644
--- a/libgfortran/generated/spread_c10.c
+++ b/libgfortran/generated/spread_c10.c
@@ -227,10 +227,8 @@  spread_c10 (gfc_array_c10 *ret, const gfc_array_c10 *source,
 
 void
 spread_scalar_c10 (gfc_array_c10 *ret, const GFC_COMPLEX_10 *source,
-			const index_type along, const index_type pncopies)
+			const index_type along, const index_type ncopies)
 {
-  int n;
-  int ncopies = pncopies;
   GFC_COMPLEX_10 * restrict dest;
   index_type stride;
 
@@ -256,7 +254,7 @@  spread_scalar_c10 (gfc_array_c10 *ret, const GFC_COMPLEX_10 *source,
   dest = ret->base_addr;
   stride = GFC_DESCRIPTOR_STRIDE(ret,0);
 
-  for (n = 0; n < ncopies; n++)
+  for (index_type n = 0; n < ncopies; n++)
     {
       *dest = *source;
       dest += stride;
diff --git a/libgfortran/generated/spread_c16.c b/libgfortran/generated/spread_c16.c
index e0dd156..3643c58 100644
--- a/libgfortran/generated/spread_c16.c
+++ b/libgfortran/generated/spread_c16.c
@@ -227,10 +227,8 @@  spread_c16 (gfc_array_c16 *ret, const gfc_array_c16 *source,
 
 void
 spread_scalar_c16 (gfc_array_c16 *ret, const GFC_COMPLEX_16 *source,
-			const index_type along, const index_type pncopies)
+			const index_type along, const index_type ncopies)
 {
-  int n;
-  int ncopies = pncopies;
   GFC_COMPLEX_16 * restrict dest;
   index_type stride;
 
@@ -256,7 +254,7 @@  spread_scalar_c16 (gfc_array_c16 *ret, const GFC_COMPLEX_16 *source,
   dest = ret->base_addr;
   stride = GFC_DESCRIPTOR_STRIDE(ret,0);
 
-  for (n = 0; n < ncopies; n++)
+  for (index_type n = 0; n < ncopies; n++)
     {
       *dest = *source;
       dest += stride;
diff --git a/libgfortran/generated/spread_c4.c b/libgfortran/generated/spread_c4.c
index b0bbc66..8c16b5c 100644
--- a/libgfortran/generated/spread_c4.c
+++ b/libgfortran/generated/spread_c4.c
@@ -227,10 +227,8 @@  spread_c4 (gfc_array_c4 *ret, const gfc_array_c4 *source,
 
 void
 spread_scalar_c4 (gfc_array_c4 *ret, const GFC_COMPLEX_4 *source,
-			const index_type along, const index_type pncopies)
+			const index_type along, const index_type ncopies)
 {
-  int n;
-  int ncopies = pncopies;
   GFC_COMPLEX_4 * restrict dest;
   index_type stride;
 
@@ -256,7 +254,7 @@  spread_scalar_c4 (gfc_array_c4 *ret, const GFC_COMPLEX_4 *source,
   dest = ret->base_addr;
   stride = GFC_DESCRIPTOR_STRIDE(ret,0);
 
-  for (n = 0; n < ncopies; n++)
+  for (index_type n = 0; n < ncopies; n++)
     {
       *dest = *source;
       dest += stride;
diff --git a/libgfortran/generated/spread_c8.c b/libgfortran/generated/spread_c8.c
index fb10ef8..15bd79c 100644
--- a/libgfortran/generated/spread_c8.c
+++ b/libgfortran/generated/spread_c8.c
@@ -227,10 +227,8 @@  spread_c8 (gfc_array_c8 *ret, const gfc_array_c8 *source,
 
 void
 spread_scalar_c8 (gfc_array_c8 *ret, const GFC_COMPLEX_8 *source,
-			const index_type along, const index_type pncopies)
+			const index_type along, const index_type ncopies)
 {
-  int n;
-  int ncopies = pncopies;
   GFC_COMPLEX_8 * restrict dest;
   index_type stride;
 
@@ -256,7 +254,7 @@  spread_scalar_c8 (gfc_array_c8 *ret, const GFC_COMPLEX_8 *source,
   dest = ret->base_addr;
   stride = GFC_DESCRIPTOR_STRIDE(ret,0);
 
-  for (n = 0; n < ncopies; n++)
+  for (index_type n = 0; n < ncopies; n++)
     {
       *dest = *source;
       dest += stride;
diff --git a/libgfortran/generated/spread_i1.c b/libgfortran/generated/spread_i1.c
index 5cd356e..ee051d6 100644
--- a/libgfortran/generated/spread_i1.c
+++ b/libgfortran/generated/spread_i1.c
@@ -227,10 +227,8 @@  spread_i1 (gfc_array_i1 *ret, const gfc_array_i1 *source,
 
 void
 spread_scalar_i1 (gfc_array_i1 *ret, const GFC_INTEGER_1 *source,
-			const index_type along, const index_type pncopies)
+			const index_type along, const index_type ncopies)
 {
-  int n;
-  int ncopies = pncopies;
   GFC_INTEGER_1 * restrict dest;
   index_type stride;
 
@@ -256,7 +254,7 @@  spread_scalar_i1 (gfc_array_i1 *ret, const GFC_INTEGER_1 *source,
   dest = ret->base_addr;
   stride = GFC_DESCRIPTOR_STRIDE(ret,0);
 
-  for (n = 0; n < ncopies; n++)
+  for (index_type n = 0; n < ncopies; n++)
     {
       *dest = *source;
       dest += stride;
diff --git a/libgfortran/generated/spread_i16.c b/libgfortran/generated/spread_i16.c
index 9ff7a65..54a531d 100644
--- a/libgfortran/generated/spread_i16.c
+++ b/libgfortran/generated/spread_i16.c
@@ -227,10 +227,8 @@  spread_i16 (gfc_array_i16 *ret, const gfc_array_i16 *source,
 
 void
 spread_scalar_i16 (gfc_array_i16 *ret, const GFC_INTEGER_16 *source,
-			const index_type along, const index_type pncopies)
+			const index_type along, const index_type ncopies)
 {
-  int n;
-  int ncopies = pncopies;
   GFC_INTEGER_16 * restrict dest;
   index_type stride;
 
@@ -256,7 +254,7 @@  spread_scalar_i16 (gfc_array_i16 *ret, const GFC_INTEGER_16 *source,
   dest = ret->base_addr;
   stride = GFC_DESCRIPTOR_STRIDE(ret,0);
 
-  for (n = 0; n < ncopies; n++)
+  for (index_type n = 0; n < ncopies; n++)
     {
       *dest = *source;
       dest += stride;
diff --git a/libgfortran/generated/spread_i2.c b/libgfortran/generated/spread_i2.c
index c4e1103..d4d4538 100644
--- a/libgfortran/generated/spread_i2.c
+++ b/libgfortran/generated/spread_i2.c
@@ -227,10 +227,8 @@  spread_i2 (gfc_array_i2 *ret, const gfc_array_i2 *source,
 
 void
 spread_scalar_i2 (gfc_array_i2 *ret, const GFC_INTEGER_2 *source,
-			const index_type along, const index_type pncopies)
+			const index_type along, const index_type ncopies)
 {
-  int n;
-  int ncopies = pncopies;
   GFC_INTEGER_2 * restrict dest;
   index_type stride;
 
@@ -256,7 +254,7 @@  spread_scalar_i2 (gfc_array_i2 *ret, const GFC_INTEGER_2 *source,
   dest = ret->base_addr;
   stride = GFC_DESCRIPTOR_STRIDE(ret,0);
 
-  for (n = 0; n < ncopies; n++)
+  for (index_type n = 0; n < ncopies; n++)
     {
       *dest = *source;
       dest += stride;
diff --git a/libgfortran/generated/spread_i4.c b/libgfortran/generated/spread_i4.c
index 3b69fa7..a4366f1 100644
--- a/libgfortran/generated/spread_i4.c
+++ b/libgfortran/generated/spread_i4.c
@@ -227,10 +227,8 @@  spread_i4 (gfc_array_i4 *ret, const gfc_array_i4 *source,
 
 void
 spread_scalar_i4 (gfc_array_i4 *ret, const GFC_INTEGER_4 *source,
-			const index_type along, const index_type pncopies)
+			const index_type along, const index_type ncopies)
 {
-  int n;
-  int ncopies = pncopies;
   GFC_INTEGER_4 * restrict dest;
   index_type stride;
 
@@ -256,7 +254,7 @@  spread_scalar_i4 (gfc_array_i4 *ret, const GFC_INTEGER_4 *source,
   dest = ret->base_addr;
   stride = GFC_DESCRIPTOR_STRIDE(ret,0);
 
-  for (n = 0; n < ncopies; n++)
+  for (index_type n = 0; n < ncopies; n++)
     {
       *dest = *source;
       dest += stride;
diff --git a/libgfortran/generated/spread_i8.c b/libgfortran/generated/spread_i8.c
index 0cac88d..383fe31 100644
--- a/libgfortran/generated/spread_i8.c
+++ b/libgfortran/generated/spread_i8.c
@@ -227,10 +227,8 @@  spread_i8 (gfc_array_i8 *ret, const gfc_array_i8 *source,
 
 void
 spread_scalar_i8 (gfc_array_i8 *ret, const GFC_INTEGER_8 *source,
-			const index_type along, const index_type pncopies)
+			const index_type along, const index_type ncopies)
 {
-  int n;
-  int ncopies = pncopies;
   GFC_INTEGER_8 * restrict dest;
   index_type stride;
 
@@ -256,7 +254,7 @@  spread_scalar_i8 (gfc_array_i8 *ret, const GFC_INTEGER_8 *source,
   dest = ret->base_addr;
   stride = GFC_DESCRIPTOR_STRIDE(ret,0);
 
-  for (n = 0; n < ncopies; n++)
+  for (index_type n = 0; n < ncopies; n++)
     {
       *dest = *source;
       dest += stride;
diff --git a/libgfortran/generated/spread_r10.c b/libgfortran/generated/spread_r10.c
index 43f41db..167ea22 100644
--- a/libgfortran/generated/spread_r10.c
+++ b/libgfortran/generated/spread_r10.c
@@ -227,10 +227,8 @@  spread_r10 (gfc_array_r10 *ret, const gfc_array_r10 *source,
 
 void
 spread_scalar_r10 (gfc_array_r10 *ret, const GFC_REAL_10 *source,
-			const index_type along, const index_type pncopies)
+			const index_type along, const index_type ncopies)
 {
-  int n;
-  int ncopies = pncopies;
   GFC_REAL_10 * restrict dest;
   index_type stride;
 
@@ -256,7 +254,7 @@  spread_scalar_r10 (gfc_array_r10 *ret, const GFC_REAL_10 *source,
   dest = ret->base_addr;
   stride = GFC_DESCRIPTOR_STRIDE(ret,0);
 
-  for (n = 0; n < ncopies; n++)
+  for (index_type n = 0; n < ncopies; n++)
     {
       *dest = *source;
       dest += stride;
diff --git a/libgfortran/generated/spread_r16.c b/libgfortran/generated/spread_r16.c
index 555247d..d1e1f21 100644
--- a/libgfortran/generated/spread_r16.c
+++ b/libgfortran/generated/spread_r16.c
@@ -227,10 +227,8 @@  spread_r16 (gfc_array_r16 *ret, const gfc_array_r16 *source,
 
 void
 spread_scalar_r16 (gfc_array_r16 *ret, const GFC_REAL_16 *source,
-			const index_type along, const index_type pncopies)
+			const index_type along, const index_type ncopies)
 {
-  int n;
-  int ncopies = pncopies;
   GFC_REAL_16 * restrict dest;
   index_type stride;
 
@@ -256,7 +254,7 @@  spread_scalar_r16 (gfc_array_r16 *ret, const GFC_REAL_16 *source,
   dest = ret->base_addr;
   stride = GFC_DESCRIPTOR_STRIDE(ret,0);
 
-  for (n = 0; n < ncopies; n++)
+  for (index_type n = 0; n < ncopies; n++)
     {
       *dest = *source;
       dest += stride;
diff --git a/libgfortran/generated/spread_r4.c b/libgfortran/generated/spread_r4.c
index c0ae50d..d0b04b0 100644
--- a/libgfortran/generated/spread_r4.c
+++ b/libgfortran/generated/spread_r4.c
@@ -227,10 +227,8 @@  spread_r4 (gfc_array_r4 *ret, const gfc_array_r4 *source,
 
 void
 spread_scalar_r4 (gfc_array_r4 *ret, const GFC_REAL_4 *source,
-			const index_type along, const index_type pncopies)
+			const index_type along, const index_type ncopies)
 {
-  int n;
-  int ncopies = pncopies;
   GFC_REAL_4 * restrict dest;
   index_type stride;
 
@@ -256,7 +254,7 @@  spread_scalar_r4 (gfc_array_r4 *ret, const GFC_REAL_4 *source,
   dest = ret->base_addr;
   stride = GFC_DESCRIPTOR_STRIDE(ret,0);
 
-  for (n = 0; n < ncopies; n++)
+  for (index_type n = 0; n < ncopies; n++)
     {
       *dest = *source;
       dest += stride;
diff --git a/libgfortran/generated/spread_r8.c b/libgfortran/generated/spread_r8.c
index 610ac62..09bf33e 100644
--- a/libgfortran/generated/spread_r8.c
+++ b/libgfortran/generated/spread_r8.c
@@ -227,10 +227,8 @@  spread_r8 (gfc_array_r8 *ret, const gfc_array_r8 *source,
 
 void
 spread_scalar_r8 (gfc_array_r8 *ret, const GFC_REAL_8 *source,
-			const index_type along, const index_type pncopies)
+			const index_type along, const index_type ncopies)
 {
-  int n;
-  int ncopies = pncopies;
   GFC_REAL_8 * restrict dest;
   index_type stride;
 
@@ -256,7 +254,7 @@  spread_scalar_r8 (gfc_array_r8 *ret, const GFC_REAL_8 *source,
   dest = ret->base_addr;
   stride = GFC_DESCRIPTOR_STRIDE(ret,0);
 
-  for (n = 0; n < ncopies; n++)
+  for (index_type n = 0; n < ncopies; n++)
     {
       *dest = *source;
       dest += stride;
diff --git a/libgfortran/intrinsics/random.c b/libgfortran/intrinsics/random.c
index 2edfa82..c8e442c 100644
--- a/libgfortran/intrinsics/random.c
+++ b/libgfortran/intrinsics/random.c
@@ -259,7 +259,7 @@  jump (xorshift1024star_state* rs)
   };
 
   uint64_t t[16] = { 0 };
-  for(unsigned int i = 0; i < sizeof JUMP / sizeof *JUMP; i++)
+  for(size_t i = 0; i < sizeof JUMP / sizeof *JUMP; i++)
     for(int b = 0; b < 64; b++)
       {
 	if (JUMP[i] & 1ULL << b)
@@ -306,7 +306,7 @@  getosrandom (void *buf, size_t buflen)
   /* rand_s is available in MinGW-w64 but not plain MinGW.  */
 #if defined(__MINGW64_VERSION_MAJOR)
   unsigned int* b = buf;
-  for (unsigned i = 0; i < buflen / sizeof (unsigned int); i++)
+  for (size_t i = 0; i < buflen / sizeof (unsigned int); i++)
     rand_s (&b[i]);
   return buflen;
 #else
@@ -462,14 +462,12 @@  arandom_r4 (gfc_array_r4 *x)
   index_type dim;
   GFC_REAL_4 *dest;
   xorshift1024star_state* rs = get_rand_state();
-  int n;
-
 
   dest = x->base_addr;
 
   dim = GFC_DESCRIPTOR_RANK (x);
 
-  for (n = 0; n < dim; n++)
+  for (index_type n = 0; n < dim; n++)
     {
       count[n] = 0;
       stride[n] = GFC_DESCRIPTOR_STRIDE(x,n);
@@ -494,7 +492,7 @@  arandom_r4 (gfc_array_r4 *x)
       dest += stride0;
       count[0]++;
       /* Advance to the next source element.  */
-      n = 0;
+      index_type n = 0;
       while (count[n] == extent[n])
         {
           /* When we get to the end of a dimension, reset it and increment
@@ -531,13 +529,12 @@  arandom_r8 (gfc_array_r8 *x)
   index_type dim;
   GFC_REAL_8 *dest;
   xorshift1024star_state* rs = get_rand_state();
-  int n;
 
   dest = x->base_addr;
 
   dim = GFC_DESCRIPTOR_RANK (x);
 
-  for (n = 0; n < dim; n++)
+  for (index_type n = 0; n < dim; n++)
     {
       count[n] = 0;
       stride[n] = GFC_DESCRIPTOR_STRIDE(x,n);
@@ -561,7 +558,7 @@  arandom_r8 (gfc_array_r8 *x)
       dest += stride0;
       count[0]++;
       /* Advance to the next source element.  */
-      n = 0;
+      index_type n = 0;
       while (count[n] == extent[n])
         {
           /* When we get to the end of a dimension, reset it and increment
@@ -600,13 +597,12 @@  arandom_r10 (gfc_array_r10 *x)
   index_type dim;
   GFC_REAL_10 *dest;
   xorshift1024star_state* rs = get_rand_state();
-  int n;
 
   dest = x->base_addr;
 
   dim = GFC_DESCRIPTOR_RANK (x);
 
-  for (n = 0; n < dim; n++)
+  for (index_type n = 0; n < dim; n++)
     {
       count[n] = 0;
       stride[n] = GFC_DESCRIPTOR_STRIDE(x,n);
@@ -630,7 +626,7 @@  arandom_r10 (gfc_array_r10 *x)
       dest += stride0;
       count[0]++;
       /* Advance to the next source element.  */
-      n = 0;
+      index_type n = 0;
       while (count[n] == extent[n])
         {
           /* When we get to the end of a dimension, reset it and increment
@@ -671,13 +667,12 @@  arandom_r16 (gfc_array_r16 *x)
   index_type dim;
   GFC_REAL_16 *dest;
   xorshift1024star_state* rs = get_rand_state();
-  int n;
 
   dest = x->base_addr;
 
   dim = GFC_DESCRIPTOR_RANK (x);
 
-  for (n = 0; n < dim; n++)
+  for (index_type n = 0; n < dim; n++)
     {
       count[n] = 0;
       stride[n] = GFC_DESCRIPTOR_STRIDE(x,n);
@@ -702,7 +697,7 @@  arandom_r16 (gfc_array_r16 *x)
       dest += stride0;
       count[0]++;
       /* Advance to the next source element.  */
-      n = 0;
+      index_type n = 0;
       while (count[n] == extent[n])
         {
           /* When we get to the end of a dimension, reset it and increment
@@ -751,7 +746,7 @@  static const uint64_t xor_keys[] = {
 static void
 scramble_seed (uint64_t *dest, const uint64_t *src)
 {
-  for (int i = 0; i < (int) SZU64; i++)
+  for (size_t i = 0; i < SZU64; i++)
     dest[i] = src[i] ^ xor_keys[i];
 }
 
diff --git a/libgfortran/m4/cshift1.m4 b/libgfortran/m4/cshift1.m4
index 07e8580..9c7af9a 100644
--- a/libgfortran/m4/cshift1.m4
+++ b/libgfortran/m4/cshift1.m4
@@ -78,12 +78,10 @@  cshift1 (gfc_array_char * const restrict ret,
 
   if (ret->base_addr == NULL)
     {
-      int i;
-
       ret->base_addr = xmallocarray (arraysize, size);
       ret->offset = 0;
       ret->dtype = array->dtype;
-      for (i = 0; i < GFC_DESCRIPTOR_RANK (array); i++)
+      for (index_type i = 0; i < GFC_DESCRIPTOR_RANK (array); i++)
         {
 	  index_type ub, str;
 
diff --git a/libgfortran/m4/eoshift1.m4 b/libgfortran/m4/eoshift1.m4
index 6950460..0be0ab4 100644
--- a/libgfortran/m4/eoshift1.m4
+++ b/libgfortran/m4/eoshift1.m4
@@ -85,11 +85,9 @@  eoshift1 (gfc_array_char * const restrict ret,
   arraysize = size0 ((array_t *) array);
   if (ret->base_addr == NULL)
     {
-      int i;
-
       ret->offset = 0;
       ret->dtype = array->dtype;
-      for (i = 0; i < GFC_DESCRIPTOR_RANK (array); i++)
+      for (index_type i = 0; i < GFC_DESCRIPTOR_RANK (array); i++)
         {
 	  index_type ub, str;
 
diff --git a/libgfortran/m4/eoshift3.m4 b/libgfortran/m4/eoshift3.m4
index 9e7f787..8bdddd2 100644
--- a/libgfortran/m4/eoshift3.m4
+++ b/libgfortran/m4/eoshift3.m4
@@ -86,12 +86,10 @@  eoshift3 (gfc_array_char * const restrict ret,
 
   if (ret->base_addr == NULL)
     {
-      int i;
-
       ret->base_addr = xmallocarray (arraysize, size);
       ret->offset = 0;
       ret->dtype = array->dtype;
-      for (i = 0; i < GFC_DESCRIPTOR_RANK (array); i++)
+      for (index_type i = 0; i < GFC_DESCRIPTOR_RANK (array); i++)
         {
 	  index_type ub, str;
 
diff --git a/libgfortran/m4/in_pack.m4 b/libgfortran/m4/in_pack.m4
index 43370ea..df16ea6 100644
--- a/libgfortran/m4/in_pack.m4
+++ b/libgfortran/m4/in_pack.m4
@@ -46,7 +46,6 @@  internal_pack_'rtype_ccode` ('rtype` * source)
   const 'rtype_name` *src;
   'rtype_name` * restrict dest;
   'rtype_name` *destptr;
-  int n;
   int packed;
 
   /* TODO: Investigate how we can figure out if this is a temporary
@@ -55,7 +54,7 @@  internal_pack_'rtype_ccode` ('rtype` * source)
   dim = GFC_DESCRIPTOR_RANK (source);
   ssize = 1;
   packed = 1;
-  for (n = 0; n < dim; n++)
+  for (index_type n = 0; n < dim; n++)
     {
       count[n] = 0;
       stride[n] = GFC_DESCRIPTOR_STRIDE(source,n);
@@ -91,7 +90,7 @@  internal_pack_'rtype_ccode` ('rtype` * source)
       src += stride0;
       count[0]++;
       /* Advance to the next source element.  */
-      n = 0;
+      index_type n = 0;
       while (count[n] == extent[n])
         {
           /* When we get to the end of a dimension, reset it and increment
diff --git a/libgfortran/m4/in_unpack.m4 b/libgfortran/m4/in_unpack.m4
index f906713..838eeb5 100644
--- a/libgfortran/m4/in_unpack.m4
+++ b/libgfortran/m4/in_unpack.m4
@@ -42,7 +42,6 @@  internal_unpack_'rtype_ccode` ('rtype` * d, const 'rtype_name` * src)
   index_type dim;
   index_type dsize;
   'rtype_name` * restrict dest;
-  int n;
 
   dest = d->base_addr;
   if (src == dest || !src)
@@ -50,7 +49,7 @@  internal_unpack_'rtype_ccode` ('rtype` * d, const 'rtype_name` * src)
 
   dim = GFC_DESCRIPTOR_RANK (d);
   dsize = 1;
-  for (n = 0; n < dim; n++)
+  for (index_type n = 0; n < dim; n++)
     {
       count[n] = 0;
       stride[n] = GFC_DESCRIPTOR_STRIDE(d,n);
@@ -80,7 +79,7 @@  internal_unpack_'rtype_ccode` ('rtype` * d, const 'rtype_name` * src)
       dest += stride0;
       count[0]++;
       /* Advance to the next source element.  */
-      n = 0;
+      index_type n = 0;
       while (count[n] == extent[n])
         {
           /* When we get to the end of a dimension, reset it and increment
diff --git a/libgfortran/m4/reshape.m4 b/libgfortran/m4/reshape.m4
index 346d538..8d6c36d 100644
--- a/libgfortran/m4/reshape.m4
+++ b/libgfortran/m4/reshape.m4
@@ -76,8 +76,6 @@  reshape_'rtype_ccode` ('rtype` * const restrict ret,
   const 'rtype_name` *pptr;
 
   const 'rtype_name` *src;
-  int n;
-  int dim;
   int sempty, pempty, shape_empty;
   index_type shape_data[GFC_MAX_DIMENSIONS];
 
@@ -91,7 +89,7 @@  reshape_'rtype_ccode` ('rtype` * const restrict ret,
 
   shape_empty = 0;
 
-  for (n = 0; n < rdim; n++)
+  for (index_type n = 0; n < rdim; n++)
     {
       shape_data[n] = shape->base_addr[n * GFC_DESCRIPTOR_STRIDE(shape,0)];
       if (shape_data[n] <= 0)
@@ -106,7 +104,7 @@  reshape_'rtype_ccode` ('rtype` * const restrict ret,
       index_type alloc_size;
 
       rs = 1;
-      for (n = 0; n < rdim; n++)
+      for (index_type n = 0; n < rdim; n++)
 	{
 	  rex = shape_data[n];
 
@@ -133,7 +131,7 @@  reshape_'rtype_ccode` ('rtype` * const restrict ret,
       pdim = GFC_DESCRIPTOR_RANK (pad);
       psize = 1;
       pempty = 0;
-      for (n = 0; n < pdim; n++)
+      for (index_type n = 0; n < pdim; n++)
         {
           pcount[n] = 0;
           pstride[n] = GFC_DESCRIPTOR_STRIDE(pad,n);
@@ -164,7 +162,7 @@  reshape_'rtype_ccode` ('rtype` * const restrict ret,
       index_type ret_extent, source_extent;
 
       rs = 1;
-      for (n = 0; n < rdim; n++)
+      for (index_type n = 0; n < rdim; n++)
 	{
 	  rs *= shape_data[n];
 	  ret_extent = GFC_DESCRIPTOR_EXTENT(ret,n);
@@ -177,7 +175,7 @@  reshape_'rtype_ccode` ('rtype` * const restrict ret,
 
       source_extent = 1;
       sdim = GFC_DESCRIPTOR_RANK (source);
-      for (n = 0; n < sdim; n++)
+      for (index_type n = 0; n < sdim; n++)
 	{
 	  index_type se;
 	  se = GFC_DESCRIPTOR_EXTENT(source,n);
@@ -194,10 +192,10 @@  reshape_'rtype_ccode` ('rtype` * const restrict ret,
 	  int seen[GFC_MAX_DIMENSIONS];
 	  index_type v;
 
-	  for (n = 0; n < rdim; n++)
+	  for (index_type n = 0; n < rdim; n++)
 	    seen[n] = 0;
 
-	  for (n = 0; n < rdim; n++)
+	  for (index_type n = 0; n < rdim; n++)
 	    {
 	      v = order->base_addr[n * GFC_DESCRIPTOR_STRIDE(order,0)] - 1;
 
@@ -215,8 +213,9 @@  reshape_'rtype_ccode` ('rtype` * const restrict ret,
     }
 
   rsize = 1;
-  for (n = 0; n < rdim; n++)
+  for (index_type n = 0; n < rdim; n++)
     {
+      index_type dim;
       if (order)
         dim = order->base_addr[n * GFC_DESCRIPTOR_STRIDE(order,0)] - 1;
       else
@@ -247,7 +246,7 @@  reshape_'rtype_ccode` ('rtype` * const restrict ret,
 
   ssize = 1;
   sempty = 0;
-  for (n = 0; n < sdim; n++)
+  for (index_type n = 0; n < sdim; n++)
     {
       scount[n] = 0;
       sstride[n] = GFC_DESCRIPTOR_STRIDE(source,n);
@@ -287,7 +286,7 @@  reshape_'rtype_ccode` ('rtype` * const restrict ret,
       src = pptr;
       sptr = pptr;
       sdim = pdim;
-      for (dim = 0; dim < pdim; dim++)
+      for (index_type dim = 0; dim < pdim; dim++)
 	{
 	  scount[dim] = pcount[dim];
 	  sextent[dim] = pextent[dim];
@@ -307,7 +306,7 @@  reshape_'rtype_ccode` ('rtype` * const restrict ret,
       scount[0]++;
 
       /* Advance to the next destination element.  */
-      n = 0;
+      index_type n = 0;
       while (rcount[n] == rextent[n])
         {
           /* When we get to the end of a dimension, reset it and increment
@@ -347,7 +346,7 @@  reshape_'rtype_ccode` ('rtype` * const restrict ret,
                   /* Switch to the pad array.  */
                   sptr = NULL;
                   sdim = pdim;
-                  for (dim = 0; dim < pdim; dim++)
+                  for (index_type dim = 0; dim < pdim; dim++)
                     {
                       scount[dim] = pcount[dim];
                       sextent[dim] = pextent[dim];
diff --git a/libgfortran/m4/shape.m4 b/libgfortran/m4/shape.m4
index f663b4d..46c31e6 100644
--- a/libgfortran/m4/shape.m4
+++ b/libgfortran/m4/shape.m4
@@ -37,12 +37,10 @@  void
 shape_'rtype_kind` ('rtype` * const restrict ret, 
 	const array_t * const restrict array)
 {
-  int n;
   index_type stride;
   index_type extent;
-  int rank;
 
-  rank = GFC_DESCRIPTOR_RANK (array);
+  int rank = GFC_DESCRIPTOR_RANK (array);
 
   if (ret->base_addr == NULL)
     {
@@ -56,7 +54,7 @@  shape_'rtype_kind` ('rtype` * const restrict ret,
   if (GFC_DESCRIPTOR_EXTENT(ret,0) < 1)
     return;
 
-  for (n = 0; n < rank; n++)
+  for (index_type n = 0; n < rank; n++)
     {
       extent = GFC_DESCRIPTOR_EXTENT(array,n);
       ret->base_addr[n * stride] = extent > 0 ? extent : 0 ;
diff --git a/libgfortran/m4/spread.m4 b/libgfortran/m4/spread.m4
index 7ec2430..42051ab 100644
--- a/libgfortran/m4/spread.m4
+++ b/libgfortran/m4/spread.m4
@@ -228,10 +228,8 @@  spread_'rtype_code` ('rtype` *ret, const 'rtype` *source,
 
 void
 spread_scalar_'rtype_code` ('rtype` *ret, const 'rtype_name` *source,
-			const index_type along, const index_type pncopies)
+			const index_type along, const index_type ncopies)
 {
-  int n;
-  int ncopies = pncopies;
   'rtype_name` * restrict dest;
   index_type stride;
 
@@ -257,7 +255,7 @@  spread_scalar_'rtype_code` ('rtype` *ret, const 'rtype_name` *source,
   dest = ret->base_addr;
   stride = GFC_DESCRIPTOR_STRIDE(ret,0);
 
-  for (n = 0; n < ncopies; n++)
+  for (index_type n = 0; n < ncopies; n++)
     {
       *dest = *source;
       dest += stride;
diff --git a/libgfortran/runtime/bounds.c b/libgfortran/runtime/bounds.c
index 376b9d7..b6e250f 100644
--- a/libgfortran/runtime/bounds.c
+++ b/libgfortran/runtime/bounds.c
@@ -62,7 +62,6 @@  bounds_ifunction_return (array_t * a, const index_type * extent,
 			 const char * a_name, const char * intrinsic)
 {
   int empty;
-  int n;
   int rank;
   index_type a_size;
 
@@ -70,7 +69,7 @@  bounds_ifunction_return (array_t * a, const index_type * extent,
   a_size = size0 (a);
 
   empty = 0;
-  for (n = 0; n < rank; n++)
+  for (index_type n = 0; n < rank; n++)
     {
       if (extent[n] == 0)
 	empty = 1;
@@ -89,7 +88,7 @@  bounds_ifunction_return (array_t * a, const index_type * extent,
 		       " intrinsic: should not be zero-sized",
 		       a_name, intrinsic);
 
-      for (n = 0; n < rank; n++)
+      for (index_type n = 0; n < rank; n++)
 	{
 	  index_type a_extent;
 	  a_extent = GFC_DESCRIPTOR_EXTENT(a, n);
diff --git a/libgfortran/runtime/in_pack_generic.c b/libgfortran/runtime/in_pack_generic.c
index c4b78e9..5498c6f 100644
--- a/libgfortran/runtime/in_pack_generic.c
+++ b/libgfortran/runtime/in_pack_generic.c
@@ -41,7 +41,6 @@  internal_pack (gfc_array_char * source)
   const char *src;
   char *dest;
   void *destptr;
-  int n;
   int packed;
   index_type size;
   index_type type_size;
@@ -156,7 +155,7 @@  internal_pack (gfc_array_char * source)
   dim = GFC_DESCRIPTOR_RANK (source);
   ssize = 1;
   packed = 1;
-  for (n = 0; n < dim; n++)
+  for (index_type n = 0; n < dim; n++)
     {
       count[n] = 0;
       stride[n] = GFC_DESCRIPTOR_STRIDE(source,n);
@@ -192,7 +191,7 @@  internal_pack (gfc_array_char * source)
       src += stride0;
       count[0]++;
       /* Advance to the next source element.  */
-      n = 0;
+      index_type n = 0;
       while (count[n] == extent[n])
         {
           /* When we get to the end of a dimension, reset it and increment
diff --git a/libgfortran/runtime/in_unpack_generic.c b/libgfortran/runtime/in_unpack_generic.c
index 46b6ddd..cbe12b7 100644
--- a/libgfortran/runtime/in_unpack_generic.c
+++ b/libgfortran/runtime/in_unpack_generic.c
@@ -40,8 +40,7 @@  internal_unpack (gfc_array_char * d, const void * s)
   index_type dsize;
   char *dest;
   const char *src;
-  int n;
-  int size;
+  index_type size;
   int type_size;
 
   dest = d->base_addr;
@@ -181,7 +180,7 @@  internal_unpack (gfc_array_char * d, const void * s)
 
   dim = GFC_DESCRIPTOR_RANK (d);
   dsize = 1;
-  for (n = 0; n < dim; n++)
+  for (index_type n = 0; n < dim; n++)
     {
       count[n] = 0;
       stride[n] = GFC_DESCRIPTOR_STRIDE(d,n);
@@ -214,7 +213,7 @@  internal_unpack (gfc_array_char * d, const void * s)
       dest += stride0;
       count[0]++;
       /* Advance to the next source element.  */
-      n = 0;
+      index_type n = 0;
       while (count[n] == extent[n])
         {
           /* When we get to the end of a dimension, reset it and increment