OSDN Git Service

gcc/
[pf3gnuchains/gcc-fork.git] / gcc / fortran / expr.c
index 486da13..ebed1f2 100644 (file)
@@ -1,13 +1,13 @@
 /* Routines for manipulation of expression nodes.
-   Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006 Free Software 
-   Foundation, Inc.
+   Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007
+   Free Software Foundation, Inc.
    Contributed by Andy Vaught
 
 This file is part of GCC.
 
 GCC is free software; you can redistribute it and/or modify it under
 the terms of the GNU General Public License as published by the Free
-Software Foundation; either version 2, or (at your option) any later
+Software Foundation; either version 3, or (at your option) any later
 version.
 
 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
@@ -16,9 +16,8 @@ FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 for more details.
 
 You should have received a copy of the GNU General Public License
-along with GCC; see the file COPYING.  If not, write to the Free
-Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
-02110-1301, USA.  */
+along with GCC; see the file COPYING3.  If not see
+<http://www.gnu.org/licenses/>.  */
 
 #include "config.h"
 #include "system.h"
@@ -34,12 +33,11 @@ gfc_get_expr (void)
   gfc_expr *e;
 
   e = gfc_getmem (sizeof (gfc_expr));
-
   gfc_clear_ts (&e->ts);
   e->shape = NULL;
   e->ref = NULL;
   e->symtree = NULL;
-
+  e->con_by_offset = NULL;
   return e;
 }
 
@@ -47,7 +45,7 @@ gfc_get_expr (void)
 /* Free an argument list and everything below it.  */
 
 void
-gfc_free_actual_arglist (gfc_actual_arglist * a1)
+gfc_free_actual_arglist (gfc_actual_arglist *a1)
 {
   gfc_actual_arglist *a2;
 
@@ -64,7 +62,7 @@ gfc_free_actual_arglist (gfc_actual_arglist * a1)
 /* Copy an arglist structure and all of the arguments.  */
 
 gfc_actual_arglist *
-gfc_copy_actual_arglist (gfc_actual_arglist * p)
+gfc_copy_actual_arglist (gfc_actual_arglist *p)
 {
   gfc_actual_arglist *head, *tail, *new;
 
@@ -93,7 +91,7 @@ gfc_copy_actual_arglist (gfc_actual_arglist * p)
 /* Free a list of reference structures.  */
 
 void
-gfc_free_ref_list (gfc_ref * p)
+gfc_free_ref_list (gfc_ref *p)
 {
   gfc_ref *q;
   int i;
@@ -134,19 +132,14 @@ gfc_free_ref_list (gfc_ref * p)
    something else or the expression node belongs to another structure.  */
 
 static void
-free_expr0 (gfc_expr * e)
+free_expr0 (gfc_expr *e)
 {
   int n;
 
   switch (e->expr_type)
     {
     case EXPR_CONSTANT:
-      if (e->from_H)
-       {
-         gfc_free (e->value.character.string);
-         break;
-       }
-
+      /* Free any parts of the value that need freeing.  */
       switch (e->ts.type)
        {
        case BT_INTEGER:
@@ -158,7 +151,6 @@ free_expr0 (gfc_expr * e)
          break;
 
        case BT_CHARACTER:
-       case BT_HOLLERITH:
          gfc_free (e->value.character.string);
          break;
 
@@ -171,6 +163,11 @@ free_expr0 (gfc_expr * e)
          break;
        }
 
+      /* Free the representation, except in character constants where it
+        is the same as value.character.string and thus already freed.  */
+      if (e->representation.string && e->ts.type != BT_CHARACTER)
+       gfc_free (e->representation.string);
+
       break;
 
     case EXPR_OP:
@@ -221,12 +218,12 @@ free_expr0 (gfc_expr * e)
 /* Free an expression node and everything beneath it.  */
 
 void
-gfc_free_expr (gfc_expr * e)
+gfc_free_expr (gfc_expr *e)
 {
-
   if (e == NULL)
     return;
-
+  if (e->con_by_offset)
+    splay_tree_delete (e->con_by_offset); 
   free_expr0 (e);
   gfc_free (e);
 }
@@ -235,12 +232,10 @@ gfc_free_expr (gfc_expr * e)
 /* Graft the *src expression onto the *dest subexpression.  */
 
 void
-gfc_replace_expr (gfc_expr * dest, gfc_expr * src)
+gfc_replace_expr (gfc_expr *dest, gfc_expr *src)
 {
-
   free_expr0 (dest);
   *dest = *src;
-
   gfc_free (src);
 }
 
@@ -251,9 +246,8 @@ gfc_replace_expr (gfc_expr * dest, gfc_expr * src)
    failure is OK for some callers.  */
 
 const char *
-gfc_extract_int (gfc_expr * expr, int *result)
+gfc_extract_int (gfc_expr *expr, int *result)
 {
-
   if (expr->expr_type != EXPR_CONSTANT)
     return _("Constant expression required at %C");
 
@@ -275,7 +269,7 @@ gfc_extract_int (gfc_expr * expr, int *result)
 /* Recursively copy a list of reference structures.  */
 
 static gfc_ref *
-copy_ref (gfc_ref * src)
+copy_ref (gfc_ref *src)
 {
   gfc_array_ref *ar;
   gfc_ref *dest;
@@ -311,13 +305,12 @@ copy_ref (gfc_ref * src)
 }
 
 
-/* Detect whether an expression has any vector index array
-   references.  */
+/* Detect whether an expression has any vector index array references.  */
 
 int
 gfc_has_vector_index (gfc_expr *e)
 {
-  gfc_ref * ref;
+  gfc_ref *ref;
   int i;
   for (ref = e->ref; ref; ref = ref->next)
     if (ref->type == REF_ARRAY)
@@ -331,7 +324,7 @@ gfc_has_vector_index (gfc_expr *e)
 /* Copy a shape array.  */
 
 mpz_t *
-gfc_copy_shape (mpz_t * shape, int rank)
+gfc_copy_shape (mpz_t *shape, int rank)
 {
   mpz_t *new_shape;
   int n;
@@ -358,11 +351,10 @@ gfc_copy_shape (mpz_t * shape, int rank)
       { s1 ... sN-1  sN+1    ...  sR-1}
 
    If anything goes wrong -- N is not a constant, its value is out
-   of range -- or anything else, just returns NULL.
-*/
+   of range -- or anything else, just returns NULL.  */
 
 mpz_t *
-gfc_copy_shape_excluding (mpz_t * shape, int rank, gfc_expr * dim)
+gfc_copy_shape_excluding (mpz_t *shape, int rank, gfc_expr *dim)
 {
   mpz_t *new_shape, *s;
   int i, n;
@@ -375,16 +367,16 @@ gfc_copy_shape_excluding (mpz_t * shape, int rank, gfc_expr * dim)
     return NULL;
 
   n = mpz_get_si (dim->value.integer);
-  n--; /* Convert to zero based index */
+  n--; /* Convert to zero based index */
   if (n < 0 || n >= rank)
     return NULL;
 
-  s = new_shape = gfc_get_shape (rank-1);
+  s = new_shape = gfc_get_shape (rank - 1);
 
   for (i = 0; i < rank; i++)
     {
       if (i == n)
-        continue;
+       continue;
       mpz_init_set (*s, shape[i]);
       s++;
     }
@@ -392,11 +384,12 @@ gfc_copy_shape_excluding (mpz_t * shape, int rank, gfc_expr * dim)
   return new_shape;
 }
 
+
 /* Given an expression pointer, return a copy of the expression.  This
    subroutine is recursive.  */
 
 gfc_expr *
-gfc_copy_expr (gfc_expr * p)
+gfc_copy_expr (gfc_expr *p)
 {
   gfc_expr *q;
   char *s;
@@ -417,15 +410,16 @@ gfc_copy_expr (gfc_expr * p)
       break;
 
     case EXPR_CONSTANT:
-      if (p->from_H)
+      /* Copy target representation, if it exists.  */
+      if (p->representation.string)
        {
-         s = gfc_getmem (p->value.character.length + 1);
-         q->value.character.string = s;
+         s = gfc_getmem (p->representation.length + 1);
+         q->representation.string = s;
 
-         memcpy (s, p->value.character.string,
-                 p->value.character.length + 1);
-         break;
+         memcpy (s, p->representation.string, p->representation.length + 1);
        }
+
+      /* Copy the values of any pointer components of p->value.  */
       switch (q->ts.type)
        {
        case BT_INTEGER:
@@ -433,36 +427,53 @@ gfc_copy_expr (gfc_expr * p)
          break;
 
        case BT_REAL:
-          gfc_set_model_kind (q->ts.kind);
-          mpfr_init (q->value.real);
+         gfc_set_model_kind (q->ts.kind);
+         mpfr_init (q->value.real);
          mpfr_set (q->value.real, p->value.real, GFC_RND_MODE);
          break;
 
        case BT_COMPLEX:
-          gfc_set_model_kind (q->ts.kind);
-          mpfr_init (q->value.complex.r);
-          mpfr_init (q->value.complex.i);
+         gfc_set_model_kind (q->ts.kind);
+         mpfr_init (q->value.complex.r);
+         mpfr_init (q->value.complex.i);
          mpfr_set (q->value.complex.r, p->value.complex.r, GFC_RND_MODE);
          mpfr_set (q->value.complex.i, p->value.complex.i, GFC_RND_MODE);
          break;
 
        case BT_CHARACTER:
-       case BT_HOLLERITH:
-         s = gfc_getmem (p->value.character.length + 1);
-         q->value.character.string = s;
+         if (p->representation.string)
+           q->value.character.string = q->representation.string;
+         else
+           {
+             s = gfc_getmem (p->value.character.length + 1);
+             q->value.character.string = s;
 
-         memcpy (s, p->value.character.string,
-                 p->value.character.length + 1);
+             /* This is the case for the C_NULL_CHAR named constant.  */
+             if (p->value.character.length == 0
+                 && (p->ts.is_c_interop || p->ts.is_iso_c))
+               {
+                 *s = '\0';
+                 /* Need to set the length to 1 to make sure the NUL
+                    terminator is copied.  */
+                 q->value.character.length = 1;
+               }
+             else
+               memcpy (s, p->value.character.string,
+                       p->value.character.length + 1);
+           }
          break;
 
+       case BT_HOLLERITH:
        case BT_LOGICAL:
        case BT_DERIVED:
-         break;                /* Already done */
+         break;                /* Already done */
 
        case BT_PROCEDURE:
+        case BT_VOID:
+           /* Should never be reached.  */
        case BT_UNKNOWN:
          gfc_internal_error ("gfc_copy_expr(): Bad expr node");
-         /* Not reached */
+         /* Not reached */
        }
 
       break;
@@ -471,12 +482,13 @@ gfc_copy_expr (gfc_expr * p)
       switch (q->value.op.operator)
        {
        case INTRINSIC_NOT:
+       case INTRINSIC_PARENTHESES:
        case INTRINSIC_UPLUS:
        case INTRINSIC_UMINUS:
          q->value.op.op1 = gfc_copy_expr (p->value.op.op1);
          break;
 
-       default:                /* Binary operators */
+       default:                /* Binary operators */
          q->value.op.op1 = gfc_copy_expr (p->value.op.op1);
          q->value.op.op2 = gfc_copy_expr (p->value.op.op2);
          break;
@@ -511,9 +523,8 @@ gfc_copy_expr (gfc_expr * p)
    kind numbers mean more precision for numeric types.  */
 
 int
-gfc_kind_max (gfc_expr * e1, gfc_expr * e2)
+gfc_kind_max (gfc_expr *e1, gfc_expr *e2)
 {
-
   return (e1->ts.kind > e2->ts.kind) ? e1->ts.kind : e2->ts.kind;
 }
 
@@ -523,7 +534,6 @@ gfc_kind_max (gfc_expr * e1, gfc_expr * e2)
 static int
 numeric_type (bt type)
 {
-
   return type == BT_COMPLEX || type == BT_REAL || type == BT_INTEGER;
 }
 
@@ -531,9 +541,8 @@ numeric_type (bt type)
 /* Returns nonzero if the typespec is a numeric type, zero otherwise.  */
 
 int
-gfc_numeric_ts (gfc_typespec * ts)
+gfc_numeric_ts (gfc_typespec *ts)
 {
-
   return numeric_type (ts->type);
 }
 
@@ -561,7 +570,7 @@ gfc_int_expr (int i)
 /* Returns an expression node that is a logical constant.  */
 
 gfc_expr *
-gfc_logical_expr (int i, locus * where)
+gfc_logical_expr (int i, locus *where)
 {
   gfc_expr *p;
 
@@ -585,7 +594,7 @@ gfc_logical_expr (int i, locus * where)
    argument list with a NULL pointer terminating the list.  */
 
 gfc_expr *
-gfc_build_conversion (gfc_expr * e)
+gfc_build_conversion (gfc_expr *e)
 {
   gfc_expr *p;
 
@@ -611,7 +620,7 @@ gfc_build_conversion (gfc_expr * e)
    1.0**2 stays as it is.  */
 
 void
-gfc_type_convert_binary (gfc_expr * e)
+gfc_type_convert_binary (gfc_expr *e)
 {
   gfc_expr *op1, *op2;
 
@@ -627,10 +636,9 @@ gfc_type_convert_binary (gfc_expr * e)
   /* Kind conversions of same type.  */
   if (op1->ts.type == op2->ts.type)
     {
-
       if (op1->ts.kind == op2->ts.kind)
        {
-          /* No type conversions.  */
+         /* No type conversions.  */
          e->ts = op1->ts;
          goto done;
        }
@@ -680,11 +688,36 @@ done:
 }
 
 
+static match
+check_specification_function (gfc_expr *e)
+{
+  gfc_symbol *sym;
+
+  if (!e->symtree)
+    return MATCH_NO;
+
+  sym = e->symtree->n.sym;
+
+  /* F95, 7.1.6.2; F2003, 7.1.7  */
+  if (sym
+      && sym->attr.function
+      && sym->attr.pure
+      && !sym->attr.intrinsic
+      && !sym->attr.recursive
+      && sym->attr.proc != PROC_INTERNAL
+      && sym->attr.proc != PROC_ST_FUNCTION
+      && sym->attr.proc != PROC_UNKNOWN
+      && sym->formal == NULL)
+    return MATCH_YES;
+
+  return MATCH_NO;
+}
+
 /* Function to determine if an expression is constant or not.  This
    function expects that the expression has already been simplified.  */
 
 int
-gfc_is_constant_expr (gfc_expr * e)
+gfc_is_constant_expr (gfc_expr *e)
 {
   gfc_constructor *c;
   gfc_actual_arglist *arg;
@@ -699,7 +732,6 @@ gfc_is_constant_expr (gfc_expr * e)
       rv = (gfc_is_constant_expr (e->value.op.op1)
            && (e->value.op.op2 == NULL
                || gfc_is_constant_expr (e->value.op.op2)));
-
       break;
 
     case EXPR_VARIABLE:
@@ -707,6 +739,13 @@ gfc_is_constant_expr (gfc_expr * e)
       break;
 
     case EXPR_FUNCTION:
+      /* Specification functions are constant.  */
+      if (check_specification_function (e) == MATCH_YES)
+       {
+         rv = 1;
+         break;
+       }
+
       /* Call to intrinsic with at least one argument.  */
       rv = 0;
       if (e->value.function.isym && e->value.function.actual)
@@ -727,8 +766,8 @@ gfc_is_constant_expr (gfc_expr * e)
       break;
 
     case EXPR_SUBSTRING:
-      rv = (gfc_is_constant_expr (e->ref->u.ss.start)
-           && gfc_is_constant_expr (e->ref->u.ss.end));
+      rv = e->ref == NULL || (gfc_is_constant_expr (e->ref->u.ss.start)
+                             && gfc_is_constant_expr (e->ref->u.ss.end));
       break;
 
     case EXPR_STRUCTURE:
@@ -756,8 +795,9 @@ gfc_is_constant_expr (gfc_expr * e)
 /* Try to collapse intrinsic expressions.  */
 
 static try
-simplify_intrinsic_op (gfc_expr * p, int type)
+simplify_intrinsic_op (gfc_expr *p, int type)
 {
+  gfc_intrinsic_op op;
   gfc_expr *op1, *op2, *result;
 
   if (p->value.op.operator == INTRINSIC_USER)
@@ -765,6 +805,7 @@ simplify_intrinsic_op (gfc_expr * p, int type)
 
   op1 = p->value.op.op1;
   op2 = p->value.op.op2;
+  op  = p->value.op.operator;
 
   if (gfc_simplify_expr (op1, type) == FAILURE)
     return FAILURE;
@@ -775,14 +816,17 @@ simplify_intrinsic_op (gfc_expr * p, int type)
       || (op2 != NULL && !gfc_is_constant_expr (op2)))
     return SUCCESS;
 
-  /* Rip p apart */
+  /* Rip p apart */
   p->value.op.op1 = NULL;
   p->value.op.op2 = NULL;
 
-  switch (p->value.op.operator)
+  switch (op)
     {
-    case INTRINSIC_UPLUS:
     case INTRINSIC_PARENTHESES:
+      result = gfc_parentheses (op1);
+      break;
+
+    case INTRINSIC_UPLUS:
       result = gfc_uplus (op1);
       break;
 
@@ -815,27 +859,33 @@ simplify_intrinsic_op (gfc_expr * p, int type)
       break;
 
     case INTRINSIC_EQ:
-      result = gfc_eq (op1, op2);
+    case INTRINSIC_EQ_OS:
+      result = gfc_eq (op1, op2, op);
       break;
 
     case INTRINSIC_NE:
-      result = gfc_ne (op1, op2);
+    case INTRINSIC_NE_OS:
+      result = gfc_ne (op1, op2, op);
       break;
 
     case INTRINSIC_GT:
-      result = gfc_gt (op1, op2);
+    case INTRINSIC_GT_OS:
+      result = gfc_gt (op1, op2, op);
       break;
 
     case INTRINSIC_GE:
-      result = gfc_ge (op1, op2);
+    case INTRINSIC_GE_OS:
+      result = gfc_ge (op1, op2, op);
       break;
 
     case INTRINSIC_LT:
-      result = gfc_lt (op1, op2);
+    case INTRINSIC_LT_OS:
+      result = gfc_lt (op1, op2, op);
       break;
 
     case INTRINSIC_LE:
-      result = gfc_le (op1, op2);
+    case INTRINSIC_LE_OS:
+      result = gfc_le (op1, op2, op);
       break;
 
     case INTRINSIC_NOT:
@@ -881,9 +931,8 @@ simplify_intrinsic_op (gfc_expr * p, int type)
    with gfc_simplify_expr().  */
 
 static try
-simplify_constructor (gfc_constructor * c, int type)
+simplify_constructor (gfc_constructor *c, int type)
 {
-
   for (; c; c = c->next)
     {
       if (c->iterator
@@ -903,13 +952,15 @@ simplify_constructor (gfc_constructor * c, int type)
 /* Pull a single array element out of an array constructor.  */
 
 static try
-find_array_element (gfc_constructor * cons, gfc_array_ref * ar,
-                   gfc_constructor ** rval)
+find_array_element (gfc_constructor *cons, gfc_array_ref *ar,
+                   gfc_constructor **rval)
 {
   unsigned long nelemen;
   int i;
   mpz_t delta;
   mpz_t offset;
+  mpz_t span;
+  mpz_t tmp;
   gfc_expr *e;
   try t;
 
@@ -918,6 +969,8 @@ find_array_element (gfc_constructor * cons, gfc_array_ref * ar,
 
   mpz_init_set_ui (offset, 0);
   mpz_init (delta);
+  mpz_init (tmp);
+  mpz_init_set_ui (span, 1);
   for (i = 0; i < ar->dimen; i++)
     {
       e = gfc_copy_expr (ar->start[i]);
@@ -929,10 +982,9 @@ find_array_element (gfc_constructor * cons, gfc_array_ref * ar,
 
       /* Check the bounds.  */
       if (ar->as->upper[i]
-           && (mpz_cmp (e->value.integer,
-                       ar->as->upper[i]->value.integer) > 0
-           || mpz_cmp (e->value.integer,
-                       ar->as->lower[i]->value.integer) < 0))
+         && (mpz_cmp (e->value.integer, ar->as->upper[i]->value.integer) > 0
+             || mpz_cmp (e->value.integer,
+                         ar->as->lower[i]->value.integer) < 0))
        {
          gfc_error ("index in dimension %d is out of bounds "
                     "at %L", i + 1, &ar->c_where[i]);
@@ -941,9 +993,14 @@ find_array_element (gfc_constructor * cons, gfc_array_ref * ar,
          goto depart;
        }
 
-      mpz_sub (delta, e->value.integer,
-              ar->as->lower[i]->value.integer);
+      mpz_sub (delta, e->value.integer, ar->as->lower[i]->value.integer);
+      mpz_mul (delta, delta, span);
       mpz_add (offset, offset, delta);
+
+      mpz_set_ui (tmp, 1);
+      mpz_add (tmp, tmp, ar->as->upper[i]->value.integer);
+      mpz_sub (tmp, tmp, ar->as->lower[i]->value.integer);
+      mpz_mul (span, span, tmp);
     }
 
   if (cons)
@@ -962,6 +1019,8 @@ find_array_element (gfc_constructor * cons, gfc_array_ref * ar,
 depart:
   mpz_clear (delta);
   mpz_clear (offset);
+  mpz_clear (span);
+  mpz_clear (tmp);
   if (e)
     gfc_free_expr (e);
   *rval = cons;
@@ -972,7 +1031,7 @@ depart:
 /* Find a component of a structure constructor.  */
 
 static gfc_constructor *
-find_component_ref (gfc_constructor * cons, gfc_ref * ref)
+find_component_ref (gfc_constructor *cons, gfc_ref *ref)
 {
   gfc_component *comp;
   gfc_component *pick;
@@ -993,7 +1052,7 @@ find_component_ref (gfc_constructor * cons, gfc_ref * ref)
    the subobject reference in the process.  */
 
 static void
-remove_subobject_ref (gfc_expr * p, gfc_constructor * cons)
+remove_subobject_ref (gfc_expr *p, gfc_constructor *cons)
 {
   gfc_expr *e;
 
@@ -1013,7 +1072,9 @@ find_array_section (gfc_expr *expr, gfc_ref *ref)
   int idx;
   int rank;
   int d;
+  int shape_i;
   long unsigned one = 1;
+  bool incr_ctr;
   mpz_t start[GFC_MAX_DIMENSIONS];
   mpz_t end[GFC_MAX_DIMENSIONS];
   mpz_t stride[GFC_MAX_DIMENSIONS];
@@ -1023,7 +1084,6 @@ find_array_section (gfc_expr *expr, gfc_ref *ref)
   mpz_t tmp_mpz;
   mpz_t nelts;
   mpz_t ptr;
-  mpz_t stop;
   mpz_t index;
   gfc_constructor *cons;
   gfc_constructor *base;
@@ -1032,6 +1092,7 @@ find_array_section (gfc_expr *expr, gfc_ref *ref)
   gfc_expr *step;
   gfc_expr *upper;
   gfc_expr *lower;
+  gfc_constructor *vecsub[GFC_MAX_DIMENSIONS], *c;
   try t;
 
   t = SUCCESS;
@@ -1057,9 +1118,11 @@ find_array_section (gfc_expr *expr, gfc_ref *ref)
       mpz_init (end[d]);
       mpz_init (ctr[d]);
       mpz_init (stride[d]);
+      vecsub[d] = NULL;
     }
 
   /* Build the counters to clock through the array reference.  */
+  shape_i = 0;
   for (d = 0; d < rank; d++)
     {
       /* Make this stretch of code easier on the eye!  */
@@ -1069,63 +1132,100 @@ find_array_section (gfc_expr *expr, gfc_ref *ref)
       lower = ref->u.ar.as->lower[d];
       upper = ref->u.ar.as->upper[d];
 
-      if ((begin && begin->expr_type != EXPR_CONSTANT)
-           || (finish && finish->expr_type != EXPR_CONSTANT)
-           || (step && step->expr_type != EXPR_CONSTANT))
+      if (ref->u.ar.dimen_type[d] == DIMEN_VECTOR)  /* Vector subscript.  */
        {
-         t = FAILURE;
-         goto cleanup;
-       }
+         gcc_assert (begin);
 
-      /* Obtain the stride.  */
-      if (step)
-       mpz_set (stride[d], step->value.integer);
-      else
-       mpz_set_ui (stride[d], one);
+         if (begin->expr_type != EXPR_ARRAY)
+           {
+             t = FAILURE;
+             goto cleanup;
+           }
 
-      if (mpz_cmp_ui (stride[d], 0) == 0)
-       mpz_set_ui (stride[d], one);
+         gcc_assert (begin->rank == 1);
+         gcc_assert (begin->shape);
 
-      /* Obtain the start value for the index.  */
-      if (begin)
-         mpz_set (start[d], begin->value.integer);
+         vecsub[d] = begin->value.constructor;
+         mpz_set (ctr[d], vecsub[d]->expr->value.integer);
+         mpz_mul (nelts, nelts, begin->shape[0]);
+         mpz_set (expr->shape[shape_i++], begin->shape[0]);
+
+         /* Check bounds.  */
+         for (c = vecsub[d]; c; c = c->next)
+           {
+             if (mpz_cmp (c->expr->value.integer, upper->value.integer) > 0
+                 || mpz_cmp (c->expr->value.integer,
+                             lower->value.integer) < 0)
+               {
+                 gfc_error ("index in dimension %d is out of bounds "
+                            "at %L", d + 1, &ref->u.ar.c_where[d]);
+                 t = FAILURE;
+                 goto cleanup;
+               }
+           }
+       }
       else
-       mpz_set (start[d], lower->value.integer);
+       {
+         if ((begin && begin->expr_type != EXPR_CONSTANT)
+             || (finish && finish->expr_type != EXPR_CONSTANT)
+             || (step && step->expr_type != EXPR_CONSTANT))
+           {
+             t = FAILURE;
+             goto cleanup;
+           }
 
-      mpz_set (ctr[d], start[d]);
+         /* Obtain the stride.  */
+         if (step)
+           mpz_set (stride[d], step->value.integer);
+         else
+           mpz_set_ui (stride[d], one);
 
-      /* Obtain the end value for the index.  */
-      if (finish)
-        mpz_set (end[d], finish->value.integer);
-      else
-       mpz_set (end[d], upper->value.integer);
+         if (mpz_cmp_ui (stride[d], 0) == 0)
+           mpz_set_ui (stride[d], one);
 
-      /* Separate 'if' because elements sometimes arrive with
-        non-null end.  */
-      if (ref->u.ar.dimen_type[d] == DIMEN_ELEMENT)
-       mpz_set (end [d], begin->value.integer);
+         /* Obtain the start value for the index.  */
+         if (begin)
+           mpz_set (start[d], begin->value.integer);
+         else
+           mpz_set (start[d], lower->value.integer);
 
-      /* Check the bounds.  */
-      if (mpz_cmp (ctr[d], upper->value.integer) > 0
-           || mpz_cmp (end[d], upper->value.integer) > 0
-           || mpz_cmp (ctr[d], lower->value.integer) < 0
-           || mpz_cmp (end[d], lower->value.integer) < 0)
-       {
-         gfc_error ("index in dimension %d is out of bounds "
-                    "at %L", d + 1, &ref->u.ar.c_where[d]);
-         t = FAILURE;
-         goto cleanup;
-       }
+         mpz_set (ctr[d], start[d]);
 
-      /* Calculate the number of elements and the shape.  */
-      mpz_abs (tmp_mpz, stride[d]);
-      mpz_div (tmp_mpz, stride[d], tmp_mpz);
-      mpz_add (tmp_mpz, end[d], tmp_mpz);
-      mpz_sub (tmp_mpz, tmp_mpz, ctr[d]);
-      mpz_div (tmp_mpz, tmp_mpz, stride[d]);
-      mpz_mul (nelts, nelts, tmp_mpz);
+         /* Obtain the end value for the index.  */
+         if (finish)
+           mpz_set (end[d], finish->value.integer);
+         else
+           mpz_set (end[d], upper->value.integer);
+
+         /* Separate 'if' because elements sometimes arrive with
+            non-null end.  */
+         if (ref->u.ar.dimen_type[d] == DIMEN_ELEMENT)
+           mpz_set (end [d], begin->value.integer);
+
+         /* Check the bounds.  */
+         if (mpz_cmp (ctr[d], upper->value.integer) > 0
+             || mpz_cmp (end[d], upper->value.integer) > 0
+             || mpz_cmp (ctr[d], lower->value.integer) < 0
+             || mpz_cmp (end[d], lower->value.integer) < 0)
+           {
+             gfc_error ("index in dimension %d is out of bounds "
+                        "at %L", d + 1, &ref->u.ar.c_where[d]);
+             t = FAILURE;
+             goto cleanup;
+           }
 
-      mpz_set (expr->shape[d], tmp_mpz);
+         /* Calculate the number of elements and the shape.  */
+         mpz_set (tmp_mpz, stride[d]);
+         mpz_add (tmp_mpz, end[d], tmp_mpz);
+         mpz_sub (tmp_mpz, tmp_mpz, ctr[d]);
+         mpz_div (tmp_mpz, tmp_mpz, stride[d]);
+         mpz_mul (nelts, nelts, tmp_mpz);
+
+         /* An element reference reduces the rank of the expression; don't
+            add anything to the shape array.  */
+         if (ref->u.ar.dimen_type[d] != DIMEN_ELEMENT) 
+           mpz_set (expr->shape[shape_i++], tmp_mpz);
+       }
 
       /* Calculate the 'stride' (=delta) for conversion of the
         counter values into the index along the constructor.  */
@@ -1137,37 +1237,52 @@ find_array_section (gfc_expr *expr, gfc_ref *ref)
 
   mpz_init (index);
   mpz_init (ptr);
-  mpz_init (stop);
   cons = base;
 
   /* Now clock through the array reference, calculating the index in
      the source constructor and transferring the elements to the new
      constructor.  */  
-  for (idx = 0; idx < (int)mpz_get_si (nelts); idx++)
+  for (idx = 0; idx < (int) mpz_get_si (nelts); idx++)
     {
       if (ref->u.ar.offset)
        mpz_set (ptr, ref->u.ar.offset->value.integer);
       else
        mpz_init_set_ui (ptr, 0);
 
-      mpz_set_ui (stop, one);
+      incr_ctr = true;
       for (d = 0; d < rank; d++)
        {
          mpz_set (tmp_mpz, ctr[d]);
-         mpz_sub_ui (tmp_mpz, tmp_mpz, one);
+         mpz_sub (tmp_mpz, tmp_mpz, ref->u.ar.as->lower[d]->value.integer);
          mpz_mul (tmp_mpz, tmp_mpz, delta[d]);
          mpz_add (ptr, ptr, tmp_mpz);
 
-         mpz_mul (tmp_mpz, stride[d], stop);
-         mpz_add (ctr[d], ctr[d], tmp_mpz); 
+         if (!incr_ctr) continue;
 
-         mpz_set (tmp_mpz, end[d]);
-         if (mpz_cmp_ui (stride[d], 0) > 0 ?
-               mpz_cmp (ctr[d], tmp_mpz) > 0 :
-               mpz_cmp (ctr[d], tmp_mpz) < 0)
-           mpz_set (ctr[d], start[d]);
+         if (ref->u.ar.dimen_type[d] == DIMEN_VECTOR) /* Vector subscript.  */
+           {
+             gcc_assert(vecsub[d]);
+
+             if (!vecsub[d]->next)
+               vecsub[d] = ref->u.ar.start[d]->value.constructor;
+             else
+               {
+                 vecsub[d] = vecsub[d]->next;
+                 incr_ctr = false;
+               }
+             mpz_set (ctr[d], vecsub[d]->expr->value.integer);
+           }
          else
-           mpz_set_ui (stop, 0);
+           {
+             mpz_add (ctr[d], ctr[d], stride[d]); 
+
+             if (mpz_cmp_ui (stride[d], 0) > 0
+                 ? mpz_cmp (ctr[d], end[d]) > 0
+                 : mpz_cmp (ctr[d], end[d]) < 0)
+               mpz_set (ctr[d], start[d]);
+             else
+               incr_ctr = false;
+           }
        }
 
       /* There must be a better way of dealing with negative strides
@@ -1189,7 +1304,6 @@ find_array_section (gfc_expr *expr, gfc_ref *ref)
 
   mpz_clear (ptr);
   mpz_clear (index);
-  mpz_clear (stop);
 
 cleanup:
 
@@ -1215,20 +1329,24 @@ find_substring_ref (gfc_expr *p, gfc_expr **newp)
 {
   int end;
   int start;
+  int length;
   char *chr;
 
   if (p->ref->u.ss.start->expr_type != EXPR_CONSTANT
-       || p->ref->u.ss.end->expr_type != EXPR_CONSTANT)
+      || p->ref->u.ss.end->expr_type != EXPR_CONSTANT)
     return FAILURE;
 
   *newp = gfc_copy_expr (p);
-  chr = p->value.character.string;
-  end = (int)mpz_get_ui (p->ref->u.ss.end->value.integer);
-  start = (int)mpz_get_ui (p->ref->u.ss.start->value.integer);
+  gfc_free ((*newp)->value.character.string);
+
+  end = (int) mpz_get_ui (p->ref->u.ss.end->value.integer);
+  start = (int) mpz_get_ui (p->ref->u.ss.start->value.integer);
+  length = end - start + 1;
 
-  (*newp)->value.character.length = end - start + 1;
-  strncpy ((*newp)->value.character.string, &chr[start - 1],
-          (*newp)->value.character.length);
+  chr = (*newp)->value.character.string = gfc_getmem (length + 1);
+  (*newp)->value.character.length = length;
+  memcpy (chr, &p->value.character.string[start - 1], length);
+  chr[length] = '\0';
   return SUCCESS;
 }
 
@@ -1238,7 +1356,7 @@ find_substring_ref (gfc_expr *p, gfc_expr **newp)
    parameter variable values are substituted.  */
 
 static try
-simplify_const_ref (gfc_expr * p)
+simplify_const_ref (gfc_expr *p)
 {
   gfc_constructor *cons;
   gfc_expr *newp;
@@ -1251,8 +1369,7 @@ simplify_const_ref (gfc_expr * p)
          switch (p->ref->u.ar.type)
            {
            case AR_ELEMENT:
-             if (find_array_element (p->value.constructor,
-                                     &p->ref->u.ar,
+             if (find_array_element (p->value.constructor, &p->ref->u.ar,
                                      &cons) == FAILURE)
                return FAILURE;
 
@@ -1267,11 +1384,11 @@ simplify_const_ref (gfc_expr * p)
                return FAILURE;
              p->ref->u.ar.type = AR_FULL;
 
-           /* FALLTHROUGH  */
+           /* Fall through.  */
 
            case AR_FULL:
              if (p->ref->next != NULL
-                   && (p->ts.type == BT_CHARACTER || p->ts.type == BT_DERIVED))
+                 && (p->ts.type == BT_CHARACTER || p->ts.type == BT_DERIVED))
                {
                  cons = p->value.constructor;
                  for (; cons; cons = cons->next)
@@ -1313,7 +1430,7 @@ simplify_const_ref (gfc_expr * p)
 /* Simplify a chain of references.  */
 
 static try
-simplify_ref_chain (gfc_ref * ref, int type)
+simplify_ref_chain (gfc_ref *ref, int type)
 {
   int n;
 
@@ -1324,16 +1441,12 @@ simplify_ref_chain (gfc_ref * ref, int type)
        case REF_ARRAY:
          for (n = 0; n < ref->u.ar.dimen; n++)
            {
-             if (gfc_simplify_expr (ref->u.ar.start[n], type)
-                   == FAILURE)
+             if (gfc_simplify_expr (ref->u.ar.start[n], type) == FAILURE)
                return FAILURE;
-             if (gfc_simplify_expr (ref->u.ar.end[n], type)
-                    == FAILURE)
+             if (gfc_simplify_expr (ref->u.ar.end[n], type) == FAILURE)
                return FAILURE;
-             if (gfc_simplify_expr (ref->u.ar.stride[n], type)
-                    == FAILURE)
+             if (gfc_simplify_expr (ref->u.ar.stride[n], type) == FAILURE)
                return FAILURE;
-
            }
          break;
 
@@ -1353,8 +1466,9 @@ simplify_ref_chain (gfc_ref * ref, int type)
 
 
 /* Try to substitute the value of a parameter variable.  */
+
 static try
-simplify_parameter_variable (gfc_expr * p, int type)
+simplify_parameter_variable (gfc_expr *p, int type)
 {
   gfc_expr *e;
   try t;
@@ -1370,9 +1484,8 @@ simplify_parameter_variable (gfc_expr * p, int type)
     e->ref = copy_ref (p->ref);
   t = gfc_simplify_expr (e, type);
 
-  /* Only use the simplification if it eliminated all subobject
-     references.  */
-  if (t == SUCCESS && ! e->ref)
+  /* Only use the simplification if it eliminated all subobject references.  */
+  if (t == SUCCESS && !e->ref)
     gfc_replace_expr (p, e);
   else
     gfc_free_expr (e);
@@ -1395,12 +1508,12 @@ simplify_parameter_variable (gfc_expr * p, int type)
    The expression type is defined for:
      0   Basic expression parsing
      1   Simplifying array constructors -- will substitute
-         iterator values.
+        iterator values.
    Returns FAILURE on error, SUCCESS otherwise.
    NOTE: Will return SUCCESS even if the expression can not be simplified.  */
 
 try
-gfc_simplify_expr (gfc_expr * p, int type)
+gfc_simplify_expr (gfc_expr *p, int type)
 {
   gfc_actual_arglist *ap;
 
@@ -1433,12 +1546,22 @@ gfc_simplify_expr (gfc_expr * p, int type)
          char *s;
          int start, end;
 
-         gfc_extract_int (p->ref->u.ss.start, &start);
-         start--;  /* Convert from one-based to zero-based.  */
-         gfc_extract_int (p->ref->u.ss.end, &end);
+         if (p->ref && p->ref->u.ss.start)
+           {
+             gfc_extract_int (p->ref->u.ss.start, &start);
+             start--;  /* Convert from one-based to zero-based.  */
+           }
+         else
+           start = 0;
+
+         if (p->ref && p->ref->u.ss.end)
+           gfc_extract_int (p->ref->u.ss.end, &end);
+         else
+           end = p->value.character.length;
+
          s = gfc_getmem (end - start + 2);
          memcpy (s, p->value.character.string + start, end - start);
-         s[end-start+1] = '\0';  /* TODO: C-style string for debugging.  */
+         s[end - start + 1] = '\0';  /* TODO: C-style string.  */
          gfc_free (p->value.character.string);
          p->value.character.string = s;
          p->value.character.length = end - start;
@@ -1459,7 +1582,7 @@ gfc_simplify_expr (gfc_expr * p, int type)
 
     case EXPR_VARIABLE:
       /* Only substitute array parameter variables if we are in an
-         initialization expression, or we want a subsection.  */
+        initialization expression, or we want a subsection.  */
       if (p->symtree->n.sym->attr.flavor == FL_PARAMETER
          && (gfc_init_expr || p->ref
              || p->symtree->n.sym->value->expr_type != EXPR_ARRAY))
@@ -1488,9 +1611,8 @@ gfc_simplify_expr (gfc_expr * p, int type)
       if (simplify_constructor (p->value.constructor, type) == FAILURE)
        return FAILURE;
 
-      if (p->expr_type == EXPR_ARRAY
-           && p->ref && p->ref->type == REF_ARRAY
-           && p->ref->u.ar.type == AR_FULL)
+      if (p->expr_type == EXPR_ARRAY && p->ref && p->ref->type == REF_ARRAY
+         && p->ref->u.ar.type == AR_FULL)
          gfc_expand_constructor (p);
 
       if (simplify_const_ref (p) == FAILURE)
@@ -1508,9 +1630,8 @@ gfc_simplify_expr (gfc_expr * p, int type)
    be declared as.  */
 
 static bt
-et0 (gfc_expr * e)
+et0 (gfc_expr *e)
 {
-
   if (e->expr_type == EXPR_VARIABLE && gfc_check_iter_variable (e) == SUCCESS)
     return BT_INTEGER;
 
@@ -1523,8 +1644,130 @@ et0 (gfc_expr * e)
 
 static try check_init_expr (gfc_expr *);
 
+
+/* Scalarize an expression for an elemental intrinsic call.  */
+
 static try
-check_intrinsic_op (gfc_expr * e, try (*check_function) (gfc_expr *))
+scalarize_intrinsic_call (gfc_expr *e)
+{
+  gfc_actual_arglist *a, *b;
+  gfc_constructor *args[5], *ctor, *new_ctor;
+  gfc_expr *expr, *old;
+  int n, i, rank[5];
+
+  old = gfc_copy_expr (e);
+
+/* Assume that the old expression carries the type information and
+   that the first arg carries all the shape information.  */
+  expr = gfc_copy_expr (old->value.function.actual->expr);
+  gfc_free_constructor (expr->value.constructor);
+  expr->value.constructor = NULL;
+
+  expr->ts = old->ts;
+  expr->expr_type = EXPR_ARRAY;
+
+  /* Copy the array argument constructors into an array, with nulls
+     for the scalars.  */
+  n = 0;
+  a = old->value.function.actual;
+  for (; a; a = a->next)
+    {
+      /* Check that this is OK for an initialization expression.  */
+      if (a->expr && check_init_expr (a->expr) == FAILURE)
+       goto cleanup;
+
+      rank[n] = 0;
+      if (a->expr && a->expr->rank && a->expr->expr_type == EXPR_VARIABLE)
+       {
+         rank[n] = a->expr->rank;
+         ctor = a->expr->symtree->n.sym->value->value.constructor;
+         args[n] = gfc_copy_constructor (ctor);
+       }
+      else if (a->expr && a->expr->expr_type == EXPR_ARRAY)
+       {
+         if (a->expr->rank)
+           rank[n] = a->expr->rank;
+         else
+           rank[n] = 1;
+         args[n] = gfc_copy_constructor (a->expr->value.constructor);
+       }
+      else
+       args[n] = NULL;
+      n++;
+    }
+
+  for (i = 1; i < n; i++)
+    if (rank[i] && rank[i] != rank[0])
+      goto compliance;
+
+  /* Using the first argument as the master, step through the array
+     calling the function for each element and advancing the array
+     constructors together.  */
+  ctor = args[0];
+  new_ctor = NULL;
+  for (; ctor; ctor = ctor->next)
+    {
+         if (expr->value.constructor == NULL)
+           expr->value.constructor
+               = new_ctor = gfc_get_constructor ();
+         else
+           {
+             new_ctor->next = gfc_get_constructor ();
+             new_ctor = new_ctor->next;
+           }
+         new_ctor->expr = gfc_copy_expr (old);
+         gfc_free_actual_arglist (new_ctor->expr->value.function.actual);
+         a = NULL;
+         b = old->value.function.actual;
+         for (i = 0; i < n; i++)
+           {
+             if (a == NULL)
+               new_ctor->expr->value.function.actual
+                       = a = gfc_get_actual_arglist ();
+             else
+               {
+                 a->next = gfc_get_actual_arglist ();
+                 a = a->next;
+               }
+             if (args[i])
+               a->expr = gfc_copy_expr (args[i]->expr);
+             else
+               a->expr = gfc_copy_expr (b->expr);
+
+             b = b->next;
+           }
+
+         /* Simplify the function calls.  */
+         if (gfc_simplify_expr (new_ctor->expr, 0) == FAILURE)
+           goto cleanup;
+
+         for (i = 0; i < n; i++)
+           if (args[i])
+             args[i] = args[i]->next;
+
+         for (i = 1; i < n; i++)
+           if (rank[i] && ((args[i] != NULL && args[0] == NULL)
+                        || (args[i] == NULL && args[0] != NULL)))
+             goto compliance;
+    }
+
+  free_expr0 (e);
+  *e = *expr;
+  gfc_free_expr (old);
+  return SUCCESS;
+
+compliance:
+  gfc_error_now ("elemental function arguments at %C are not compliant");
+
+cleanup:
+  gfc_free_expr (expr);
+  gfc_free_expr (old);
+  return FAILURE;
+}
+
+
+static try
+check_intrinsic_op (gfc_expr *e, try (*check_function) (gfc_expr *))
 {
   gfc_expr *op1 = e->value.op.op1;
   gfc_expr *op2 = e->value.op.op2;
@@ -1541,11 +1784,17 @@ check_intrinsic_op (gfc_expr * e, try (*check_function) (gfc_expr *))
       break;
 
     case INTRINSIC_EQ:
+    case INTRINSIC_EQ_OS:
     case INTRINSIC_NE:
+    case INTRINSIC_NE_OS:
     case INTRINSIC_GT:
+    case INTRINSIC_GT_OS:
     case INTRINSIC_GE:
+    case INTRINSIC_GE_OS:
     case INTRINSIC_LT:
+    case INTRINSIC_LT_OS:
     case INTRINSIC_LE:
+    case INTRINSIC_LE_OS:
       if ((*check_function) (op2) == FAILURE)
        return FAILURE;
       
@@ -1554,7 +1803,7 @@ check_intrinsic_op (gfc_expr * e, try (*check_function) (gfc_expr *))
        {
          gfc_error ("Numeric or CHARACTER operands are required in "
                     "expression at %L", &e->where);
-         return FAILURE;
+        return FAILURE;
        }
       break;
 
@@ -1572,9 +1821,11 @@ check_intrinsic_op (gfc_expr * e, try (*check_function) (gfc_expr *))
       if (e->value.op.operator == INTRINSIC_POWER
          && check_function == check_init_expr && et0 (op2) != BT_INTEGER)
        {
-         gfc_error ("Exponent at %L must be INTEGER for an initialization "
-                    "expression", &op2->where);
-         return FAILURE;
+         if (gfc_notify_std (GFC_STD_F2003,"Fortran 2003: Noninteger "
+                             "exponent in an initialization "
+                             "expression at %L", &op2->where)
+             == FAILURE)
+           return FAILURE;
        }
 
       break;
@@ -1643,69 +1894,195 @@ not_numeric:
 }
 
 
+static match
+check_init_expr_arguments (gfc_expr *e)
+{
+  gfc_actual_arglist *ap;
+
+  for (ap = e->value.function.actual; ap; ap = ap->next)
+    if (check_init_expr (ap->expr) == FAILURE)
+      return MATCH_ERROR;
+
+  return MATCH_YES;
+}
 
-/* Certain inquiry functions are specifically allowed to have variable
-   arguments, which is an exception to the normal requirement that an
-   initialization function have initialization arguments.  We head off
-   this problem here.  */
+/* F95, 7.1.6.1, Initialization expressions, (7)
+   F2003, 7.1.7 Initialization expression, (8)  */
 
-static try
-check_inquiry (gfc_expr * e, int not_restricted)
+static match
+check_inquiry (gfc_expr *e, int not_restricted)
 {
   const char *name;
+  const char *const *functions;
+
+  static const char *const inquiry_func_f95[] = {
+    "lbound", "shape", "size", "ubound",
+    "bit_size", "len", "kind",
+    "digits", "epsilon", "huge", "maxexponent", "minexponent",
+    "precision", "radix", "range", "tiny",
+    NULL
+  };
 
-  /* FIXME: This should be moved into the intrinsic definitions,
-     to eliminate this ugly hack.  */
-  static const char * const inquiry_function[] = {
-    "digits", "epsilon", "huge", "kind", "len", "maxexponent", "minexponent",
-    "precision", "radix", "range", "tiny", "bit_size", "size", "shape",
-    "lbound", "ubound", NULL
+  static const char *const inquiry_func_f2003[] = {
+    "lbound", "shape", "size", "ubound",
+    "bit_size", "len", "kind",
+    "digits", "epsilon", "huge", "maxexponent", "minexponent",
+    "precision", "radix", "range", "tiny",
+    "new_line", NULL
   };
 
   int i;
+  gfc_actual_arglist *ap;
+
+  if (!e->value.function.isym
+      || !e->value.function.isym->inquiry)
+    return MATCH_NO;
 
   /* An undeclared parameter will get us here (PR25018).  */
   if (e->symtree == NULL)
-    return FAILURE;
+    return MATCH_NO;
 
   name = e->symtree->n.sym->name;
 
-  for (i = 0; inquiry_function[i]; i++)
-    if (strcmp (inquiry_function[i], name) == 0)
-      break;
+  functions = (gfc_option.warn_std & GFC_STD_F2003) 
+               ? inquiry_func_f2003 : inquiry_func_f95;
 
-  if (inquiry_function[i] == NULL)
-    return FAILURE;
-
-  e = e->value.function.actual->expr;
+  for (i = 0; functions[i]; i++)
+    if (strcmp (functions[i], name) == 0)
+      break;
 
-  if (e == NULL || e->expr_type != EXPR_VARIABLE)
-    return FAILURE;
+  if (functions[i] == NULL)
+    {
+      gfc_error ("Inquiry function '%s' at %L is not permitted "
+                "in an initialization expression", name, &e->where);
+      return MATCH_ERROR;
+    }
 
   /* At this point we have an inquiry function with a variable argument.  The
      type of the variable might be undefined, but we need it now, because the
-     arguments of these functions are allowed to be undefined.  */
+     arguments of these functions are not allowed to be undefined.  */
 
-  if (e->ts.type == BT_UNKNOWN)
+  for (ap = e->value.function.actual; ap; ap = ap->next)
     {
-      if (e->symtree->n.sym->ts.type == BT_UNKNOWN
-         && gfc_set_default_type (e->symtree->n.sym, 0, gfc_current_ns)
-            == FAILURE)
-       return FAILURE;
+      if (!ap->expr)
+       continue;
+
+      if (ap->expr->ts.type == BT_UNKNOWN)
+       {
+         if (ap->expr->symtree->n.sym->ts.type == BT_UNKNOWN
+             && gfc_set_default_type (ap->expr->symtree->n.sym, 0, gfc_current_ns)
+             == FAILURE)
+           return MATCH_NO;
+
+         ap->expr->ts = ap->expr->symtree->n.sym->ts;
+       }
 
-      e->ts = e->symtree->n.sym->ts;
+       /* Assumed character length will not reduce to a constant expression
+          with LEN, as required by the standard.  */
+       if (i == 5 && not_restricted
+           && ap->expr->symtree->n.sym->ts.type == BT_CHARACTER
+           && ap->expr->symtree->n.sym->ts.cl->length == NULL)
+         {
+           gfc_error ("assumed character length variable '%s' in constant "
+                      "expression at %L", e->symtree->n.sym->name, &e->where);
+             return MATCH_ERROR;
+         }
+       else if (not_restricted && check_init_expr (ap->expr) == FAILURE)
+         return MATCH_ERROR;
     }
 
-  /* Assumed character length will not reduce to a constant expression
-     with LEN, as required by the standard.  */
-  if (i == 4 && not_restricted
-       && e->symtree->n.sym->ts.type == BT_CHARACTER
-       && e->symtree->n.sym->ts.cl->length == NULL)
-    gfc_notify_std (GFC_STD_GNU, "assumed character length "
-                   "variable '%s' in constant expression at %L",
-                   e->symtree->n.sym->name, &e->where);
+  return MATCH_YES;
+}
 
-  return SUCCESS;
+
+/* F95, 7.1.6.1, Initialization expressions, (5)
+   F2003, 7.1.7 Initialization expression, (5)  */
+
+static match
+check_transformational (gfc_expr *e)
+{
+  static const char * const trans_func_f95[] = {
+    "repeat", "reshape", "selected_int_kind",
+    "selected_real_kind", "transfer", "trim", NULL
+  };
+
+  int i;
+  const char *name;
+
+  if (!e->value.function.isym
+      || !e->value.function.isym->transformational)
+    return MATCH_NO;
+
+  name = e->symtree->n.sym->name;
+
+  /* NULL() is dealt with below.  */
+  if (strcmp ("null", name) == 0)
+    return MATCH_NO;
+
+  for (i = 0; trans_func_f95[i]; i++)
+    if (strcmp (trans_func_f95[i], name) == 0)
+      break;
+
+  /* FIXME, F2003: implement translation of initialization
+     expressions before enabling this check. For F95, error
+     out if the transformational function is not in the list.  */
+#if 0
+  if (trans_func_f95[i] == NULL
+      && gfc_notify_std (GFC_STD_F2003, 
+                        "transformational intrinsic '%s' at %L is not permitted "
+                        "in an initialization expression", name, &e->where) == FAILURE)
+    return MATCH_ERROR;
+#else
+  if (trans_func_f95[i] == NULL)
+    {
+      gfc_error("transformational intrinsic '%s' at %L is not permitted "
+               "in an initialization expression", name, &e->where);
+      return MATCH_ERROR;
+    }
+#endif
+
+  return check_init_expr_arguments (e);
+}
+
+
+/* F95, 7.1.6.1, Initialization expressions, (6)
+   F2003, 7.1.7 Initialization expression, (6)  */
+
+static match
+check_null (gfc_expr *e)
+{
+  if (strcmp ("null", e->symtree->n.sym->name) != 0)
+    return MATCH_NO;
+
+  return check_init_expr_arguments (e);
+}
+
+
+static match
+check_elemental (gfc_expr *e)
+{
+  if (!e->value.function.isym
+      || !e->value.function.isym->elemental)
+    return MATCH_NO;
+
+  if ((e->ts.type != BT_INTEGER || e->ts.type != BT_CHARACTER)
+      && gfc_notify_std (GFC_STD_F2003, "Extension: Evaluation of "
+                       "nonstandard initialization expression at %L",
+                       &e->where) == FAILURE)
+    return MATCH_ERROR;
+
+  return check_init_expr_arguments (e);
+}
+
+
+static match
+check_conversion (gfc_expr *e)
+{
+  if (!e->value.function.isym
+      || !e->value.function.isym->conversion)
+    return MATCH_NO;
+
+  return check_init_expr_arguments (e);
 }
 
 
@@ -1717,11 +2094,11 @@ check_inquiry (gfc_expr * e, int not_restricted)
    FAILURE is returned an error message has been generated.  */
 
 static try
-check_init_expr (gfc_expr * e)
+check_init_expr (gfc_expr *e)
 {
-  gfc_actual_arglist *ap;
   match m;
   try t;
+  gfc_intrinsic_sym *isym;
 
   if (e == NULL)
     return SUCCESS;
@@ -1736,32 +2113,44 @@ check_init_expr (gfc_expr * e)
       break;
 
     case EXPR_FUNCTION:
-      t = SUCCESS;
-
-      if (check_inquiry (e, 1) != SUCCESS)
-       {
-         t = SUCCESS;
-         for (ap = e->value.function.actual; ap; ap = ap->next)
-           if (check_init_expr (ap->expr) == FAILURE)
-             {
-               t = FAILURE;
-               break;
-             }
-       }
+      t = FAILURE;
 
-      if (t == SUCCESS)
+      if ((m = check_specification_function (e)) != MATCH_YES)
        {
-         m = gfc_intrinsic_func_interface (e, 0);
+         if ((m = gfc_intrinsic_func_interface (e, 0)) != MATCH_YES)
+           {
+             gfc_error ("Function '%s' in initialization expression at %L "
+                        "must be an intrinsic or a specification function",
+                        e->symtree->n.sym->name, &e->where);
+             break;
+           }
 
-         if (m == MATCH_NO)
-           gfc_error ("Function '%s' in initialization expression at %L "
-                      "must be an intrinsic function",
-                       e->symtree->n.sym->name, &e->where);
+         if ((m = check_conversion (e)) == MATCH_NO
+             && (m = check_inquiry (e, 1)) == MATCH_NO
+             && (m = check_null (e)) == MATCH_NO
+             && (m = check_transformational (e)) == MATCH_NO
+             && (m = check_elemental (e)) == MATCH_NO)
+           {
+             gfc_error ("Intrinsic function '%s' at %L is not permitted "
+                        "in an initialization expression",
+                        e->symtree->n.sym->name, &e->where);
+             m = MATCH_ERROR;
+           }
 
-         if (m != MATCH_YES)
-           t = FAILURE;
+         /* Try to scalarize an elemental intrinsic function that has an
+            array argument.  */
+         isym = gfc_find_function (e->symtree->n.sym->name);
+         if (isym && isym->elemental
+             && e->value.function.actual->expr->expr_type == EXPR_ARRAY)
+           {
+               if ((t = scalarize_intrinsic_call (e)) == SUCCESS)
+               break;
+           }
        }
 
+      if (m == MATCH_YES)
+       t = gfc_simplify_expr (e, 0);
+
       break;
 
     case EXPR_VARIABLE:
@@ -1776,10 +2165,42 @@ check_init_expr (gfc_expr * e)
          break;
        }
 
-      gfc_error ("Parameter '%s' at %L has not been declared or is "
-                "a variable, which does not reduce to a constant "
-                "expression", e->symtree->n.sym->name, &e->where);
+      if (gfc_in_match_data ())
+       break;
+
       t = FAILURE;
+
+      if (e->symtree->n.sym->as)
+       {
+         switch (e->symtree->n.sym->as->type)
+           {
+             case AS_ASSUMED_SIZE:
+               gfc_error ("assumed size array '%s' at %L is not permitted "
+                          "in an initialization expression",
+                          e->symtree->n.sym->name, &e->where);
+               break;
+
+             case AS_ASSUMED_SHAPE:
+               gfc_error ("assumed shape array '%s' at %L is not permitted "
+                          "in an initialization expression",
+                          e->symtree->n.sym->name, &e->where);
+               break;
+
+             case AS_DEFERRED:
+               gfc_error ("deferred array '%s' at %L is not permitted "
+                          "in an initialization expression",
+                          e->symtree->n.sym->name, &e->where);
+               break;
+
+             default:
+               gcc_unreachable();
+         }
+       }
+      else
+       gfc_error ("Parameter '%s' at %L has not been declared or is "
+                  "a variable, which does not reduce to a constant "
+                  "expression", e->symtree->n.sym->name, &e->where);
+
       break;
 
     case EXPR_CONSTANT:
@@ -1826,7 +2247,7 @@ check_init_expr (gfc_expr * e)
    expression, then reducing it to a constant.  */
 
 match
-gfc_match_init_expr (gfc_expr ** result)
+gfc_match_init_expr (gfc_expr **result)
 {
   gfc_expr *expr;
   match m;
@@ -1858,8 +2279,8 @@ gfc_match_init_expr (gfc_expr ** result)
 
   /* Not all inquiry functions are simplified to constant expressions
      so it is necessary to call check_inquiry again.  */ 
-  if (!gfc_is_constant_expr (expr)
-       && check_inquiry (expr, 1) == FAILURE)
+  if (!gfc_is_constant_expr (expr) && check_inquiry (expr, 1) != MATCH_YES
+      && !gfc_in_match_data ())
     {
       gfc_error ("Initialization expression didn't reduce %C");
       return MATCH_ERROR;
@@ -1871,7 +2292,6 @@ gfc_match_init_expr (gfc_expr ** result)
 }
 
 
-
 static try check_restricted (gfc_expr *);
 
 /* Given an actual argument list, test to see that each argument is a
@@ -1879,7 +2299,7 @@ static try check_restricted (gfc_expr *);
    integer or character.  */
 
 static try
-restricted_args (gfc_actual_arglist * a)
+restricted_args (gfc_actual_arglist *a)
 {
   for (; a; a = a->next)
     {
@@ -1897,7 +2317,7 @@ restricted_args (gfc_actual_arglist * a)
 /* Make sure a non-intrinsic function is a specification function.  */
 
 static try
-external_spec_function (gfc_expr * e)
+external_spec_function (gfc_expr *e)
 {
   gfc_symbol *f;
 
@@ -1939,10 +2359,10 @@ external_spec_function (gfc_expr * e)
    restricted expression.  */
 
 static try
-restricted_intrinsic (gfc_expr * e)
+restricted_intrinsic (gfc_expr *e)
 {
   /* TODO: Check constraints on inquiry functions.  7.1.6.2 (7).  */
-  if (check_inquiry (e, 0) == SUCCESS)
+  if (check_inquiry (e, 0) == MATCH_YES)
     return SUCCESS;
 
   return restricted_args (e->value.function.actual);
@@ -1954,7 +2374,7 @@ restricted_intrinsic (gfc_expr * e)
    return FAILURE.  */
 
 static try
-check_restricted (gfc_expr * e)
+check_restricted (gfc_expr *e)
 {
   gfc_symbol *sym;
   try t;
@@ -1972,9 +2392,8 @@ check_restricted (gfc_expr * e)
       break;
 
     case EXPR_FUNCTION:
-      t = e->value.function.esym ?
-       external_spec_function (e) : restricted_intrinsic (e);
-
+      t = e->value.function.esym ? external_spec_function (e)
+                                : restricted_intrinsic (e);
       break;
 
     case EXPR_VARIABLE:
@@ -1995,16 +2414,18 @@ check_restricted (gfc_expr * e)
          break;
        }
 
-      /* gfc_is_formal_arg broadcasts that a formal argument list is being processed
-        in resolve.c(resolve_formal_arglist).  This is done so that host associated
-        dummy array indices are accepted (PR23446).  */
+      /* gfc_is_formal_arg broadcasts that a formal argument list is being
+        processed in resolve.c(resolve_formal_arglist).  This is done so
+        that host associated dummy array indices are accepted (PR23446).
+        This mechanism also does the same for the specification expressions
+        of array-valued functions.  */
       if (sym->attr.in_common
          || sym->attr.use_assoc
          || sym->attr.dummy
          || sym->ns != gfc_current_ns
          || (sym->ns->proc_name != NULL
              && sym->ns->proc_name->attr.flavor == FL_MODULE)
-         || gfc_is_formal_arg ())
+         || (gfc_is_formal_arg () && (sym->ns == gfc_current_ns)))
        {
          t = SUCCESS;
          break;
@@ -2051,8 +2472,9 @@ check_restricted (gfc_expr * e)
    we return FAILURE, an error has been generated.  */
 
 try
-gfc_specification_expr (gfc_expr * e)
+gfc_specification_expr (gfc_expr *e)
 {
+
   if (e == NULL)
     return SUCCESS;
 
@@ -2080,8 +2502,7 @@ gfc_specification_expr (gfc_expr * e)
 /* Given two expressions, make sure that the arrays are conformable.  */
 
 try
-gfc_check_conformance (const char *optype_msgid,
-                      gfc_expr * op1, gfc_expr * op2)
+gfc_check_conformance (const char *optype_msgid, gfc_expr *op1, gfc_expr *op2)
 {
   int op1_flag, op2_flag, d;
   mpz_t op1_size, op2_size;
@@ -2131,32 +2552,44 @@ gfc_check_conformance (const char *optype_msgid,
    sure that the assignment can take place.  */
 
 try
-gfc_check_assign (gfc_expr * lvalue, gfc_expr * rvalue, int conform)
+gfc_check_assign (gfc_expr *lvalue, gfc_expr *rvalue, int conform)
 {
   gfc_symbol *sym;
+  gfc_ref *ref;
+  int has_pointer;
 
   sym = lvalue->symtree->n.sym;
 
-  if (sym->attr.intent == INTENT_IN)
+  /* Check INTENT(IN), unless the object itself is the component or
+     sub-component of a pointer.  */
+  has_pointer = sym->attr.pointer;
+
+  for (ref = lvalue->ref; ref; ref = ref->next)
+    if (ref->type == REF_COMPONENT && ref->u.c.component->pointer)
+      {
+       has_pointer = 1;
+       break;
+      }
+
+  if (!has_pointer && sym->attr.intent == INTENT_IN)
     {
-      gfc_error ("Can't assign to INTENT(IN) variable '%s' at %L",
+      gfc_error ("Cannot assign to INTENT(IN) variable '%s' at %L",
                 sym->name, &lvalue->where);
       return FAILURE;
     }
 
-/* 12.5.2.2, Note 12.26: The result variable is very similar to any other
-   variable local to a function subprogram.  Its existence begins when
-   execution of the function is initiated and ends when execution of the
-   function is terminated.....
-   Therefore, the left hand side is no longer a varaiable, when it is:*/
-  if (sym->attr.flavor == FL_PROCEDURE
-       && sym->attr.proc != PROC_ST_FUNCTION
-       && !sym->attr.external)
+  /* 12.5.2.2, Note 12.26: The result variable is very similar to any other
+     variable local to a function subprogram.  Its existence begins when
+     execution of the function is initiated and ends when execution of the
+     function is terminated...
+     Therefore, the left hand side is no longer a variable, when it is:  */
+  if (sym->attr.flavor == FL_PROCEDURE && sym->attr.proc != PROC_ST_FUNCTION
+      && !sym->attr.external)
     {
       bool bad_proc;
       bad_proc = false;
 
-      /* (i) Use associated; */
+      /* (i) Use associated;  */
       if (sym->attr.use_assoc)
        bad_proc = true;
 
@@ -2164,19 +2597,19 @@ gfc_check_assign (gfc_expr * lvalue, gfc_expr * rvalue, int conform)
       if (gfc_current_ns->proc_name->attr.is_main_program)
        bad_proc = true;
 
-      /* (iii) A module or internal procedure....  */
+      /* (iii) A module or internal procedure...  */
       if ((gfc_current_ns->proc_name->attr.proc == PROC_INTERNAL
-            || gfc_current_ns->proc_name->attr.proc == PROC_MODULE)
+          || gfc_current_ns->proc_name->attr.proc == PROC_MODULE)
          && gfc_current_ns->parent
          && (!(gfc_current_ns->parent->proc_name->attr.function
-                 || gfc_current_ns->parent->proc_name->attr.subroutine)
+               || gfc_current_ns->parent->proc_name->attr.subroutine)
              || gfc_current_ns->parent->proc_name->attr.is_main_program))
        {
-         /* .... that is not a function.... */ 
+         /* ... that is not a function...  */ 
          if (!gfc_current_ns->proc_name->attr.function)
            bad_proc = true;
 
-         /* .... or is not an entry and has a different name.  */
+         /* ... or is not an entry and has a different name.  */
          if (!sym->attr.entry && sym->name != gfc_current_ns->proc_name->name)
            bad_proc = true;
        }
@@ -2202,24 +2635,30 @@ gfc_check_assign (gfc_expr * lvalue, gfc_expr * rvalue, int conform)
       return FAILURE;
     }
 
-   if (rvalue->expr_type == EXPR_NULL)
-     {
-       gfc_error ("NULL appears on right-hand side in assignment at %L",
-                 &rvalue->where);
-       return FAILURE;
-     }
+  if (rvalue->expr_type == EXPR_NULL)
+    {  
+      if (lvalue->symtree->n.sym->attr.pointer
+         && lvalue->symtree->n.sym->attr.data)
+        return SUCCESS;
+      else
+       {
+         gfc_error ("NULL appears on right-hand side in assignment at %L",
+                    &rvalue->where);
+         return FAILURE;
+       }
+    }
 
    if (sym->attr.cray_pointee
        && lvalue->ref != NULL
        && lvalue->ref->u.ar.type == AR_FULL
        && lvalue->ref->u.ar.as->cp_was_assumed)
      {
-       gfc_error ("Vector assignment to assumed-size Cray Pointee at %L"
-                 " is illegal.", &lvalue->where);
+       gfc_error ("Vector assignment to assumed-size Cray Pointee at %L "
+                 "is illegal", &lvalue->where);
        return FAILURE;
      }
 
-  /* This is possibly a typo: x = f() instead of x => f()  */
+  /* This is possibly a typo: x = f() instead of x => f().  */
   if (gfc_option.warn_surprising 
       && rvalue->expr_type == EXPR_FUNCTION
       && rvalue->symtree->n.sym->attr.pointer)
@@ -2261,10 +2700,12 @@ gfc_check_assign (gfc_expr * lvalue, gfc_expr * rvalue, int conform)
    NULLIFY statement.  */
 
 try
-gfc_check_pointer_assign (gfc_expr * lvalue, gfc_expr * rvalue)
+gfc_check_pointer_assign (gfc_expr *lvalue, gfc_expr *rvalue)
 {
   symbol_attribute attr;
+  gfc_ref *ref;
   int is_pure;
+  int pointer, check_intent_in;
 
   if (lvalue->symtree->n.sym->ts.type == BT_UNKNOWN)
     {
@@ -2274,7 +2715,7 @@ gfc_check_pointer_assign (gfc_expr * lvalue, gfc_expr * rvalue)
     }
 
   if (lvalue->symtree->n.sym->attr.flavor == FL_PROCEDURE
-       && lvalue->symtree->n.sym->attr.use_assoc)
+      && lvalue->symtree->n.sym->attr.use_assoc)
     {
       gfc_error ("'%s' in the pointer assignment at %L cannot be an "
                 "l-value since it is a procedure",
@@ -2282,8 +2723,29 @@ gfc_check_pointer_assign (gfc_expr * lvalue, gfc_expr * rvalue)
       return FAILURE;
     }
 
-  attr = gfc_variable_attr (lvalue, NULL);
-  if (!attr.pointer)
+
+  /* Check INTENT(IN), unless the object itself is the component or
+     sub-component of a pointer.  */
+  check_intent_in = 1;
+  pointer = lvalue->symtree->n.sym->attr.pointer;
+
+  for (ref = lvalue->ref; ref; ref = ref->next)
+    {
+      if (pointer)
+       check_intent_in = 0;
+
+      if (ref->type == REF_COMPONENT && ref->u.c.component->pointer)
+       pointer = 1;
+    }
+
+  if (check_intent_in && lvalue->symtree->n.sym->attr.intent == INTENT_IN)
+    {
+      gfc_error ("Cannot assign to INTENT(IN) variable '%s' at %L",
+                lvalue->symtree->n.sym->name, &lvalue->where);
+      return FAILURE;
+    }
+
+  if (!pointer)
     {
       gfc_error ("Pointer assignment to non-POINTER at %L", &lvalue->where);
       return FAILURE;
@@ -2291,10 +2753,10 @@ gfc_check_pointer_assign (gfc_expr * lvalue, gfc_expr * rvalue)
 
   is_pure = gfc_pure (NULL);
 
-  if (is_pure && gfc_impure_variable (lvalue->symtree->n.sym))
+  if (is_pure && gfc_impure_variable (lvalue->symtree->n.sym)
+       && lvalue->symtree->n.sym->value != rvalue)
     {
-      gfc_error ("Bad pointer object in PURE procedure at %L",
-                &lvalue->where);
+      gfc_error ("Bad pointer object in PURE procedure at %L", &lvalue->where);
       return FAILURE;
     }
 
@@ -2321,7 +2783,7 @@ gfc_check_pointer_assign (gfc_expr * lvalue, gfc_expr * rvalue)
   if (lvalue->rank != rvalue->rank)
     {
       gfc_error ("Different ranks in pointer assignment at %L",
-                 &lvalue->where);
+                &lvalue->where);
       return FAILURE;
     }
 
@@ -2330,9 +2792,10 @@ gfc_check_pointer_assign (gfc_expr * lvalue, gfc_expr * rvalue)
     return SUCCESS;
 
   if (lvalue->ts.type == BT_CHARACTER
-       && lvalue->ts.cl->length && rvalue->ts.cl->length
-       && abs (gfc_dep_compare_expr (lvalue->ts.cl->length,
-                                     rvalue->ts.cl->length)) == 1)
+      && lvalue->ts.cl && rvalue->ts.cl
+      && lvalue->ts.cl->length && rvalue->ts.cl->length
+      && abs (gfc_dep_compare_expr (lvalue->ts.cl->length,
+                                   rvalue->ts.cl->length)) == 1)
     {
       gfc_error ("Different character lengths in pointer "
                 "assignment at %L", &lvalue->where);
@@ -2360,6 +2823,13 @@ gfc_check_pointer_assign (gfc_expr * lvalue, gfc_expr * rvalue)
       return FAILURE;
     }
 
+  if (attr.protected && attr.use_assoc)
+    {
+      gfc_error ("Pointer assigment target has PROTECTED "
+                "attribute at %L", &rvalue->where);
+      return FAILURE;
+    }
+
   return SUCCESS;
 }
 
@@ -2368,7 +2838,7 @@ gfc_check_pointer_assign (gfc_expr * lvalue, gfc_expr * rvalue)
    symbol.  Used for initialization assignments.  */
 
 try
-gfc_check_assign_symbol (gfc_symbol * sym, gfc_expr * rvalue)
+gfc_check_assign_symbol (gfc_symbol *sym, gfc_expr *rvalue)
 {
   gfc_expr lvalue;
   try r;
@@ -2379,7 +2849,7 @@ gfc_check_assign_symbol (gfc_symbol * sym, gfc_expr * rvalue)
   lvalue.ts = sym->ts;
   if (sym->as)
     lvalue.rank = sym->as->rank;
-  lvalue.symtree = (gfc_symtree *)gfc_getmem (sizeof (gfc_symtree));
+  lvalue.symtree = (gfc_symtree *) gfc_getmem (sizeof (gfc_symtree));
   lvalue.symtree->n.sym = sym;
   lvalue.where = sym->declared_at;
 
@@ -2409,7 +2879,7 @@ gfc_default_initializer (gfc_typespec *ts)
   for (c = ts->derived->components; c; c = c->next)
     {
       if ((c->initializer || c->allocatable) && init == NULL)
-        init = gfc_get_expr ();
+       init = gfc_get_expr ();
     }
 
   if (init == NULL)
@@ -2423,15 +2893,15 @@ gfc_default_initializer (gfc_typespec *ts)
   for (c = ts->derived->components; c; c = c->next)
     {
       if (tail == NULL)
-        init->value.constructor = tail = gfc_get_constructor ();
+       init->value.constructor = tail = gfc_get_constructor ();
       else
-        {
-          tail->next = gfc_get_constructor ();
-          tail = tail->next;
-        }
+       {
+         tail->next = gfc_get_constructor ();
+         tail = tail->next;
+       }
 
       if (c->initializer)
-        tail->expr = gfc_copy_expr (c->initializer);
+       tail->expr = gfc_copy_expr (c->initializer);
 
       if (c->allocatable)
        {
@@ -2449,7 +2919,7 @@ gfc_default_initializer (gfc_typespec *ts)
    whole array.  */
 
 gfc_expr *
-gfc_get_variable_expr (gfc_symtree * var)
+gfc_get_variable_expr (gfc_symtree *var)
 {
   gfc_expr *e;
 
@@ -2473,7 +2943,7 @@ gfc_get_variable_expr (gfc_symtree * var)
 /* Traverse expr, marking all EXPR_VARIABLE symbols referenced.  */
 
 void
-gfc_expr_set_symbols_referenced (gfc_expr * expr)
+gfc_expr_set_symbols_referenced (gfc_expr *expr)
 {
   gfc_actual_arglist *arg;
   gfc_constructor *c;
@@ -2491,7 +2961,7 @@ gfc_expr_set_symbols_referenced (gfc_expr * expr)
 
     case EXPR_FUNCTION:
       for (arg = expr->value.function.actual; arg; arg = arg->next)
-        gfc_expr_set_symbols_referenced (arg->expr);
+       gfc_expr_set_symbols_referenced (arg->expr);
       break;
 
     case EXPR_VARIABLE:
@@ -2506,7 +2976,7 @@ gfc_expr_set_symbols_referenced (gfc_expr * expr)
     case EXPR_STRUCTURE:
     case EXPR_ARRAY:
       for (c = expr->value.constructor; c; c = c->next)
-        gfc_expr_set_symbols_referenced (c->expr);
+       gfc_expr_set_symbols_referenced (c->expr);
       break;
 
     default:
@@ -2516,26 +2986,26 @@ gfc_expr_set_symbols_referenced (gfc_expr * expr)
 
     for (ref = expr->ref; ref; ref = ref->next)
       switch (ref->type)
-        {
-        case REF_ARRAY:
-          for (i = 0; i < ref->u.ar.dimen; i++)
-            {
-              gfc_expr_set_symbols_referenced (ref->u.ar.start[i]);
-              gfc_expr_set_symbols_referenced (ref->u.ar.end[i]);
-              gfc_expr_set_symbols_referenced (ref->u.ar.stride[i]);
-            }
-          break;
-           
-        case REF_COMPONENT:
-          break;
-           
-        case REF_SUBSTRING:
-          gfc_expr_set_symbols_referenced (ref->u.ss.start);
-          gfc_expr_set_symbols_referenced (ref->u.ss.end);
-          break;
-           
-        default:
-          gcc_unreachable ();
-          break;
-        }
+       {
+       case REF_ARRAY:
+         for (i = 0; i < ref->u.ar.dimen; i++)
+           {
+             gfc_expr_set_symbols_referenced (ref->u.ar.start[i]);
+             gfc_expr_set_symbols_referenced (ref->u.ar.end[i]);
+             gfc_expr_set_symbols_referenced (ref->u.ar.stride[i]);
+           }
+         break;
+          
+       case REF_COMPONENT:
+         break;
+          
+       case REF_SUBSTRING:
+         gfc_expr_set_symbols_referenced (ref->u.ss.start);
+         gfc_expr_set_symbols_referenced (ref->u.ss.end);
+         break;
+          
+       default:
+         gcc_unreachable ();
+         break;
+       }
 }