72aed9d
git diff --stat -p gdb/master...gdb/users/bheckel/fortran-strides
d258670
dbfd7140bf4c0500d1f5d192be781f83f78f7922
72aed9d
d258670
 gdb/dwarf2loc.c                             |  46 ++-
d258670
 gdb/dwarf2loc.h                             |   6 +
72aed9d
 gdb/dwarf2read.c                            |  13 +-
72aed9d
 gdb/eval.c                                  | 391 +++++++++++++++++++++-----
72aed9d
 gdb/expprint.c                              |  20 +-
72aed9d
 gdb/expression.h                            |  18 +-
72aed9d
 gdb/f-exp.y                                 |  42 ++-
72aed9d
 gdb/f-valprint.c                            |   8 +-
d258670
 gdb/gdbtypes.c                              |  34 ++-
d258670
 gdb/gdbtypes.h                              |  18 +-
72aed9d
 gdb/parse.c                                 |  24 +-
72aed9d
 gdb/rust-exp.y                              |  12 +-
72aed9d
 gdb/rust-lang.c                             |  17 +-
72aed9d
 gdb/testsuite/gdb.fortran/static-arrays.exp | 421 ++++++++++++++++++++++++++++
72aed9d
 gdb/testsuite/gdb.fortran/static-arrays.f90 |  55 ++++
d258670
 gdb/testsuite/gdb.fortran/vla-ptype.exp     |   4 +
d258670
 gdb/testsuite/gdb.fortran/vla-sizeof.exp    |   4 +
72aed9d
 gdb/testsuite/gdb.fortran/vla-stride.exp    |  44 +++
72aed9d
 gdb/testsuite/gdb.fortran/vla-stride.f90    |  29 ++
d258670
 gdb/testsuite/gdb.fortran/vla.f90           |  10 +
d258670
 gdb/valarith.c                              |  10 +-
72aed9d
 gdb/valops.c                                | 197 +++++++++++--
72aed9d
 gdb/value.h                                 |   2 +
d258670
 23 files changed, 1242 insertions(+), 183 deletions(-)
72aed9d
d258670
diff --git a/gdb/dwarf2loc.c b/gdb/dwarf2loc.c
d258670
index 548e468..560e16f 100644
d258670
--- a/gdb/dwarf2loc.c
d258670
+++ b/gdb/dwarf2loc.c
d258670
@@ -2601,11 +2601,14 @@ dwarf2_locexpr_baton_eval (const struct dwarf2_locexpr_baton *dlbaton,
d258670
 /* See dwarf2loc.h.  */
d258670
 
d258670
 int
d258670
-dwarf2_evaluate_property (const struct dynamic_prop *prop,
d258670
+dwarf2_evaluate_property_signed (const struct dynamic_prop *prop,
d258670
 			  struct frame_info *frame,
d258670
 			  struct property_addr_info *addr_stack,
d258670
-			  CORE_ADDR *value)
d258670
+			  CORE_ADDR *value,
d258670
+			  int is_signed)
d258670
 {
d258670
+  int rc = 0;
d258670
+
d258670
   if (prop == NULL)
d258670
     return 0;
d258670
 
d258670
@@ -2629,7 +2632,7 @@ dwarf2_evaluate_property (const struct dynamic_prop *prop,
d258670
 
d258670
 		*value = value_as_address (val);
d258670
 	      }
d258670
-	    return 1;
d258670
+	    rc = 1;
d258670
 	  }
d258670
       }
d258670
       break;
d258670
@@ -2651,7 +2654,7 @@ dwarf2_evaluate_property (const struct dynamic_prop *prop,
d258670
 	    if (!value_optimized_out (val))
d258670
 	      {
d258670
 		*value = value_as_address (val);
d258670
-		return 1;
d258670
+		rc = 1;
d258670
 	      }
d258670
 	  }
d258670
       }
d258670
@@ -2659,8 +2662,8 @@ dwarf2_evaluate_property (const struct dynamic_prop *prop,
d258670
 
d258670
     case PROP_CONST:
d258670
       *value = prop->data.const_val;
d258670
-      return 1;
d258670
-
d258670
+      rc = 1;
d258670
+      break;
d258670
     case PROP_ADDR_OFFSET:
d258670
       {
d258670
 	struct dwarf2_property_baton *baton
d258670
@@ -2681,11 +2684,38 @@ dwarf2_evaluate_property (const struct dynamic_prop *prop,
d258670
 	  val = value_at (baton->offset_info.type,
d258670
 			  pinfo->addr + baton->offset_info.offset);
d258670
 	*value = value_as_address (val);
d258670
-	return 1;
d258670
+	rc = 1;
d258670
       }
d258670
+      break;
d258670
     }
d258670
 
d258670
-  return 0;
d258670
+  if (rc == 1 && is_signed == 1)
d258670
+    {
d258670
+      /* If we have a valid return candidate and it's value is signed,
d258670
+         we have to sign-extend the value because CORE_ADDR on 64bit machine has
d258670
+         8 bytes but address size of an 32bit application is 4 bytes.  */
d258670
+      struct gdbarch * gdbarch = target_gdbarch ();
d258670
+      const int addr_bit = gdbarch_addr_bit (gdbarch);
d258670
+      const CORE_ADDR neg_mask = ((~0) <<  (addr_bit - 1));
d258670
+
d258670
+      /* Check if signed bit is set and sign-extend values.  */
d258670
+      if (*value & (neg_mask))
d258670
+	*value |= (neg_mask );
d258670
+    }
d258670
+  return rc;
d258670
+}
d258670
+
d258670
+int
d258670
+dwarf2_evaluate_property (const struct dynamic_prop *prop,
d258670
+			  struct frame_info *frame,
d258670
+			  struct property_addr_info *addr_stack,
d258670
+			  CORE_ADDR *value)
d258670
+{
d258670
+  return dwarf2_evaluate_property_signed (prop,
d258670
+				   frame,
d258670
+				   addr_stack,
d258670
+				   value,
d258670
+				   0);
d258670
 }
d258670
 
d258670
 /* See dwarf2loc.h.  */
d258670
diff --git a/gdb/dwarf2loc.h b/gdb/dwarf2loc.h
d258670
index fa83459..da6b9cd 100644
d258670
--- a/gdb/dwarf2loc.h
d258670
+++ b/gdb/dwarf2loc.h
d258670
@@ -138,6 +138,12 @@ int dwarf2_evaluate_property (const struct dynamic_prop *prop,
d258670
 			      struct property_addr_info *addr_stack,
d258670
 			      CORE_ADDR *value);
d258670
 
d258670
+int dwarf2_evaluate_property_signed (const struct dynamic_prop *prop,
d258670
+			      struct frame_info *frame,
d258670
+			      struct property_addr_info *addr_stack,
d258670
+			      CORE_ADDR *value,
d258670
+			      int is_signed);
d258670
+
d258670
 /* A helper for the compiler interface that compiles a single dynamic
d258670
    property to C code.
d258670
 
72aed9d
diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
72aed9d
index 6658a38..a1ac659 100644
72aed9d
--- a/gdb/dwarf2read.c
72aed9d
+++ b/gdb/dwarf2read.c
72aed9d
@@ -14952,7 +14952,7 @@ read_subrange_type (struct die_info *die, struct dwarf2_cu *cu)
72aed9d
   struct type *base_type, *orig_base_type;
72aed9d
   struct type *range_type;
72aed9d
   struct attribute *attr;
72aed9d
-  struct dynamic_prop low, high;
72aed9d
+  struct dynamic_prop low, high, stride;
72aed9d
   int low_default_is_valid;
72aed9d
   int high_bound_is_count = 0;
72aed9d
   const char *name;
72aed9d
@@ -14972,7 +14972,9 @@ read_subrange_type (struct die_info *die, struct dwarf2_cu *cu)
72aed9d
 
72aed9d
   low.kind = PROP_CONST;
72aed9d
   high.kind = PROP_CONST;
72aed9d
+  stride.kind = PROP_CONST;
72aed9d
   high.data.const_val = 0;
72aed9d
+  stride.data.const_val = 0;
72aed9d
 
72aed9d
   /* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow
72aed9d
      omitting DW_AT_lower_bound.  */
72aed9d
@@ -15006,6 +15008,13 @@ read_subrange_type (struct die_info *die, struct dwarf2_cu *cu)
72aed9d
       break;
72aed9d
     }
72aed9d
 
72aed9d
+  attr = dwarf2_attr (die, DW_AT_byte_stride, cu);
72aed9d
+  if (attr)
72aed9d
+    if (!attr_to_dynamic_prop (attr, die, cu, &stride))
72aed9d
+        complaint (&symfile_complaints, _("Missing DW_AT_byte_stride "
72aed9d
+                  "- DIE at 0x%x [in module %s]"),
72aed9d
+             die->offset.sect_off, objfile_name (cu->objfile));
72aed9d
+
72aed9d
   attr = dwarf2_attr (die, DW_AT_lower_bound, cu);
72aed9d
   if (attr)
72aed9d
     attr_to_dynamic_prop (attr, die, cu, &low);
72aed9d
@@ -15082,7 +15091,7 @@ read_subrange_type (struct die_info *die, struct dwarf2_cu *cu)
72aed9d
       && !TYPE_UNSIGNED (base_type) && (high.data.const_val & negative_mask))
72aed9d
     high.data.const_val |= negative_mask;
72aed9d
 
72aed9d
-  range_type = create_range_type (NULL, orig_base_type, &low, &high);
72aed9d
+  range_type = create_range_type (NULL, orig_base_type, &low, &high, &stride);
72aed9d
 
72aed9d
   if (high_bound_is_count)
72aed9d
     TYPE_RANGE_DATA (range_type)->flag_upper_bound_is_count = 1;
72aed9d
diff --git a/gdb/eval.c b/gdb/eval.c
72aed9d
index 00a107c..91d8a03 100644
72aed9d
--- a/gdb/eval.c
72aed9d
+++ b/gdb/eval.c
72aed9d
@@ -399,29 +399,325 @@ init_array_element (struct value *array, struct value *element,
72aed9d
   return index;
72aed9d
 }
72aed9d
 
72aed9d
+/* Evaluates any operation on Fortran arrays or strings with at least
72aed9d
+   one user provided parameter.  Expects the input ARRAY to be either
72aed9d
+   an array, or a string.  Evaluates EXP by incrementing POS, and
72aed9d
+   writes the content from the elt stack into a local struct.  NARGS
72aed9d
+   specifies number of literal or range arguments the user provided.
72aed9d
+   NARGS must be the same number as ARRAY has dimensions.  */
72aed9d
+
72aed9d
 static struct value *
72aed9d
-value_f90_subarray (struct value *array,
72aed9d
-		    struct expression *exp, int *pos, enum noside noside)
72aed9d
+value_f90_subarray (struct value *array, struct expression *exp,
72aed9d
+		    int *pos, int nargs, enum noside noside)
72aed9d
 {
72aed9d
-  int pc = (*pos) + 1;
72aed9d
+  int i, dim_count = 0;
72aed9d
   LONGEST low_bound, high_bound;
72aed9d
-  struct type *range = check_typedef (TYPE_INDEX_TYPE (value_type (array)));
72aed9d
-  enum range_type range_type
72aed9d
-    = (enum range_type) longest_to_int (exp->elts[pc].longconst);
72aed9d
- 
72aed9d
-  *pos += 3;
72aed9d
-
72aed9d
-  if (range_type == LOW_BOUND_DEFAULT || range_type == BOTH_BOUND_DEFAULT)
72aed9d
-    low_bound = TYPE_LOW_BOUND (range);
72aed9d
-  else
72aed9d
-    low_bound = value_as_long (evaluate_subexp (NULL_TYPE, exp, pos, noside));
72aed9d
+  struct value *new_array = array;
72aed9d
+  struct type *array_type = check_typedef (value_type (new_array));
72aed9d
+  struct type *elt_type;
72aed9d
+
72aed9d
+  typedef struct subscript_range
72aed9d
+  {
72aed9d
+    enum range_type f90_range_type;
72aed9d
+    LONGEST low, high, stride;
72aed9d
+  } subscript_range;
72aed9d
+
72aed9d
+  typedef enum subscript_kind
72aed9d
+  {
72aed9d
+    SUBSCRIPT_RANGE,    /* e.g. "(lowbound:highbound)"  */
72aed9d
+    SUBSCRIPT_INDEX    /* e.g. "(literal)"  */
72aed9d
+  } kind;
72aed9d
+
72aed9d
+  /* Local struct to hold user data for Fortran subarray dimensions.  */
72aed9d
+  struct subscript_store
72aed9d
+  {
72aed9d
+    /* For every dimension, we are either working on a range or an index
72aed9d
+       expression, so we store this info separately for later.  */
72aed9d
+    enum subscript_kind kind;
72aed9d
+
72aed9d
+    /* We also store either the lower and upper bound info, or the index
72aed9d
+       number.  Before evaluation of the input values, we do not know if we are
72aed9d
+       actually working on a range of ranges, or an index in a range.  So as a
72aed9d
+       first step we store all input in a union.  The array calculation itself
72aed9d
+       deals with this later on.  */
72aed9d
+    union element_range
72aed9d
+    {
72aed9d
+      subscript_range range;
72aed9d
+      LONGEST number;
72aed9d
+    } U;
72aed9d
+  } *subscript_array;
72aed9d
+
72aed9d
+  /* Check if the number of arguments provided by the user matches
72aed9d
+     the number of dimension of the array.  A string has only one
72aed9d
+     dimension.  */
72aed9d
+  if (nargs != calc_f77_array_dims (value_type (new_array)))
72aed9d
+    error (_("Wrong number of subscripts"));
72aed9d
+
72aed9d
+  subscript_array = (struct subscript_store*) alloca (sizeof (*subscript_array) * nargs);
72aed9d
+
72aed9d
+  /* Parse the user input into the SUBSCRIPT_ARRAY to store it.  We need
72aed9d
+     to evaluate it first, as the input is from left-to-right.  The
72aed9d
+     array is stored from right-to-left.  So we have to use the user
72aed9d
+     input in reverse order.  Later on, we need the input information to
72aed9d
+     re-calculate the output array.  For multi-dimensional arrays, we
72aed9d
+     can be dealing with any possible combination of ranges and indices
72aed9d
+     for every dimension.  */
72aed9d
+  for (i = 0; i < nargs; i++)
72aed9d
+    {
72aed9d
+      struct subscript_store *index = &subscript_array[i];
72aed9d
 
72aed9d
-  if (range_type == HIGH_BOUND_DEFAULT || range_type == BOTH_BOUND_DEFAULT)
72aed9d
-    high_bound = TYPE_HIGH_BOUND (range);
72aed9d
-  else
72aed9d
-    high_bound = value_as_long (evaluate_subexp (NULL_TYPE, exp, pos, noside));
72aed9d
+      /* The user input is a range, with or without lower and upper bound.
72aed9d
+	 E.g.: "p arry(2:5)", "p arry( :5)", "p arry( : )", etc.  */
72aed9d
+      if (exp->elts[*pos].opcode == OP_RANGE)
72aed9d
+	{
72aed9d
+	  int pc = (*pos) + 1;
72aed9d
+	  subscript_range *range;
72aed9d
+
72aed9d
+	  index->kind = SUBSCRIPT_RANGE;
72aed9d
+	  range = &index->U.range;
72aed9d
+
72aed9d
+	  *pos += 3;
72aed9d
+	  range->f90_range_type = (enum range_type) exp->elts[pc].longconst;
72aed9d
+
72aed9d
+	  /* If a lower bound was provided by the user, the bit has been
72aed9d
+	     set and we can assign the value from the elt stack.  Same for
72aed9d
+	     upper bound.  */
72aed9d
+	  if ((range->f90_range_type & SUBARRAY_LOW_BOUND)
72aed9d
+	      == SUBARRAY_LOW_BOUND)
72aed9d
+	    range->low = value_as_long (evaluate_subexp (NULL_TYPE, exp,
72aed9d
+							 pos, noside));
72aed9d
+	  if ((range->f90_range_type & SUBARRAY_HIGH_BOUND)
72aed9d
+	      == SUBARRAY_HIGH_BOUND)
72aed9d
+	    range->high = value_as_long (evaluate_subexp (NULL_TYPE, exp,
72aed9d
+							  pos, noside));
72aed9d
+
72aed9d
+	  /* Assign the user's stride value if provided.  */
72aed9d
+	  if ((range->f90_range_type & SUBARRAY_STRIDE) == SUBARRAY_STRIDE)
72aed9d
+	    range->stride = value_as_long (evaluate_subexp (NULL_TYPE, exp,
72aed9d
+							     pos, noside));
72aed9d
+
72aed9d
+	  /* Assign the default stride value '1'.  */
72aed9d
+	  else
72aed9d
+	    range->stride = 1;
72aed9d
+
72aed9d
+	  /* Check the provided stride value is illegal, aka '0'.  */
72aed9d
+	  if (range->stride == 0)
72aed9d
+	    error (_("Stride must not be 0"));
72aed9d
+	}
72aed9d
+      /* User input is an index.  E.g.: "p arry(5)".  */
72aed9d
+      else
72aed9d
+	{
72aed9d
+	  struct value *val;
72aed9d
+
72aed9d
+	  index->kind = SUBSCRIPT_INDEX;
72aed9d
+
72aed9d
+	  /* Evaluate each subscript; it must be a legal integer in F77.  This
72aed9d
+	     ensures the validity of the provided index.  */
72aed9d
+	  val = evaluate_subexp_with_coercion (exp, pos, noside);
72aed9d
+	  index->U.number = value_as_long (val);
72aed9d
+	}
72aed9d
+
72aed9d
+    }
72aed9d
+
72aed9d
+  /* Traverse the array from right to left and set the high and low bounds
72aed9d
+     for later use.  */
72aed9d
+  for (i = nargs - 1; i >= 0; i--)
72aed9d
+    {
72aed9d
+      struct subscript_store *index = &subscript_array[i];
72aed9d
+      struct type *index_type = TYPE_INDEX_TYPE (array_type);
72aed9d
+
72aed9d
+      switch (index->kind)
72aed9d
+	{
72aed9d
+	case SUBSCRIPT_RANGE:
72aed9d
+	  {
72aed9d
+
72aed9d
+	    /* When we hit the first range specified by the user, we must
72aed9d
+	       treat any subsequent user entry as a range.  We simply
72aed9d
+	       increment DIM_COUNT which tells us how many times we are
72aed9d
+	       calling VALUE_SLICE_1.  */
72aed9d
+	    subscript_range *range = &index->U.range;
72aed9d
+
72aed9d
+	    /* If no lower bound was provided by the user, we take the
72aed9d
+	       default boundary.  Same for the high bound.  */
72aed9d
+	    if ((range->f90_range_type & SUBARRAY_LOW_BOUND) == 0)
72aed9d
+	      range->low = TYPE_LOW_BOUND (index_type);
72aed9d
+
72aed9d
+	    if ((range->f90_range_type & SUBARRAY_HIGH_BOUND) == 0)
72aed9d
+	      range->high = TYPE_HIGH_BOUND (index_type);
72aed9d
+
72aed9d
+	    /* Both user provided low and high bound have to be inside the
72aed9d
+	       array bounds.  Throw an error if not.  */
72aed9d
+	    if (range->low < TYPE_LOW_BOUND (index_type)
72aed9d
+		|| range->low > TYPE_HIGH_BOUND (index_type)
72aed9d
+		|| range->high < TYPE_LOW_BOUND (index_type)
72aed9d
+		|| range->high > TYPE_HIGH_BOUND (index_type))
72aed9d
+	      error (_("provided bound(s) outside array bound(s)"));
72aed9d
+
72aed9d
+	    /* For a negative stride the lower boundary must be larger than the
72aed9d
+	       upper boundary.
72aed9d
+	       For a positive stride the lower boundary must be smaller than the
72aed9d
+	       upper boundary.  */
72aed9d
+	    if ((range->stride < 0 && range->low < range->high)
72aed9d
+		|| (range->stride > 0 && range->low > range->high))
72aed9d
+	      error (_("Wrong value provided for stride and boundaries"));
72aed9d
+
72aed9d
+	  }
72aed9d
+	  break;
72aed9d
+
72aed9d
+	case SUBSCRIPT_INDEX:
72aed9d
+	  break;
72aed9d
+
72aed9d
+	}
72aed9d
+
72aed9d
+       array_type = TYPE_TARGET_TYPE (array_type);
72aed9d
+    }
72aed9d
+
72aed9d
+  /* Reset ARRAY_TYPE before slicing.*/
72aed9d
+  array_type = check_typedef (value_type (new_array));
72aed9d
+
72aed9d
+  /* Traverse the array from right to left and evaluate each corresponding
72aed9d
+     user input.  VALUE_SUBSCRIPT is called for every index, until a range
72aed9d
+     expression is evaluated.  After a range expression has been evaluated,
72aed9d
+     every subsequent expression is also treated as a range.  */
72aed9d
+  for (i = nargs - 1; i >= 0; i--)
72aed9d
+    {
72aed9d
+      struct subscript_store *index = &subscript_array[i];
72aed9d
+      struct type *index_type = TYPE_INDEX_TYPE (array_type);
72aed9d
+
72aed9d
+      switch (index->kind)
72aed9d
+	{
72aed9d
+	case SUBSCRIPT_RANGE:
72aed9d
+	  {
72aed9d
+
72aed9d
+	    /* When we hit the first range specified by the user, we must
72aed9d
+	       treat any subsequent user entry as a range.  We simply
72aed9d
+	       increment DIM_COUNT which tells us how many times we are
72aed9d
+	       calling VALUE_SLICE_1.  */
72aed9d
+	    subscript_range *range = &index->U.range;
72aed9d
+
72aed9d
+	    /* DIM_COUNT counts every user argument that is treated as a range.
72aed9d
+	       This is necessary for expressions like 'print array(7, 8:9).
72aed9d
+	       Here the first argument is a literal, but must be treated as a
72aed9d
+	       range argument to allow the correct output representation.  */
72aed9d
+	    dim_count++;
72aed9d
+
72aed9d
+	    new_array
72aed9d
+	      = value_slice_1 (new_array, range->low,
72aed9d
+			       range->high - range->low + 1,
72aed9d
+			       range->stride, dim_count);
72aed9d
+	  }
72aed9d
+	  break;
72aed9d
+
72aed9d
+	case SUBSCRIPT_INDEX:
72aed9d
+	  {
72aed9d
+	    /* DIM_COUNT only stays '0' when no range argument was processed
72aed9d
+	       before, starting from the last dimension.  This way we can
72aed9d
+	       reduce the number of dimensions from the result array.
72aed9d
+	       However, if a range has been processed before an index, we
72aed9d
+	       treat the index like a range with equal low- and high bounds
72aed9d
+	       to get the value offset right.  */
72aed9d
+	    if (dim_count == 0)
72aed9d
+	      new_array
72aed9d
+	        = value_subscripted_rvalue (new_array, index->U.number,
72aed9d
+					    f77_get_lowerbound (value_type
72aed9d
+								  (new_array)));
72aed9d
+	    else
72aed9d
+	      {
72aed9d
+		dim_count++;
72aed9d
+
72aed9d
+		/* We might end up here, because we have to treat the provided
72aed9d
+		   index like a range. But now VALUE_SUBSCRIPTED_RVALUE
72aed9d
+		   cannot do the range checks for us. So we have to make sure
72aed9d
+		   ourselves that the user provided index is inside the
72aed9d
+		   array bounds.  Throw an error if not.  */
72aed9d
+		if (index->U.number < TYPE_LOW_BOUND (index_type)
72aed9d
+		    && index->U.number > TYPE_HIGH_BOUND (index_type))
72aed9d
+		  error (_("provided bound(s) outside array bound(s)"));
72aed9d
+
72aed9d
+		if (index->U.number > TYPE_LOW_BOUND (index_type)
72aed9d
+		    && index->U.number > TYPE_HIGH_BOUND (index_type))
72aed9d
+		  error (_("provided bound(s) outside array bound(s)"));
72aed9d
+
72aed9d
+		new_array = value_slice_1 (new_array,
72aed9d
+					   index->U.number,
72aed9d
+					   1, /* COUNT is '1' element  */
72aed9d
+					   1, /* STRIDE set to '1'  */
72aed9d
+					   dim_count);
72aed9d
+	      }
72aed9d
+
72aed9d
+	  }
72aed9d
+	  break;
72aed9d
+	}
72aed9d
+      array_type = TYPE_TARGET_TYPE (array_type);
72aed9d
+    }
72aed9d
+
72aed9d
+  /* With DIM_COUNT > 1 we currently have a one dimensional array, but expect
72aed9d
+     an array of arrays, depending on how many ranges have been provided by
72aed9d
+     the user.  So we need to rebuild the array dimensions for printing it
72aed9d
+     correctly.
72aed9d
+     Starting from right to left in the user input, after we hit the first
72aed9d
+     range argument every subsequent argument is also treated as a range.
72aed9d
+     E.g.:
72aed9d
+     "p ary(3, 7, 2:15)" in Fortran has only 1 dimension, but we calculated 3
72aed9d
+     ranges.
72aed9d
+     "p ary(3, 7:12, 4)" in Fortran has only 1 dimension, but we calculated 2
72aed9d
+     ranges.
72aed9d
+     "p ary(2:4, 5, 7)" in Fortran has only 1 dimension, and we calculated 1
72aed9d
+     range.  */
72aed9d
+  if (dim_count > 1)
72aed9d
+    {
72aed9d
+      struct value *v = NULL;
72aed9d
+
72aed9d
+      elt_type = TYPE_TARGET_TYPE (value_type (new_array));
72aed9d
+
72aed9d
+      /* Every SUBSCRIPT_RANGE in the user input signifies an actual range in
72aed9d
+	 the output array.  So we traverse the SUBSCRIPT_ARRAY again, looking
72aed9d
+	 for a range entry.  When we find one, we use the range info to create
72aed9d
+	 an additional range_type to set the correct bounds and dimensions for
72aed9d
+	 the output array.  In addition, we may have a stride value that is not
72aed9d
+	 '1', forcing us to adjust the number of elements in a range, according
72aed9d
+	 to the stride value.  */
72aed9d
+      for (i = 0; i < nargs; i++)
72aed9d
+	{
72aed9d
+	  struct subscript_store *index = &subscript_array[i];
72aed9d
+
72aed9d
+	  if (index->kind == SUBSCRIPT_RANGE)
72aed9d
+	    {
72aed9d
+	      struct type *range_type, *interim_array_type;
72aed9d
+
72aed9d
+	      int new_length;
72aed9d
 
72aed9d
-  return value_slice (array, low_bound, high_bound - low_bound + 1);
72aed9d
+	      /* The length of a sub-dimension with all elements between the
72aed9d
+		 bounds plus the start element itself.  It may be modified by
72aed9d
+		 a user provided stride value.  */
72aed9d
+	      new_length = index->U.range.high - index->U.range.low;
72aed9d
+
72aed9d
+	      new_length /= index->U.range.stride;
72aed9d
+
72aed9d
+	      range_type
72aed9d
+		= create_static_range_type (NULL,
72aed9d
+					    elt_type,
72aed9d
+					    index->U.range.low,
72aed9d
+					    index->U.range.low + new_length);
72aed9d
+
72aed9d
+	      interim_array_type = create_array_type (NULL,
72aed9d
+						      elt_type,
72aed9d
+						      range_type);
72aed9d
+
72aed9d
+	      TYPE_CODE (interim_array_type)
72aed9d
+		= TYPE_CODE (value_type (new_array));
72aed9d
+
72aed9d
+	      v = allocate_value (interim_array_type);
72aed9d
+
72aed9d
+	      elt_type = value_type (v);
72aed9d
+	    }
72aed9d
+
72aed9d
+	}
72aed9d
+      value_contents_copy (v, 0, new_array, 0, TYPE_LENGTH (elt_type));
72aed9d
+      return v;
72aed9d
+    }
72aed9d
+
72aed9d
+  return new_array;
72aed9d
 }
72aed9d
 
72aed9d
 
72aed9d
@@ -1810,19 +2106,8 @@ evaluate_subexp_standard (struct type *expect_type,
72aed9d
       switch (code)
72aed9d
 	{
72aed9d
 	case TYPE_CODE_ARRAY:
72aed9d
-	  if (exp->elts[*pos].opcode == OP_RANGE)
72aed9d
-	    return value_f90_subarray (arg1, exp, pos, noside);
72aed9d
-	  else
72aed9d
-	    goto multi_f77_subscript;
72aed9d
-
72aed9d
 	case TYPE_CODE_STRING:
72aed9d
-	  if (exp->elts[*pos].opcode == OP_RANGE)
72aed9d
-	    return value_f90_subarray (arg1, exp, pos, noside);
72aed9d
-	  else
72aed9d
-	    {
72aed9d
-	      arg2 = evaluate_subexp_with_coercion (exp, pos, noside);
72aed9d
-	      return value_subscript (arg1, value_as_long (arg2));
72aed9d
-	    }
72aed9d
+	  return value_f90_subarray (arg1, exp, pos, nargs, noside);
72aed9d
 
72aed9d
 	case TYPE_CODE_PTR:
72aed9d
 	case TYPE_CODE_FUNC:
72aed9d
@@ -2223,49 +2508,6 @@ evaluate_subexp_standard (struct type *expect_type,
72aed9d
 	}
72aed9d
       return (arg1);
72aed9d
 
72aed9d
-    multi_f77_subscript:
72aed9d
-      {
72aed9d
-	LONGEST subscript_array[MAX_FORTRAN_DIMS];
72aed9d
-	int ndimensions = 1, i;
72aed9d
-	struct value *array = arg1;
72aed9d
-
72aed9d
-	if (nargs > MAX_FORTRAN_DIMS)
72aed9d
-	  error (_("Too many subscripts for F77 (%d Max)"), MAX_FORTRAN_DIMS);
72aed9d
-
72aed9d
-	ndimensions = calc_f77_array_dims (type);
72aed9d
-
72aed9d
-	if (nargs != ndimensions)
72aed9d
-	  error (_("Wrong number of subscripts"));
72aed9d
-
72aed9d
-	gdb_assert (nargs > 0);
72aed9d
-
72aed9d
-	/* Now that we know we have a legal array subscript expression 
72aed9d
-	   let us actually find out where this element exists in the array.  */
72aed9d
-
72aed9d
-	/* Take array indices left to right.  */
72aed9d
-	for (i = 0; i < nargs; i++)
72aed9d
-	  {
72aed9d
-	    /* Evaluate each subscript; it must be a legal integer in F77.  */
72aed9d
-	    arg2 = evaluate_subexp_with_coercion (exp, pos, noside);
72aed9d
-
72aed9d
-	    /* Fill in the subscript array.  */
72aed9d
-
72aed9d
-	    subscript_array[i] = value_as_long (arg2);
72aed9d
-	  }
72aed9d
-
72aed9d
-	/* Internal type of array is arranged right to left.  */
72aed9d
-	for (i = nargs; i > 0; i--)
72aed9d
-	  {
72aed9d
-	    struct type *array_type = check_typedef (value_type (array));
72aed9d
-	    LONGEST index = subscript_array[i - 1];
72aed9d
-
72aed9d
-	    array = value_subscripted_rvalue (array, index,
72aed9d
-					      f77_get_lowerbound (array_type));
72aed9d
-	  }
72aed9d
-
72aed9d
-	return array;
72aed9d
-      }
72aed9d
-
72aed9d
     case BINOP_LOGICAL_AND:
72aed9d
       arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
72aed9d
       if (noside == EVAL_SKIP)
72aed9d
@@ -3123,6 +3365,9 @@ calc_f77_array_dims (struct type *array_type)
72aed9d
   int ndimen = 1;
72aed9d
   struct type *tmp_type;
72aed9d
 
72aed9d
+  if (TYPE_CODE (array_type) == TYPE_CODE_STRING)
72aed9d
+    return 1;
72aed9d
+
72aed9d
   if ((TYPE_CODE (array_type) != TYPE_CODE_ARRAY))
72aed9d
     error (_("Can't get dimensions for a non-array type"));
72aed9d
 
72aed9d
diff --git a/gdb/expprint.c b/gdb/expprint.c
72aed9d
index c37ecb0..214d58e 100644
72aed9d
--- a/gdb/expprint.c
72aed9d
+++ b/gdb/expprint.c
72aed9d
@@ -568,12 +568,10 @@ print_subexp_standard (struct expression *exp, int *pos,
72aed9d
 	*pos += 2;
72aed9d
 
72aed9d
 	fputs_filtered ("RANGE(", stream);
72aed9d
-	if (range_type == HIGH_BOUND_DEFAULT
72aed9d
-	    || range_type == NONE_BOUND_DEFAULT)
72aed9d
+	if ((range_type & SUBARRAY_LOW_BOUND) == SUBARRAY_LOW_BOUND)
72aed9d
 	  print_subexp (exp, pos, stream, PREC_ABOVE_COMMA);
72aed9d
 	fputs_filtered ("..", stream);
72aed9d
-	if (range_type == LOW_BOUND_DEFAULT
72aed9d
-	    || range_type == NONE_BOUND_DEFAULT)
72aed9d
+	if ((range_type & SUBARRAY_HIGH_BOUND) == SUBARRAY_HIGH_BOUND)
72aed9d
 	  print_subexp (exp, pos, stream, PREC_ABOVE_COMMA);
72aed9d
 	fputs_filtered (")", stream);
72aed9d
 	return;
72aed9d
@@ -1055,16 +1053,16 @@ dump_subexp_body_standard (struct expression *exp,
72aed9d
 
72aed9d
 	switch (range_type)
72aed9d
 	  {
72aed9d
-	  case BOTH_BOUND_DEFAULT:
72aed9d
+	  case SUBARRAY_NONE_BOUND:
72aed9d
 	    fputs_filtered ("Range '..'", stream);
72aed9d
 	    break;
72aed9d
-	  case LOW_BOUND_DEFAULT:
72aed9d
+	  case SUBARRAY_HIGH_BOUND:
72aed9d
 	    fputs_filtered ("Range '..EXP'", stream);
72aed9d
 	    break;
72aed9d
-	  case HIGH_BOUND_DEFAULT:
72aed9d
+	  case SUBARRAY_LOW_BOUND:
72aed9d
 	    fputs_filtered ("Range 'EXP..'", stream);
72aed9d
 	    break;
72aed9d
-	  case NONE_BOUND_DEFAULT:
72aed9d
+	  case (SUBARRAY_LOW_BOUND | SUBARRAY_HIGH_BOUND):
72aed9d
 	    fputs_filtered ("Range 'EXP..EXP'", stream);
72aed9d
 	    break;
72aed9d
 	  default:
72aed9d
@@ -1072,11 +1070,9 @@ dump_subexp_body_standard (struct expression *exp,
72aed9d
 	    break;
72aed9d
 	  }
72aed9d
 
72aed9d
-	if (range_type == HIGH_BOUND_DEFAULT
72aed9d
-	    || range_type == NONE_BOUND_DEFAULT)
72aed9d
+	if ((range_type & SUBARRAY_LOW_BOUND) == SUBARRAY_LOW_BOUND)
72aed9d
 	  elt = dump_subexp (exp, stream, elt);
72aed9d
-	if (range_type == LOW_BOUND_DEFAULT
72aed9d
-	    || range_type == NONE_BOUND_DEFAULT)
72aed9d
+	if ((range_type & SUBARRAY_HIGH_BOUND) == SUBARRAY_HIGH_BOUND)
72aed9d
 	  elt = dump_subexp (exp, stream, elt);
72aed9d
       }
72aed9d
       break;
72aed9d
diff --git a/gdb/expression.h b/gdb/expression.h
72aed9d
index 4952d84..34ca54b 100644
72aed9d
--- a/gdb/expression.h
72aed9d
+++ b/gdb/expression.h
72aed9d
@@ -152,17 +152,17 @@ extern void dump_raw_expression (struct expression *,
72aed9d
 				 struct ui_file *, char *);
72aed9d
 extern void dump_prefix_expression (struct expression *, struct ui_file *);
72aed9d
 
72aed9d
-/* In an OP_RANGE expression, either bound could be empty, indicating
72aed9d
-   that its value is by default that of the corresponding bound of the
72aed9d
-   array or string.  So we have four sorts of subrange.  This
72aed9d
-   enumeration type is to identify this.  */
72aed9d
-   
72aed9d
+/* In an OP_RANGE expression, either bound can be provided by the user, or not.
72aed9d
+   In addition to this, the user can also specify a stride value to indicated
72aed9d
+   only certain elements of the array.  This enumeration type is to identify
72aed9d
+   this.  */
72aed9d
+
72aed9d
 enum range_type
72aed9d
   {
72aed9d
-    BOTH_BOUND_DEFAULT,		/* "(:)"  */
72aed9d
-    LOW_BOUND_DEFAULT,		/* "(:high)"  */
72aed9d
-    HIGH_BOUND_DEFAULT,		/* "(low:)"  */
72aed9d
-    NONE_BOUND_DEFAULT		/* "(low:high)"  */
72aed9d
+    SUBARRAY_NONE_BOUND = 0x0,		/* "( : )"  */
72aed9d
+    SUBARRAY_LOW_BOUND = 0x1,		/* "(low:)"  */
72aed9d
+    SUBARRAY_HIGH_BOUND = 0x2,		/* "(:high)"  */
72aed9d
+    SUBARRAY_STRIDE = 0x4		/* "(::stride)"  */
72aed9d
   };
72aed9d
 
72aed9d
 #endif /* !defined (EXPRESSION_H) */
72aed9d
diff --git a/gdb/f-exp.y b/gdb/f-exp.y
72aed9d
index e3148a3..71f1823 100644
72aed9d
--- a/gdb/f-exp.y
72aed9d
+++ b/gdb/f-exp.y
72aed9d
@@ -253,31 +253,63 @@ arglist :	subrange
72aed9d
    
72aed9d
 arglist	:	arglist ',' exp   %prec ABOVE_COMMA
72aed9d
 			{ arglist_len++; }
72aed9d
+	|	arglist ',' subrange	%prec ABOVE_COMMA
72aed9d
+			{ arglist_len++; }
72aed9d
 	;
72aed9d
 
72aed9d
 /* There are four sorts of subrange types in F90.  */
72aed9d
 
72aed9d
 subrange:	exp ':' exp	%prec ABOVE_COMMA
72aed9d
-			{ write_exp_elt_opcode (pstate, OP_RANGE); 
72aed9d
-			  write_exp_elt_longcst (pstate, NONE_BOUND_DEFAULT);
72aed9d
+			{ write_exp_elt_opcode (pstate, OP_RANGE);
72aed9d
+			  write_exp_elt_longcst (pstate,
72aed9d
+						 SUBARRAY_LOW_BOUND | SUBARRAY_HIGH_BOUND);
72aed9d
 			  write_exp_elt_opcode (pstate, OP_RANGE); }
72aed9d
 	;
72aed9d
 
72aed9d
 subrange:	exp ':'	%prec ABOVE_COMMA
72aed9d
 			{ write_exp_elt_opcode (pstate, OP_RANGE);
72aed9d
-			  write_exp_elt_longcst (pstate, HIGH_BOUND_DEFAULT);
72aed9d
+			  write_exp_elt_longcst (pstate, SUBARRAY_LOW_BOUND);
72aed9d
 			  write_exp_elt_opcode (pstate, OP_RANGE); }
72aed9d
 	;
72aed9d
 
72aed9d
 subrange:	':' exp	%prec ABOVE_COMMA
72aed9d
 			{ write_exp_elt_opcode (pstate, OP_RANGE);
72aed9d
-			  write_exp_elt_longcst (pstate, LOW_BOUND_DEFAULT);
72aed9d
+			  write_exp_elt_longcst (pstate, SUBARRAY_HIGH_BOUND);
72aed9d
 			  write_exp_elt_opcode (pstate, OP_RANGE); }
72aed9d
 	;
72aed9d
 
72aed9d
 subrange:	':'	%prec ABOVE_COMMA
72aed9d
 			{ write_exp_elt_opcode (pstate, OP_RANGE);
72aed9d
-			  write_exp_elt_longcst (pstate, BOTH_BOUND_DEFAULT);
72aed9d
+			  write_exp_elt_longcst (pstate, SUBARRAY_NONE_BOUND);
72aed9d
+			  write_exp_elt_opcode (pstate, OP_RANGE); }
72aed9d
+	;
72aed9d
+
72aed9d
+/* Each subrange type can have a stride argument.  */
72aed9d
+subrange:	exp ':' exp ':' exp %prec ABOVE_COMMA
72aed9d
+			{ write_exp_elt_opcode (pstate, OP_RANGE);
72aed9d
+			  write_exp_elt_longcst (pstate, SUBARRAY_LOW_BOUND
72aed9d
+						 | SUBARRAY_HIGH_BOUND
72aed9d
+						 | SUBARRAY_STRIDE);
72aed9d
+			  write_exp_elt_opcode (pstate, OP_RANGE); }
72aed9d
+	;
72aed9d
+
72aed9d
+subrange:	exp ':' ':' exp %prec ABOVE_COMMA
72aed9d
+			{ write_exp_elt_opcode (pstate, OP_RANGE);
72aed9d
+			  write_exp_elt_longcst (pstate, SUBARRAY_LOW_BOUND
72aed9d
+						 | SUBARRAY_STRIDE);
72aed9d
+			  write_exp_elt_opcode (pstate, OP_RANGE); }
72aed9d
+	;
72aed9d
+
72aed9d
+subrange:	':' exp ':' exp %prec ABOVE_COMMA
72aed9d
+			{ write_exp_elt_opcode (pstate, OP_RANGE);
72aed9d
+			  write_exp_elt_longcst (pstate, SUBARRAY_HIGH_BOUND
72aed9d
+						 | SUBARRAY_STRIDE);
72aed9d
+			  write_exp_elt_opcode (pstate, OP_RANGE); }
72aed9d
+	;
72aed9d
+
72aed9d
+subrange:	':' ':' exp %prec ABOVE_COMMA
72aed9d
+			{ write_exp_elt_opcode (pstate, OP_RANGE);
72aed9d
+			  write_exp_elt_longcst (pstate, SUBARRAY_STRIDE);
72aed9d
 			  write_exp_elt_opcode (pstate, OP_RANGE); }
72aed9d
 	;
72aed9d
 
72aed9d
diff --git a/gdb/f-valprint.c b/gdb/f-valprint.c
72aed9d
index 08215e2..e6eca6a 100644
72aed9d
--- a/gdb/f-valprint.c
72aed9d
+++ b/gdb/f-valprint.c
72aed9d
@@ -121,8 +121,14 @@ f77_print_array_1 (int nss, int ndimensions, struct type *type,
72aed9d
 
72aed9d
   if (nss != ndimensions)
72aed9d
     {
72aed9d
-      size_t dim_size = TYPE_LENGTH (TYPE_TARGET_TYPE (type));
72aed9d
+      size_t dim_size;
72aed9d
       size_t offs = 0;
72aed9d
+      LONGEST byte_stride = abs (TYPE_BYTE_STRIDE (range_type));
72aed9d
+
72aed9d
+      if (byte_stride)
72aed9d
+        dim_size = byte_stride;
72aed9d
+      else
72aed9d
+        dim_size = TYPE_LENGTH (TYPE_TARGET_TYPE (type));
72aed9d
 
72aed9d
       for (i = lowerbound;
72aed9d
 	   (i < upperbound + 1 && (*elts) < options->print_max);
72aed9d
diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c
d258670
index ec5c17a..eb83791 100644
72aed9d
--- a/gdb/gdbtypes.c
72aed9d
+++ b/gdb/gdbtypes.c
72aed9d
@@ -836,7 +836,8 @@ allocate_stub_method (struct type *type)
72aed9d
 struct type *
72aed9d
 create_range_type (struct type *result_type, struct type *index_type,
72aed9d
 		   const struct dynamic_prop *low_bound,
72aed9d
-		   const struct dynamic_prop *high_bound)
72aed9d
+		   const struct dynamic_prop *high_bound,
72aed9d
+		   const struct dynamic_prop *stride)
72aed9d
 {
72aed9d
   if (result_type == NULL)
72aed9d
     result_type = alloc_type_copy (index_type);
72aed9d
@@ -851,6 +852,7 @@ create_range_type (struct type *result_type, struct type *index_type,
72aed9d
     TYPE_ZALLOC (result_type, sizeof (struct range_bounds));
72aed9d
   TYPE_RANGE_DATA (result_type)->low = *low_bound;
72aed9d
   TYPE_RANGE_DATA (result_type)->high = *high_bound;
72aed9d
+  TYPE_RANGE_DATA (result_type)->stride = *stride;
72aed9d
 
72aed9d
   if (low_bound->kind == PROP_CONST && low_bound->data.const_val >= 0)
72aed9d
     TYPE_UNSIGNED (result_type) = 1;
72aed9d
@@ -879,7 +881,7 @@ struct type *
72aed9d
 create_static_range_type (struct type *result_type, struct type *index_type,
72aed9d
 			  LONGEST low_bound, LONGEST high_bound)
72aed9d
 {
72aed9d
-  struct dynamic_prop low, high;
72aed9d
+  struct dynamic_prop low, high, stride;
72aed9d
 
72aed9d
   low.kind = PROP_CONST;
72aed9d
   low.data.const_val = low_bound;
72aed9d
@@ -887,7 +889,11 @@ create_static_range_type (struct type *result_type, struct type *index_type,
72aed9d
   high.kind = PROP_CONST;
72aed9d
   high.data.const_val = high_bound;
72aed9d
 
72aed9d
-  result_type = create_range_type (result_type, index_type, &low, &high);
72aed9d
+  stride.kind = PROP_CONST;
72aed9d
+  stride.data.const_val = 0;
72aed9d
+
72aed9d
+  result_type = create_range_type (result_type, index_type,
72aed9d
+                                   &low, &high, &stride);
72aed9d
 
72aed9d
   return result_type;
72aed9d
 }
72aed9d
@@ -1084,16 +1090,20 @@ create_array_type_with_stride (struct type *result_type,
72aed9d
       && (!type_not_associated (result_type)
72aed9d
 	  && !type_not_allocated (result_type)))
72aed9d
     {
72aed9d
-      LONGEST low_bound, high_bound;
72aed9d
+      LONGEST low_bound, high_bound, byte_stride;
72aed9d
 
72aed9d
       if (get_discrete_bounds (range_type, &low_bound, &high_bound) < 0)
72aed9d
 	low_bound = high_bound = 0;
72aed9d
       element_type = check_typedef (element_type);
72aed9d
+      byte_stride = abs (TYPE_BYTE_STRIDE (range_type));
72aed9d
+
72aed9d
       /* Be careful when setting the array length.  Ada arrays can be
72aed9d
 	 empty arrays with the high_bound being smaller than the low_bound.
72aed9d
 	 In such cases, the array length should be zero.  */
72aed9d
       if (high_bound < low_bound)
72aed9d
 	TYPE_LENGTH (result_type) = 0;
72aed9d
+      else if (byte_stride > 0)
72aed9d
+	TYPE_LENGTH (result_type) = byte_stride * (high_bound - low_bound + 1);
72aed9d
       else if (bit_stride > 0)
72aed9d
 	TYPE_LENGTH (result_type) =
72aed9d
 	  (bit_stride * (high_bound - low_bound + 1) + 7) / 8;
d258670
@@ -1888,12 +1898,12 @@ resolve_dynamic_range (struct type *dyn_range_type,
72aed9d
   CORE_ADDR value;
72aed9d
   struct type *static_range_type, *static_target_type;
72aed9d
   const struct dynamic_prop *prop;
72aed9d
-  struct dynamic_prop low_bound, high_bound;
72aed9d
+  struct dynamic_prop low_bound, high_bound, stride;
72aed9d
 
72aed9d
   gdb_assert (TYPE_CODE (dyn_range_type) == TYPE_CODE_RANGE);
72aed9d
 
d258670
   prop = &TYPE_RANGE_DATA (dyn_range_type)->low;
d258670
-  if (dwarf2_evaluate_property (prop, NULL, addr_stack, &value))
d258670
+  if (dwarf2_evaluate_property_signed (prop, NULL, addr_stack, &value, 1))
d258670
     {
d258670
       low_bound.kind = PROP_CONST;
d258670
       low_bound.data.const_val = value;
d258670
@@ -1905,7 +1915,7 @@ resolve_dynamic_range (struct type *dyn_range_type,
d258670
     }
d258670
 
d258670
   prop = &TYPE_RANGE_DATA (dyn_range_type)->high;
d258670
-  if (dwarf2_evaluate_property (prop, NULL, addr_stack, &value))
d258670
+  if (dwarf2_evaluate_property_signed (prop, NULL, addr_stack, &value, 1))
d258670
     {
d258670
       high_bound.kind = PROP_CONST;
d258670
       high_bound.data.const_val = value;
d258670
@@ -1920,12 +1930,20 @@ resolve_dynamic_range (struct type *dyn_range_type,
72aed9d
       high_bound.data.const_val = 0;
72aed9d
     }
d258670
 
72aed9d
+  prop = &TYPE_RANGE_DATA (dyn_range_type)->stride;
d258670
+  if (dwarf2_evaluate_property_signed (prop, NULL, addr_stack, &value, 1))
72aed9d
+    {
72aed9d
+      stride.kind = PROP_CONST;
72aed9d
+      stride.data.const_val = value;
72aed9d
+    }
d258670
+
72aed9d
   static_target_type
72aed9d
     = resolve_dynamic_type_internal (TYPE_TARGET_TYPE (dyn_range_type),
72aed9d
 				     addr_stack, 0);
72aed9d
   static_range_type = create_range_type (copy_type (dyn_range_type),
72aed9d
 					 static_target_type,
72aed9d
-					 &low_bound, &high_bound);
72aed9d
+					 &low_bound, &high_bound, &stride);
72aed9d
+
72aed9d
   TYPE_RANGE_DATA (static_range_type)->flag_bound_evaluated = 1;
72aed9d
   return static_range_type;
72aed9d
 }
72aed9d
diff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h
d258670
index 2dda074..bcc9200 100644
72aed9d
--- a/gdb/gdbtypes.h
72aed9d
+++ b/gdb/gdbtypes.h
72aed9d
@@ -577,6 +577,10 @@ struct range_bounds
72aed9d
 
72aed9d
   struct dynamic_prop high;
72aed9d
 
72aed9d
+  /* * Stride of range.  */
72aed9d
+
72aed9d
+  struct dynamic_prop stride;
72aed9d
+
72aed9d
   /* True if HIGH range bound contains the number of elements in the
72aed9d
      subrange. This affects how the final hight bound is computed.  */
72aed9d
 
d258670
@@ -739,7 +743,6 @@ struct main_type
d258670
     /* * Union member used for range types.  */
72aed9d
 
72aed9d
     struct range_bounds *bounds;
d258670
-
72aed9d
   } flds_bnds;
72aed9d
 
72aed9d
   /* * Slot to point to additional language-specific fields of this
d258670
@@ -1255,6 +1258,15 @@ extern void allocate_gnat_aux_type (struct type *);
72aed9d
   TYPE_RANGE_DATA(range_type)->high.kind
72aed9d
 #define TYPE_LOW_BOUND_KIND(range_type) \
72aed9d
   TYPE_RANGE_DATA(range_type)->low.kind
72aed9d
+#define TYPE_BYTE_STRIDE(range_type) \
72aed9d
+  TYPE_RANGE_DATA(range_type)->stride.data.const_val
72aed9d
+#define TYPE_BYTE_STRIDE_BLOCK(range_type) \
72aed9d
+  TYPE_RANGE_DATA(range_type)->stride.data.locexpr
72aed9d
+#define TYPE_BYTE_STRIDE_LOCLIST(range_type) \
72aed9d
+  TYPE_RANGE_DATA(range_type)->stride.data.loclist
72aed9d
+#define TYPE_BYTE_STRIDE_KIND(range_type) \
72aed9d
+  TYPE_RANGE_DATA(range_type)->stride.kind
72aed9d
+
72aed9d
 
72aed9d
 /* Property accessors for the type data location.  */
72aed9d
 #define TYPE_DATA_LOCATION(thistype) \
d258670
@@ -1289,6 +1301,9 @@ extern void allocate_gnat_aux_type (struct type *);
72aed9d
    TYPE_HIGH_BOUND_UNDEFINED(TYPE_INDEX_TYPE(arraytype))
72aed9d
 #define TYPE_ARRAY_LOWER_BOUND_IS_UNDEFINED(arraytype) \
72aed9d
    TYPE_LOW_BOUND_UNDEFINED(TYPE_INDEX_TYPE(arraytype))
72aed9d
+#define TYPE_ARRAY_STRIDE_IS_UNDEFINED(arraytype) \
72aed9d
+   (TYPE_BYTE_STRIDE(TYPE_INDEX_TYPE(arraytype)) == 0)
72aed9d
+
72aed9d
 
72aed9d
 #define TYPE_ARRAY_UPPER_BOUND_VALUE(arraytype) \
72aed9d
    (TYPE_HIGH_BOUND(TYPE_INDEX_TYPE((arraytype))))
d258670
@@ -1783,6 +1798,7 @@ extern struct type *create_array_type_with_stride
72aed9d
 
72aed9d
 extern struct type *create_range_type (struct type *, struct type *,
72aed9d
 				       const struct dynamic_prop *,
72aed9d
+				       const struct dynamic_prop *,
72aed9d
 				       const struct dynamic_prop *);
72aed9d
 
72aed9d
 extern struct type *create_array_type (struct type *, struct type *,
72aed9d
diff --git a/gdb/parse.c b/gdb/parse.c
72aed9d
index 2b00708..992af87 100644
72aed9d
--- a/gdb/parse.c
72aed9d
+++ b/gdb/parse.c
72aed9d
@@ -1006,22 +1006,20 @@ operator_length_standard (const struct expression *expr, int endpos,
72aed9d
 
72aed9d
     case OP_RANGE:
72aed9d
       oplen = 3;
72aed9d
+      args = 0;
72aed9d
       range_type = (enum range_type)
72aed9d
 	longest_to_int (expr->elts[endpos - 2].longconst);
72aed9d
 
72aed9d
-      switch (range_type)
72aed9d
-	{
72aed9d
-	case LOW_BOUND_DEFAULT:
72aed9d
-	case HIGH_BOUND_DEFAULT:
72aed9d
-	  args = 1;
72aed9d
-	  break;
72aed9d
-	case BOTH_BOUND_DEFAULT:
72aed9d
-	  args = 0;
72aed9d
-	  break;
72aed9d
-	case NONE_BOUND_DEFAULT:
72aed9d
-	  args = 2;
72aed9d
-	  break;
72aed9d
-	}
72aed9d
+      /* Increment the argument counter for each argument
72aed9d
+	 provided by the user.  */
72aed9d
+      if ((range_type & SUBARRAY_LOW_BOUND) == SUBARRAY_LOW_BOUND)
72aed9d
+	args++;
72aed9d
+
72aed9d
+      if ((range_type & SUBARRAY_HIGH_BOUND) == SUBARRAY_HIGH_BOUND)
72aed9d
+	args++;
72aed9d
+
72aed9d
+      if ((range_type & SUBARRAY_STRIDE) == SUBARRAY_STRIDE)
72aed9d
+	args++;
72aed9d
 
72aed9d
       break;
72aed9d
 
72aed9d
diff --git a/gdb/rust-exp.y b/gdb/rust-exp.y
72aed9d
index aeb6058..b1b9633 100644
72aed9d
--- a/gdb/rust-exp.y
72aed9d
+++ b/gdb/rust-exp.y
72aed9d
@@ -2429,23 +2429,17 @@ convert_ast_to_expression (struct parser_state *state,
72aed9d
 
72aed9d
     case OP_RANGE:
72aed9d
       {
72aed9d
-	enum range_type kind = BOTH_BOUND_DEFAULT;
72aed9d
+	enum range_type kind = SUBARRAY_NONE_BOUND;
72aed9d
 
72aed9d
 	if (operation->left.op != NULL)
72aed9d
 	  {
72aed9d
 	    convert_ast_to_expression (state, operation->left.op, top);
72aed9d
-	    kind = HIGH_BOUND_DEFAULT;
72aed9d
+	    kind = SUBARRAY_LOW_BOUND;
72aed9d
 	  }
72aed9d
 	if (operation->right.op != NULL)
72aed9d
 	  {
72aed9d
 	    convert_ast_to_expression (state, operation->right.op, top);
72aed9d
-	    if (kind == BOTH_BOUND_DEFAULT)
72aed9d
-	      kind = LOW_BOUND_DEFAULT;
72aed9d
-	    else
72aed9d
-	      {
72aed9d
-		gdb_assert (kind == HIGH_BOUND_DEFAULT);
72aed9d
-		kind = NONE_BOUND_DEFAULT;
72aed9d
-	      }
72aed9d
+	    kind = (range_type) (kind | SUBARRAY_HIGH_BOUND);
72aed9d
 	  }
72aed9d
 	write_exp_elt_opcode (state, OP_RANGE);
72aed9d
 	write_exp_elt_longcst (state, kind);
72aed9d
diff --git a/gdb/rust-lang.c b/gdb/rust-lang.c
72aed9d
index 17b20c6..295002f 100644
72aed9d
--- a/gdb/rust-lang.c
72aed9d
+++ b/gdb/rust-lang.c
72aed9d
@@ -1241,9 +1241,9 @@ rust_range (struct expression *exp, int *pos, enum noside noside)
72aed9d
   kind = (enum range_type) longest_to_int (exp->elts[*pos + 1].longconst);
72aed9d
   *pos += 3;
72aed9d
 
72aed9d
-  if (kind == HIGH_BOUND_DEFAULT || kind == NONE_BOUND_DEFAULT)
72aed9d
+  if ((kind & SUBARRAY_LOW_BOUND) == SUBARRAY_LOW_BOUND)
72aed9d
     low = evaluate_subexp (NULL_TYPE, exp, pos, noside);
72aed9d
-  if (kind == LOW_BOUND_DEFAULT || kind == NONE_BOUND_DEFAULT)
72aed9d
+  if ((kind & SUBARRAY_HIGH_BOUND) == SUBARRAY_HIGH_BOUND)
72aed9d
     high = evaluate_subexp (NULL_TYPE, exp, pos, noside);
72aed9d
 
72aed9d
   if (noside == EVAL_SKIP)
72aed9d
@@ -1332,7 +1332,7 @@ rust_compute_range (struct type *type, struct value *range,
72aed9d
 
72aed9d
   *low = 0;
72aed9d
   *high = 0;
72aed9d
-  *kind = BOTH_BOUND_DEFAULT;
72aed9d
+  *kind = SUBARRAY_NONE_BOUND;
72aed9d
 
72aed9d
   if (TYPE_NFIELDS (type) == 0)
72aed9d
     return;
72aed9d
@@ -1340,15 +1340,14 @@ rust_compute_range (struct type *type, struct value *range,
72aed9d
   i = 0;
72aed9d
   if (strcmp (TYPE_FIELD_NAME (type, 0), "start") == 0)
72aed9d
     {
72aed9d
-      *kind = HIGH_BOUND_DEFAULT;
72aed9d
+      *kind = SUBARRAY_LOW_BOUND;
72aed9d
       *low = value_as_long (value_field (range, 0));
72aed9d
       ++i;
72aed9d
     }
72aed9d
   if (TYPE_NFIELDS (type) > i
72aed9d
       && strcmp (TYPE_FIELD_NAME (type, i), "end") == 0)
72aed9d
     {
72aed9d
-      *kind = (*kind == BOTH_BOUND_DEFAULT
72aed9d
-	       ? LOW_BOUND_DEFAULT : NONE_BOUND_DEFAULT);
72aed9d
+      *kind = (range_type) (*kind | SUBARRAY_HIGH_BOUND);
72aed9d
       *high = value_as_long (value_field (range, i));
72aed9d
     }
72aed9d
 }
72aed9d
@@ -1363,7 +1362,7 @@ rust_subscript (struct expression *exp, int *pos, enum noside noside,
72aed9d
   struct type *rhstype;
72aed9d
   LONGEST low, high_bound;
72aed9d
   /* Initialized to appease the compiler.  */
72aed9d
-  enum range_type kind = BOTH_BOUND_DEFAULT;
72aed9d
+  enum range_type kind = SUBARRAY_NONE_BOUND;
72aed9d
   LONGEST high = 0;
72aed9d
   int want_slice = 0;
72aed9d
 
72aed9d
@@ -1425,7 +1424,7 @@ rust_subscript (struct expression *exp, int *pos, enum noside noside,
72aed9d
 	error (_("Cannot subscript non-array type"));
72aed9d
 
72aed9d
       if (want_slice
72aed9d
-	  && (kind == BOTH_BOUND_DEFAULT || kind == LOW_BOUND_DEFAULT))
72aed9d
+	  && ((kind & SUBARRAY_LOW_BOUND) != SUBARRAY_LOW_BOUND))
72aed9d
 	low = low_bound;
72aed9d
       if (low < 0)
72aed9d
 	error (_("Index less than zero"));
72aed9d
@@ -1443,7 +1442,7 @@ rust_subscript (struct expression *exp, int *pos, enum noside noside,
72aed9d
 	  CORE_ADDR addr;
72aed9d
 	  struct value *addrval, *tem;
72aed9d
 
72aed9d
-	  if (kind == BOTH_BOUND_DEFAULT || kind == HIGH_BOUND_DEFAULT)
72aed9d
+	  if ((kind & SUBARRAY_HIGH_BOUND) != SUBARRAY_HIGH_BOUND)
72aed9d
 	    high = high_bound;
72aed9d
 	  if (high < 0)
72aed9d
 	    error (_("High index less than zero"));
72aed9d
diff --git a/gdb/testsuite/gdb.fortran/static-arrays.exp b/gdb/testsuite/gdb.fortran/static-arrays.exp
72aed9d
new file mode 100644
72aed9d
index 0000000..cc9ecc0
72aed9d
--- /dev/null
72aed9d
+++ b/gdb/testsuite/gdb.fortran/static-arrays.exp
72aed9d
@@ -0,0 +1,421 @@
72aed9d
+# Copyright 2015 Free Software Foundation, Inc.
72aed9d
+#
72aed9d
+# Contributed by Intel Corp. <christoph.t.weinmann@intel.com>
72aed9d
+#
72aed9d
+# This program is free software; you can redistribute it and/or modify
72aed9d
+# it under the terms of the GNU General Public License as published by
72aed9d
+# the Free Software Foundation; either version 3 of the License, or
72aed9d
+# (at your option) any later version.
72aed9d
+#
72aed9d
+# This program is distributed in the hope that it will be useful,
72aed9d
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
72aed9d
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
72aed9d
+# GNU General Public License for more details.
72aed9d
+#
72aed9d
+# You should have received a copy of the GNU General Public License
72aed9d
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
72aed9d
+
72aed9d
+standard_testfile static-arrays.f90
72aed9d
+
72aed9d
+if { [prepare_for_testing $testfile.exp $testfile $srcfile {debug f90}] } {
72aed9d
+    return -1
72aed9d
+}
72aed9d
+
72aed9d
+if ![runto MAIN__] then {
72aed9d
+    perror "couldn't run to breakpoint MAIN__"
72aed9d
+    continue
72aed9d
+}
72aed9d
+
72aed9d
+gdb_breakpoint [gdb_get_line_number "BP1"]
72aed9d
+gdb_continue_to_breakpoint "BP1" ".*BP1.*"
72aed9d
+
72aed9d
+# Tests subarrays of one dimensional arrays with subrange variations
72aed9d
+gdb_test "print ar1" "\\$\[0-9\]+ = \\(1, 2, 3, 4, 5, 6, 7, 8, 9\\)" \
72aed9d
+		"print ar1."
72aed9d
+gdb_test "print ar1\(4:7\)" "\\$\[0-9\]+ = \\(4, 5, 6, 7\\)" \
72aed9d
+		"print ar1\(4:7\)"
72aed9d
+gdb_test "print ar1\(8:\)" "\\$\[0-9\]+ = \\(8, 9\\).*" \
72aed9d
+		"print ar1\(8:\)"
72aed9d
+gdb_test "print ar1\(:3\)" "\\$\[0-9\]+ = \\(1, 2, 3\\).*" \
72aed9d
+		"print ar1\(:3\)"
72aed9d
+gdb_test "print ar1\(:\)" "\\$\[0-9\]+ = \\(1, 2, 3, 4, 5, 6, 7, 8, 9\\)" \
72aed9d
+		"print ar1\(:\)"
72aed9d
+
72aed9d
+# Check assignment
72aed9d
+gdb_test_no_output "set \$my_ary = ar1\(3:8\)"
72aed9d
+gdb_test "print \$my_ary" \
72aed9d
+		"\\$\[0-9\]+ = \\(3, 4, 5, 6, 7, 8\\)" \
72aed9d
+		"Assignment of subarray to variable"
72aed9d
+gdb_test_no_output "set ar1\(5\) = 42"
72aed9d
+		gdb_test "print ar1\(3:8\)" \
72aed9d
+		"\\$\[0-9\]+ = \\(3, 4, 42, 6, 7, 8\\)" \
72aed9d
+		"print ar1\(3:8\) after assignment"
72aed9d
+gdb_test "print \$my_ary" \
72aed9d
+		"\\$\[0-9\]+ = \\(3, 4, 5, 6, 7, 8\\)" \
72aed9d
+		"Assignment of subarray to variable after original array changed"
72aed9d
+
72aed9d
+# Test for subarrays of one dimensional arrays with literals
72aed9d
+		gdb_test "print ar1\(3\)" "\\$\[0-9\]+ = 3" \
72aed9d
+		"print ar1\(3\)"
72aed9d
+
72aed9d
+# Tests for subranges of 2 dimensional arrays with subrange variations
72aed9d
+gdb_test "print ar2\(2:3, 3:4\)" \
72aed9d
+		"\\$\[0-9\]+ = \\(\\( 23, 33\\) \\( 24, 34\\) \\)" \
72aed9d
+		"print ar2\(2:3, 3:4\)."
72aed9d
+gdb_test "print ar2\(8:9,8:\)" \
72aed9d
+		"\\$\[0-9\]+ = \\(\\( 88, 98\\) \\( 89, 99\\) \\)" \
72aed9d
+		"print ar2\(8:9,8:\)"
72aed9d
+gdb_test "print ar2\(8:9,:2\)" \
72aed9d
+		"\\$\[0-9\]+ = \\(\\( 81, 91\\) \\( 82, 92\\) \\)" \
72aed9d
+		"print ar2\(8:9,:2\)"
72aed9d
+
72aed9d
+gdb_test "print ar2\(8:,8:9\)" \
72aed9d
+		"\\$\[0-9\]+ = \\(\\( 88, 98\\) \\( 89, 99\\) \\)" \
72aed9d
+		"print ar2\(8:,8:9\)"
72aed9d
+gdb_test "print ar2\(8:,8:\)" \
72aed9d
+		"\\$\[0-9\]+ = \\(\\( 88, 98\\) \\( 89, 99\\) \\)" \
72aed9d
+		"print ar2\(8:,8:\)"
72aed9d
+gdb_test "print ar2\(8:,:2\)" \
72aed9d
+		"\\$\[0-9\]+ = \\(\\( 81, 91\\) \\( 82, 92\\) \\)" \
72aed9d
+		"print ar2\(8:,:2\)"
72aed9d
+
72aed9d
+gdb_test "print ar2\(:2,2:3\)" \
72aed9d
+		"\\$\[0-9\]+ = \\(\\( 12, 22\\) \\( 13, 23\\) \\)" \
72aed9d
+		"print ar2\(:2,2:3\)"
72aed9d
+gdb_test "print ar2\(:2,8:\)" \
72aed9d
+		"\\$\[0-9\]+ = \\(\\( 18, 28\\) \\( 19, 29\\) \\)" \
72aed9d
+		"print ar2\(:2,8:\)"
72aed9d
+gdb_test "print ar2\(:2,:2\)" \
72aed9d
+		"\\$\[0-9\]+ = \\(\\( 11, 21\\) \\( 12, 22\\) \\)" \
72aed9d
+		"print ar2\(:2,:2\)"
72aed9d
+
72aed9d
+# Test subranges of 2 dimensional arrays with literals and subrange variations
72aed9d
+gdb_test "print ar2\(7, 3:6\)" \
72aed9d
+		"\\$\[0-9\]+ = \\(73, 74, 75, 76\\)" \
72aed9d
+		"print ar2\(7, 3:6\)"
72aed9d
+gdb_test "print ar2\(7,8:\)" \
72aed9d
+		"\\$\[0-9\]+ = \\(78, 79\\)" \
72aed9d
+		"print ar2\(7,8:\)"
72aed9d
+gdb_test "print ar2\(7,:2\)" \
72aed9d
+		"\\$\[0-9\]+ = \\(71, 72\\)" \
72aed9d
+		"print ar2\(7,:2\)"
72aed9d
+
72aed9d
+gdb_test "print ar2\(7:8,4\)" \
72aed9d
+		"\\$\[0-9\]+ = \\(74, 84\\)" \
72aed9d
+		"print ar2(7:8,4\)"
72aed9d
+gdb_test "print ar2\(8:,4\)" \
72aed9d
+		"\\$\[0-9\]+ = \\(84, 94\\)" \
72aed9d
+		"print ar2\(8:,4\)"
72aed9d
+gdb_test "print ar2\(:2,4\)" \
72aed9d
+		"\\$\[0-9\]+ = \\(14, 24\\)" \
72aed9d
+		"print ar2\(:2,4\)"
72aed9d
+gdb_test "print ar2\(3,4\)" \
72aed9d
+		"\\$\[0-9\]+ = 34" \
72aed9d
+		"print ar2\(3,4\)"
72aed9d
+
72aed9d
+# Test subarrays of 3 dimensional arrays with literals and subrange variations
72aed9d
+gdb_test "print ar3\(2:4,3:4,7:8\)" \
72aed9d
+		"\\$\[0-9\]+ = \\(\\( \\( 237, 337, 437\\) \\( 247, 347, 447\\)\
72aed9d
+		 \\) \\( \\( 238, 338, 438\\) \\( 248, 348, 448\\) \\) \\)" \
72aed9d
+		"print ar3\(2:4,3:4,7:8\)"
72aed9d
+gdb_test "print ar3\(2:3,4:5,8:\)" \
72aed9d
+		"\\$\[0-9\]+ = \\(\\( \\( 248, 348\\) \\( 258, 358\\) \\) \\(\
72aed9d
+		 \\( 249, 349\\) \\( 259, 359\\) \\) \\)" \
72aed9d
+		"print ar3\(2:3,4:5,8:\)"
72aed9d
+gdb_test "print ar3\(2:3,4:5,:2\)" \
72aed9d
+		"\\$\[0-9\]+ = \\(\\( \\( 241, 341\\) \\( 251, 351\\) \\) \\(\
72aed9d
+		 \\( 242, 342\\) \\( 252, 352\\) \\) \\)" \
72aed9d
+		"print ar3\(2:3,4:5,:2\)"
72aed9d
+
72aed9d
+gdb_test "print ar3\(2:3,8:,7:8\)" \
72aed9d
+		"\\$\[0-9\]+ = \\(\\( \\( 287, 387\\) \\( 297, 397\\) \\) \\(\
72aed9d
+		 \\( 288, 388\\) \\( 298, 398\\) \\) \\)" \
72aed9d
+		"print ar3\(2:3,8:,7:8\)"
72aed9d
+gdb_test "print ar3\(2:3,8:,8:\)" \
72aed9d
+		"\\$\[0-9\]+ = \\(\\( \\( 288, 388\\) \\( 298, 398\\) \\) \\(\
72aed9d
+		 \\( 289, 389\\) \\( 299, 399\\) \\) \\)" \
72aed9d
+		"print ar3\(2:3,8:,8:\)"
72aed9d
+gdb_test "print ar3\(2:3,8:,:2\)" \
72aed9d
+		"\\$\[0-9\]+ = \\(\\( \\( 281, 381\\) \\( 291, 391\\) \\) \\(\
72aed9d
+		 \\( 282, 382\\) \\( 292, 392\\) \\) \\)" \
72aed9d
+		"print ar3\(2:3,8:,:2\)"
72aed9d
+
72aed9d
+gdb_test "print ar3\(2:3,:2,7:8\)" \
72aed9d
+		"\\$\[0-9\]+ = \\(\\( \\( 217, 317\\) \\( 227, 327\\) \\) \\(\
72aed9d
+		 \\( 218, 318\\) \\( 228, 328\\) \\) \\)" \
72aed9d
+		"print ar3\(2:3,:2,7:8\)"
72aed9d
+gdb_test "print ar3\(2:3,:2,8:\)" \
72aed9d
+		"\\$\[0-9\]+ = \\(\\( \\( 218, 318\\) \\( 228, 328\\) \\) \\(\
72aed9d
+		 \\( 219, 319\\) \\( 229, 329\\) \\) \\)" \
72aed9d
+		"print ar3\(2:3,:2,8:\)"
72aed9d
+gdb_test "print ar3\(2:3,:2,:2\)" \
72aed9d
+		"\\$\[0-9\]+ = \\(\\( \\( 211, 311\\) \\( 221, 321\\) \\) \\(\
72aed9d
+		 \\( 212, 312\\) \\( 222, 322\\) \\) \\)" \
72aed9d
+		"print ar3\(2:3,:2,:2\)"
72aed9d
+
72aed9d
+gdb_test "print ar3\(8:,3:4,7:8\)" \
72aed9d
+		"\\$\[0-9\]+ = \\(\\( \\( 837, 937\\) \\( 847, 947\\) \\) \\(\
72aed9d
+		 \\( 838, 938\\) \\( 848, 948\\) \\) \\)" \
72aed9d
+		"print ar3\(8:,3:4,7:8\)"
72aed9d
+gdb_test "print ar3\(8:,4:5,8:\)" \
72aed9d
+		"\\$\[0-9\]+ = \\(\\( \\( 848, 948\\) \\( 858, 958\\) \\) \\(\
72aed9d
+		 \\( 849, 949\\) \\( 859, 959\\) \\) \\)" \
72aed9d
+		"print ar3\(8:,4:5,8:\)"
72aed9d
+gdb_test "print ar3\(8:,4:5,:2\)" \
72aed9d
+		"\\$\[0-9\]+ = \\(\\( \\( 841, 941\\) \\( 851, 951\\) \\) \\(\
72aed9d
+		 \\( 842, 942\\) \\( 852, 952\\) \\) \\)" \
72aed9d
+		"print ar3\(8:,4:5,:2\)"
72aed9d
+
72aed9d
+gdb_test "print ar3\(8:,8:,7:8\)" \
72aed9d
+		"\\$\[0-9\]+ = \\(\\( \\( 887, 987\\) \\( 897, 997\\) \\) \\(\
72aed9d
+		 \\( 888, 988\\) \\( 898, 998\\) \\) \\)" \
72aed9d
+		"print ar3\(8:,8:,7:8\)"
72aed9d
+gdb_test "print ar3\(8:,8:,8:\)" \
72aed9d
+		"\\$\[0-9\]+ = \\(\\( \\( 888, 988\\) \\( 898, 998\\) \\) \\(\
72aed9d
+		 \\( 889, 989\\) \\( 899, 999\\) \\) \\)" \
72aed9d
+		"print ar3\(8:,8:,8:\)"
72aed9d
+gdb_test "print ar3\(8:,8:,:2\)" \
72aed9d
+		"\\$\[0-9\]+ = \\(\\( \\( 881, 981\\) \\( 891, 991\\) \\) \\(\
72aed9d
+		 \\( 882, 982\\) \\( 892, 992\\) \\) \\)" \
72aed9d
+		"print ar3\(8:,8:,:2\)"
72aed9d
+
72aed9d
+gdb_test "print ar3\(8:,:2,7:8\)" \
72aed9d
+		"\\$\[0-9\]+ = \\(\\( \\( 817, 917\\) \\( 827, 927\\) \\) \\(\
72aed9d
+		 \\( 818, 918\\) \\( 828, 928\\) \\) \\)" \
72aed9d
+		"print ar3\(8:,:2,7:8\)"
72aed9d
+gdb_test "print ar3\(8:,:2,8:\)" \
72aed9d
+		"\\$\[0-9\]+ = \\(\\( \\( 818, 918\\) \\( 828, 928\\) \\) \\(\
72aed9d
+		 \\( 819, 919\\) \\( 829, 929\\) \\) \\)" \
72aed9d
+		"print ar3\(8:,:2,8:\)"
72aed9d
+gdb_test "print ar3\(8:,:2,:2\)" \
72aed9d
+		"\\$\[0-9\]+ = \\(\\( \\( 811, 911\\) \\( 821, 921\\) \\) \\(\
72aed9d
+		 \\( 812, 912\\) \\( 822, 922\\) \\) \\)" \
72aed9d
+		"print ar3\(8:,:2,:2\)"
72aed9d
+
72aed9d
+
72aed9d
+gdb_test "print ar3\(:2,3:4,7:8\)" \
72aed9d
+		"\\$\[0-9\]+ = \\(\\( \\( 137, 237\\) \\( 147, 247\\) \\) \\(\
72aed9d
+		 \\( 138, 238\\) \\( 148, 248\\) \\) \\)" \
72aed9d
+		"print ar3 \(:2,3:4,7:8\)."
72aed9d
+gdb_test "print ar3\(:2,3:4,8:\)" \
72aed9d
+		"\\$\[0-9\]+ = \\(\\( \\( 138, 238\\) \\( 148, 248\\) \\) \\(\
72aed9d
+		 \\( 139, 239\\) \\( 149, 249\\) \\) \\)" \
72aed9d
+		"print ar3\(:2,3:4,8:\)"
72aed9d
+gdb_test "print ar3\(:2,3:4,:2\)" \
72aed9d
+		"\\$\[0-9\]+ = \\(\\( \\( 131, 231\\) \\( 141, 241\\) \\) \\(\
72aed9d
+		 \\( 132, 232\\) \\( 142, 242\\) \\) \\)" \
72aed9d
+		"print ar3\(:2,3:4,:2\)"
72aed9d
+
72aed9d
+gdb_test "print ar3\(:2,8:,7:8\)" "\\$\[0-9\]+ = \\(\\( \\( 187, 287\\) \\(\
72aed9d
+		 197, 297\\) \\) \\( \\( 188, 288\\) \\( 198, 298\\) \\) \\)" \
72aed9d
+		"print ar3\(:2,8:,7:8\)"
72aed9d
+gdb_test "print ar3\(:2,8:,8:\)" "\\$\[0-9\]+ = \\(\\( \\( 188, 288\\) \\( 198,\
72aed9d
+		 298\\) \\) \\( \\( 189, 289\\) \\( 199, 299\\) \\) \\)" \
72aed9d
+		"print ar3\(:2,8:,8:\)"
72aed9d
+gdb_test "print ar3\(:2,8:,:2\)" "\\$\[0-9\]+ = \\(\\( \\( 181, 281\\) \\( 191,\
72aed9d
+		 291\\) \\) \\( \\( 182, 282\\) \\( 192, 292\\) \\) \\)" \
72aed9d
+		"print ar3\(:2,8:,:2\)"
72aed9d
+
72aed9d
+gdb_test "print ar3\(:2,:2,7:8\)" \
72aed9d
+		"\\$\[0-9\]+ = \\(\\( \\( 117, 217\\) \\( 127, 227\\) \\) \\(\
72aed9d
+		 \\( 118, 218\\) \\( 128, 228\\) \\) \\)" \
72aed9d
+		"print ar3\(:2,:2,7:8\)"
72aed9d
+gdb_test "print ar3\(:2,:2,8:\)" \
72aed9d
+		"\\$\[0-9\]+ = \\(\\( \\( 118, 218\\) \\( 128, 228\\) \\) \\(\
72aed9d
+		 \\( 119, 219\\) \\( 129, 229\\) \\) \\)" \
72aed9d
+		"print ar3\(:2,:2,8:\)"
72aed9d
+gdb_test "print ar3\(:2,:2,:2\)" \
72aed9d
+		"\\$\[0-9\]+ = \\(\\( \\( 111, 211\\) \\( 121, 221\\) \\) \\(\
72aed9d
+		 \\( 112, 212\\) \\( 122, 222\\) \\) \\)" \
72aed9d
+		"print ar3\(:2,:2,:2\)"
72aed9d
+
72aed9d
+#Tests for subarrays of 3 dimensional arrays with literals and subranges
72aed9d
+gdb_test "print ar3\(3,3:4,7:8\)" \
72aed9d
+		"\\$\[0-9\]+ = \\(\\( 337, 347\\) \\( 338, 348\\) \\)" \
72aed9d
+		"print ar3\(3,3:4,7:8\)"
72aed9d
+gdb_test "print ar3\(3,4:5,8:\)" \
72aed9d
+		"\\$\[0-9\]+ = \\(\\( 348, 358\\) \\( 349, 359\\) \\)" \
72aed9d
+		"print ar3\(3,4:5,8:\)"
72aed9d
+gdb_test "print ar3\(3,4:5,:2\)" \
72aed9d
+		"\\$\[0-9\]+ = \\(\\( 341, 351\\) \\( 342, 352\\) \\)" \
72aed9d
+		"print ar3\(3,4:5,:2\)"
72aed9d
+gdb_test "print ar3\(3,4:5,3\)" \
72aed9d
+		"\\$\[0-9\]+ = \\(343, 353\\)" \
72aed9d
+		"print ar3\(3,4:5,3\)"
72aed9d
+
72aed9d
+gdb_test "print ar3\(2,8:,7:8\)" \
72aed9d
+		"\\$\[0-9\]+ = \\(\\( 287, 297\\) \\( 288, 298\\) \\)" \
72aed9d
+		"print ar3\(2,8:,7:8\)"
72aed9d
+gdb_test "print ar3\(2,8:,8:\)" \
72aed9d
+		"\\$\[0-9\]+ = \\(\\( 288, 298\\) \\( 289, 299\\) \\)" \
72aed9d
+		"print ar3\(2,8:,8:\)"
72aed9d
+gdb_test "print ar3\(2,8:,:2\)"\
72aed9d
+		"\\$\[0-9\]+ = \\(\\( 281, 291\\) \\( 282, 292\\) \\)" \
72aed9d
+		"print ar3\(2,8:,:2\)"
72aed9d
+gdb_test "print ar3\(2,8:,3\)" \
72aed9d
+		"\\$\[0-9\]+ = \\(283, 293\\)" \
72aed9d
+		"print ar3\(2,8:,3\)"
72aed9d
+
72aed9d
+gdb_test "print ar3\(2,:2,7:8\)" \
72aed9d
+		"\\$\[0-9\]+ = \\(\\( 217, 227\\) \\( 218, 228\\) \\)" \
72aed9d
+		"print ar3\(2,:2,7:8\)"
72aed9d
+gdb_test "print ar3\(2,:2,8:\)" \
72aed9d
+		"\\$\[0-9\]+ = \\(\\( 218, 228\\) \\( 219, 229\\) \\)" \
72aed9d
+		"print ar3\(2,:2,8:\)"
72aed9d
+gdb_test "print ar3\(2,:2,:2\)" \
72aed9d
+		"\\$\[0-9\]+ = \\(\\( 211, 221\\) \\( 212, 222\\) \\)" \
72aed9d
+		"print ar3\(2,:2,:2\)"
72aed9d
+gdb_test "print ar3\(2,:2,3\)" \
72aed9d
+		"\\$\[0-9\]+ = \\(213, 223\\)" \
72aed9d
+		"print ar3\(2,:2,3\)"
72aed9d
+
72aed9d
+gdb_test "print ar3\(3,4,7:8\)" \
72aed9d
+		"\\$\[0-9\]+ = \\(347, 348\\)" \
72aed9d
+		"print ar3\(3,4,7:8\)"
72aed9d
+gdb_test "print ar3\(3,4,8:\)" \
72aed9d
+		"\\$\[0-9\]+ = \\(348, 349\\)" \
72aed9d
+i		"print ar3\(3,4,8:\)"
72aed9d
+gdb_test "print ar3\(3,4,:2\)" \
72aed9d
+		"\\$\[0-9\]+ = \\(341, 342\\)" \
72aed9d
+		"print ar3\(3,4,:2\)"
72aed9d
+gdb_test "print ar3\(5,6,7\)" \
72aed9d
+		"\\$\[0-9\]+ = 567" \
72aed9d
+		"print ar3\(5,6,7\)"
72aed9d
+
72aed9d
+gdb_test "print ar3\(3:4,6,7:8\)" \
72aed9d
+		"\\$\[0-9\]+ = \\(\\( 367, 467\\) \\( 368, 468\\) \\)" \
72aed9d
+		"print ar3\(3:4,6,7:8\)"
72aed9d
+gdb_test "print ar3\(3:4,6,8:\)" \
72aed9d
+		"\\$\[0-9\]+ = \\(\\( 368, 468\\) \\( 369, 469\\) \\)" \
72aed9d
+		"print ar3\(3:4,6,8:\)"
72aed9d
+gdb_test "print ar3\(3:4,6,:2\)" \
72aed9d
+		"\\$\[0-9\]+ = \\(\\( 361, 461\\) \\( 362, 462\\) \\)" \
72aed9d
+		"print ar3\(3:4,6,:2\)"
72aed9d
+gdb_test "print ar3\(3:4,6,5\)" \
72aed9d
+		"\\$\[0-9\]+ = \\(365, 465\\)" \
72aed9d
+		"print ar3\(3:4,6,5\)"
72aed9d
+
72aed9d
+gdb_test "print ar3\(8:,6,7:8\)" \
72aed9d
+		"\\$\[0-9\]+ = \\(\\( 867, 967\\) \\( 868, 968\\) \\)" \
72aed9d
+		"print ar3\(8:,6,7:8\)"
72aed9d
+gdb_test "print ar3\(8:,6,8:\)" \
72aed9d
+		"\\$\[0-9\]+ = \\(\\( 868, 968\\) \\( 869, 969\\) \\)" \
72aed9d
+		"print ar3\(8:,6,8:\)"
72aed9d
+gdb_test "print ar3\(8:,6,:2\)" \
72aed9d
+		"\\$\[0-9\]+ = \\(\\( 861, 961\\) \\( 862, 962\\) \\)" \
72aed9d
+		"print ar3\(8:,6,:2\)"
72aed9d
+gdb_test "print ar3\(8:,6,5\)" \
72aed9d
+		"\\$\[0-9\]+ = \\(865, 965\\)" \
72aed9d
+		"print ar3\(8:,6,5\)"
72aed9d
+
72aed9d
+gdb_test "print ar3\(:2,6,7:8\)" \
72aed9d
+		"\\$\[0-9\]+ = \\(\\( 167, 267\\) \\( 168, 268\\) \\)" \
72aed9d
+		"print ar3\(:2,6,7:8\)"
72aed9d
+gdb_test "print ar3\(:2,6,8:\)" \
72aed9d
+		"\\$\[0-9\]+ = \\(\\( 168, 268\\) \\( 169, 269\\) \\)" \
72aed9d
+		"print ar3\(:2,6,8:\)"
72aed9d
+gdb_test "print ar3\(:2,6,:2\)" \
72aed9d
+		"\\$\[0-9\]+ = \\(\\( 161, 261\\) \\( 162, 262\\) \\)" \
72aed9d
+		"print ar3\(:2,6,:2\)"
72aed9d
+gdb_test "print ar3\(:2,6,5\)" \
72aed9d
+		"\\$\[0-9\]+ = \\(165, 265\\)" \
72aed9d
+		"print ar3\(:2,6,5\)"
72aed9d
+
72aed9d
+gdb_test "print ar3\(3:4,5:6,4\)" \
72aed9d
+		"\\$\[0-9\]+ = \\(\\( 354, 454\\) \\( 364, 464\\) \\)" \
72aed9d
+		"print ar2\(3:4,5:6,4\)"
72aed9d
+gdb_test "print ar3\(8:,5:6,4\)" \
72aed9d
+		"\\$\[0-9\]+ = \\(\\( 854, 954\\) \\( 864, 964\\) \\)" \
72aed9d
+		"print ar2\(8:,5:6,4\)"
72aed9d
+gdb_test "print ar3\(:2,5:6,4\)" \
72aed9d
+		"\\$\[0-9\]+ = \\(\\( 154, 254\\) \\( 164, 264\\) \\)" \
72aed9d
+		"print ar2\(:2,5:6,4\)"
72aed9d
+
72aed9d
+# Stride > 1
72aed9d
+gdb_test "print ar1\(2:6:2\)" \
72aed9d
+		"\\$\[0-9\]+ = \\(2, 4, 6\\)" \
72aed9d
+		"print ar1\(2:6:2\)"
72aed9d
+gdb_test "print ar2\(2:6:2,3:4\)" \
72aed9d
+		"\\$\[0-9\]+ = \\(\\( 23, 43, 63\\) \\( 24, 44, 64\\) \\)" \
72aed9d
+		"print ar2\(2:6:2,3:4\)"
72aed9d
+gdb_test "print ar2\(2:6:2,3\)" \
72aed9d
+		"\\$\[0-9\]+ = \\(23, 43, 63\\)" \
72aed9d
+		"print ar2\(2:6:2,3\)"
72aed9d
+gdb_test "print ar3\(2:6:2,3:5:2,4:7:3\)" \
72aed9d
+		"\\$\[0-9\]+ = \\(\\( \\( 234, 434, 634\\) \\( 254, 454, 654\\)\
72aed9d
+		 \\) \\( \\( 237, 437, 637\\) \\( 257, 457, 657\\) \\) \\)" \
72aed9d
+		"print ar3\(2:6:2,3:5:2,4:7:3\)"
72aed9d
+gdb_test "print ar3\(2:6:2,5,4:7:3\)" \
72aed9d
+		"\\$\[0-9\]+ = \\(\\( 254, 454, 654\\) \\( 257, 457, 657\\)\
72aed9d
+		 \\)" \
72aed9d
+		"print ar3\(2:6:2,5,4:7:3\)"
72aed9d
+
72aed9d
+# Stride < 0
72aed9d
+gdb_test "print ar1\(8:2:-2\)" \
72aed9d
+		"\\$\[0-9\]+ = \\(8, 6, 4, 2\\)" \
72aed9d
+		"print ar1\(8:2:-2\)"
72aed9d
+gdb_test "print ar2\(8:2:-2,3:4\)" \
72aed9d
+		"\\$\[0-9\]+ = \\(\\( 83, 63, 43, 23\\) \\( 84, 64, 44, 24\\)\
72aed9d
+		 \\)" \
72aed9d
+		"print ar2\(8:2:-2,3:4\)"
72aed9d
+gdb_test "print ar2\(2:6:2,3\)" \
72aed9d
+		"\\$\[0-9\]+ = \\(23, 43, 63\\)" \
72aed9d
+		"print ar2\(2:6:2,3\)"
72aed9d
+gdb_test "print ar3\(2:3,7:3:-4,4:7:3\)" \
72aed9d
+		"\\$\[0-9\]+ = \\(\\( \\( 274, 374\\) \\( 234, 334\\) \\) \\(\
72aed9d
+		 \\( 277, 377\\) \\( 237, 337\\) \\) \\)" \
72aed9d
+		"print ar3\(2:3,7:3:-4,4:7:3\)"
72aed9d
+gdb_test "print ar3\(2:6:2,5,7:4:-3\)" \
72aed9d
+		"\\$\[0-9\]+ = \\(\\( 257, 457, 657\\) \\( 254, 454, 654\\)\
72aed9d
+		 \\)" \
72aed9d
+		"print ar3\(2:6:2,5,7:4:-3\)"
72aed9d
+
72aed9d
+# Tests with negative and mixed indices
72aed9d
+gdb_test "p ar4\(2:4, -2:1, -15:-14\)" \
72aed9d
+		"\\$\[0-9\]+ = \\(\\( \\( 261, 361, 461\\) \\( 271, 371, 471\\)\
72aed9d
+		 \\( 281, 381, 481\\) \\( 291, 391, 491\\) \\) \\( \\( 262,\
72aed9d
+		 362, 462\\) \\( 272, 372, 472\\) \\( 282, 382, 482\\) \\( 292,\
72aed9d
+		 392, 492\\) \\) \\)" \
72aed9d
+		"print ar4(2:4, -2:1, -15:-14)"
72aed9d
+
72aed9d
+gdb_test "p ar4\(7,-6:2:3,-7\)" \
72aed9d
+                "\\$\[0-9\]+ = \\(729, 759, 789\\)" \
72aed9d
+                "print ar4(7,-6:2:3,-7)"
72aed9d
+
72aed9d
+gdb_test "p ar4\(9:2:-2, -6:2:3, -6:-15:-3\)" \
72aed9d
+                "\\$\[0-9\]+ = \\(\\( \\( 930, 730, 530, 330\\) \\( 960, 760,\
72aed9d
+		 560, 360\\) \\( 990, 790, 590, 390\\) \\) \\( \\( 927, 727,\
72aed9d
+		 527, 327\\) \\( 957, 757, 557, 357\\) \\( 987, 787, 587,\
72aed9d
+		 387\\) \\) \\( \\( 924, 724, 524, 324\\) \\( 954, 754, 554,\
72aed9d
+		 354\\) \\( 984, 784, 584, 384\\) \\) \\( \\( 921, 721, 521,\
72aed9d
+		 321\\) \\( 951, 751, 551, 351\\) \\( 981, 781, 581, 381\\) \\)\
72aed9d
+		 \\)" \
72aed9d
+                "print ar4(9:2:-2, -6:2:3, -6:-15:-3)"
72aed9d
+
72aed9d
+gdb_test "p ar4\(:,:,:\)" \
72aed9d
+                "\\$\[0-9\]+ = \\(\\( \\( 111, 211, 311, 411, 511, 611, 711,\
72aed9d
+		 811, .*" \
72aed9d
+                "print ar4(:,:,:)"
72aed9d
+
72aed9d
+# Provoke error messages for bad user input
72aed9d
+gdb_test "print ar1\(0:4\)" \
72aed9d
+		"provided bound\\(s\\) outside array bound\\(s\\)" \
72aed9d
+		"print ar1\(0:4\)"
72aed9d
+gdb_test "print ar1\(8:12\)" \
72aed9d
+		"provided bound\\(s\\) outside array bound\\(s\\)" \
72aed9d
+		"print ar1\(8:12\)"
72aed9d
+gdb_test "print ar1\(8:2:\)" \
72aed9d
+		"A syntax error in expression, near `\\)'." \
72aed9d
+		"print ar1\(8:2:\)"
72aed9d
+gdb_test "print ar1\(8:2:2\)" \
72aed9d
+		"Wrong value provided for stride and boundaries" \
72aed9d
+		"print ar1\(8:2:2\)"
72aed9d
+gdb_test "print ar1\(2:8:-2\)" \
72aed9d
+		"Wrong value provided for stride and boundaries" \
72aed9d
+		"print ar1\(2:8:-2\)"
72aed9d
+gdb_test "print ar1\(2:7:0\)" \
72aed9d
+		"Stride must not be 0" \
72aed9d
+		"print ar1\(2:7:0\)"
72aed9d
+gdb_test "print ar1\(3:7\) = 42" \
72aed9d
+		"Invalid cast." \
72aed9d
+		"Assignment of value to subarray"
72aed9d
diff --git a/gdb/testsuite/gdb.fortran/static-arrays.f90 b/gdb/testsuite/gdb.fortran/static-arrays.f90
72aed9d
new file mode 100644
72aed9d
index 0000000..f22fcbe
72aed9d
--- /dev/null
72aed9d
+++ b/gdb/testsuite/gdb.fortran/static-arrays.f90
72aed9d
@@ -0,0 +1,55 @@
72aed9d
+! Copyright 2015 Free Software Foundation, Inc.
72aed9d
+!
72aed9d
+! Contributed by Intel Corp. <christoph.t.weinmann@intel.com>
72aed9d
+!
72aed9d
+! This program is free software; you can redistribute it and/or modify
72aed9d
+! it under the terms of the GNU General Public License as published by
72aed9d
+! the Free Software Foundation; either version 3 of the License, or
72aed9d
+! (at your option) any later version.
72aed9d
+!
72aed9d
+! This program is distributed in the hope that it will be useful,
72aed9d
+! but WITHOUT ANY WARRANTY; without even the implied warranty of
72aed9d
+! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
72aed9d
+! GNU General Public License for more details.
72aed9d
+!
72aed9d
+! You should have received a copy of the GNU General Public License
72aed9d
+! along with this program.  If not, see <http://www.gnu.org/licenses/>.
72aed9d
+
72aed9d
+subroutine sub
72aed9d
+  integer, dimension(9) :: ar1
72aed9d
+  integer, dimension(9,9) :: ar2
72aed9d
+  integer, dimension(9,9,9) :: ar3
72aed9d
+  integer, dimension(10,-7:3, -15:-5) :: ar4
72aed9d
+  integer :: i,j,k
72aed9d
+
72aed9d
+  ar1 = 1
72aed9d
+  ar2 = 1
72aed9d
+  ar3 = 1
72aed9d
+  ar4 = 4
72aed9d
+
72aed9d
+  ! Resulting array ar3 looks like ((( 111, 112, 113, 114,...)))
72aed9d
+  do i = 1, 9, 1
72aed9d
+    ar1(i) = i
72aed9d
+    do j = 1, 9, 1
72aed9d
+      ar2(i,j) = i*10 + j
72aed9d
+      do k = 1, 9, 1
72aed9d
+        ar3(i,j,k) = i*100 + j*10 + k
72aed9d
+      end do
72aed9d
+    end do
72aed9d
+  end do
72aed9d
+
72aed9d
+  do i = 1, 10, 1
72aed9d
+    do j = -7, 3, 1
72aed9d
+      do k = -15, -5, 1
72aed9d
+        ar4(i,j,k) = i*100 + (j+8)*10 + (k+16)
72aed9d
+      end do
72aed9d
+    end do
72aed9d
+  end do
72aed9d
+
72aed9d
+  ar1(1) = 11  !BP1
72aed9d
+  return
72aed9d
+end
72aed9d
+
72aed9d
+program testprog
72aed9d
+  call sub
72aed9d
+end
d258670
diff --git a/gdb/testsuite/gdb.fortran/vla-ptype.exp b/gdb/testsuite/gdb.fortran/vla-ptype.exp
d258670
index 175661f..544d40a 100644
d258670
--- a/gdb/testsuite/gdb.fortran/vla-ptype.exp
d258670
+++ b/gdb/testsuite/gdb.fortran/vla-ptype.exp
d258670
@@ -98,3 +98,7 @@ gdb_test "ptype vla2" "type = <not allocated>" "ptype vla2 not allocated"
d258670
 gdb_test "ptype vla2(5, 45, 20)" \
d258670
   "no such vector element \\\(vector not allocated\\\)" \
d258670
   "ptype vla2(5, 45, 20) not allocated"
d258670
+
d258670
+gdb_breakpoint [gdb_get_line_number "vla1-neg-bounds"]
d258670
+gdb_continue_to_breakpoint "vla1-neg-bounds"
d258670
+gdb_test "ptype vla1" "type = $real \\(-2:1,-5:4,-3:-1\\)" "ptype vla1 negative bounds"
d258670
diff --git a/gdb/testsuite/gdb.fortran/vla-sizeof.exp b/gdb/testsuite/gdb.fortran/vla-sizeof.exp
d258670
index 8010c0a..f8258a1 100644
d258670
--- a/gdb/testsuite/gdb.fortran/vla-sizeof.exp
d258670
+++ b/gdb/testsuite/gdb.fortran/vla-sizeof.exp
d258670
@@ -44,3 +44,7 @@ gdb_test "print sizeof(pvla)" " = 0" "print sizeof non-associated pvla"
d258670
 gdb_breakpoint [gdb_get_line_number "pvla-associated"]
d258670
 gdb_continue_to_breakpoint "pvla-associated"
d258670
 gdb_test "print sizeof(pvla)" " = 4000" "print sizeof associated pvla"
d258670
+
d258670
+gdb_breakpoint [gdb_get_line_number "vla1-neg-bounds"]
d258670
+gdb_continue_to_breakpoint "vla1-neg-bounds"
d258670
+gdb_test "print sizeof(vla1)" " = 480" "print sizeof vla1 negative bounds"
72aed9d
diff --git a/gdb/testsuite/gdb.fortran/vla-stride.exp b/gdb/testsuite/gdb.fortran/vla-stride.exp
72aed9d
new file mode 100644
72aed9d
index 0000000..dcf15e5
72aed9d
--- /dev/null
72aed9d
+++ b/gdb/testsuite/gdb.fortran/vla-stride.exp
72aed9d
@@ -0,0 +1,44 @@
72aed9d
+# Copyright 2016 Free Software Foundation, Inc.
72aed9d
+
72aed9d
+# This program is free software; you can redistribute it and/or modify
72aed9d
+# it under the terms of the GNU General Public License as published by
72aed9d
+# the Free Software Foundation; either version 3 of the License, or
72aed9d
+# (at your option) any later version.
72aed9d
+#
72aed9d
+# This program is distributed in the hope that it will be useful,
72aed9d
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
72aed9d
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
72aed9d
+# GNU General Public License for more details.
72aed9d
+#
72aed9d
+# You should have received a copy of the GNU General Public License
72aed9d
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
72aed9d
+
72aed9d
+standard_testfile ".f90"
72aed9d
+
72aed9d
+if { [prepare_for_testing ${testfile}.exp ${testfile} ${srcfile} \
72aed9d
+    {debug f90 quiet}] } {
72aed9d
+    return -1
72aed9d
+}
72aed9d
+
72aed9d
+if ![runto MAIN__] then {
72aed9d
+    perror "couldn't run to breakpoint MAIN__"
72aed9d
+    continue
72aed9d
+}
72aed9d
+
72aed9d
+gdb_breakpoint [gdb_get_line_number "re-reverse-elements"]
72aed9d
+gdb_continue_to_breakpoint "re-reverse-elements"
72aed9d
+gdb_test "print pvla" " = \\\(1, 2, 3, 4, 5, 6, 7, 8, 9, 10\\\)" \
72aed9d
+  "print re-reverse-elements"
72aed9d
+gdb_test "print pvla(1)" " = 1" "print first re-reverse-element"
72aed9d
+gdb_test "print pvla(10)" " = 10" "print last re-reverse-element"
72aed9d
+
72aed9d
+gdb_breakpoint [gdb_get_line_number "odd-elements"]
72aed9d
+gdb_continue_to_breakpoint "odd-elements"
72aed9d
+gdb_test "print pvla" " = \\\(1, 3, 5, 7, 9\\\)" "print odd-elements"
72aed9d
+gdb_test "print pvla(1)" " = 1" "print first odd-element"
72aed9d
+gdb_test "print pvla(5)" " = 9" "print last odd-element"
72aed9d
+
72aed9d
+gdb_breakpoint [gdb_get_line_number "single-element"]
72aed9d
+gdb_continue_to_breakpoint "single-element"
72aed9d
+gdb_test "print pvla" " = \\\(5\\\)" "print single-element"
72aed9d
+gdb_test "print pvla(1)" " = 5" "print one single-element"
72aed9d
diff --git a/gdb/testsuite/gdb.fortran/vla-stride.f90 b/gdb/testsuite/gdb.fortran/vla-stride.f90
72aed9d
new file mode 100644
d258670
index 0000000..8d24252
72aed9d
--- /dev/null
72aed9d
+++ b/gdb/testsuite/gdb.fortran/vla-stride.f90
72aed9d
@@ -0,0 +1,29 @@
72aed9d
+! Copyright 2016 Free Software Foundation, Inc.
72aed9d
+!
72aed9d
+! This program is free software; you can redistribute it and/or modify
72aed9d
+! it under the terms of the GNU General Public License as published by
72aed9d
+! the Free Software Foundation; either version 3 of the License, or
72aed9d
+! (at your option) any later version.
d258670
+!
72aed9d
+! This program is distributed in the hope that it will be useful,
72aed9d
+! but WITHOUT ANY WARRANTY; without even the implied warranty of
72aed9d
+! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
72aed9d
+! GNU General Public License for more details.
d258670
+!
72aed9d
+! You should have received a copy of the GNU General Public License
72aed9d
+! along with this program.  If not, see <http://www.gnu.org/licenses/>.
72aed9d
+
72aed9d
+program vla_stride
72aed9d
+  integer, target, allocatable :: vla (:)
72aed9d
+  integer, pointer :: pvla (:)
72aed9d
+
72aed9d
+  allocate(vla(10))
72aed9d
+  vla = (/ (I, I = 1,10) /)
72aed9d
+
72aed9d
+  pvla => vla(10:1:-1)
72aed9d
+  pvla => pvla(10:1:-1)
72aed9d
+  pvla => vla(1:10:2)   ! re-reverse-elements
72aed9d
+  pvla => vla(5:4:-2)   ! odd-elements
72aed9d
+
72aed9d
+  pvla => null()        ! single-element
72aed9d
+end program vla_stride
d258670
diff --git a/gdb/testsuite/gdb.fortran/vla.f90 b/gdb/testsuite/gdb.fortran/vla.f90
d258670
index c76d24c..ef307b7 100644
d258670
--- a/gdb/testsuite/gdb.fortran/vla.f90
d258670
+++ b/gdb/testsuite/gdb.fortran/vla.f90
d258670
@@ -54,4 +54,14 @@ program vla
d258670
 
d258670
   allocate (vla3 (2,2))               ! vla2-deallocated
d258670
   vla3(:,:) = 13
d258670
+
d258670
+  allocate (vla1 (-2:1, -5:4, -3:-1))
d258670
+  l = allocated(vla1)
d258670
+
d258670
+  vla1(:, :, :) = 1
d258670
+  vla1(-2, -3, -1) = -231
d258670
+
d258670
+  deallocate (vla1)                   ! vla1-neg-bounds
d258670
+  l = allocated(vla1)
d258670
+
d258670
 end program vla
72aed9d
diff --git a/gdb/valarith.c b/gdb/valarith.c
d258670
index de6fcfd..9753506 100644
72aed9d
--- a/gdb/valarith.c
72aed9d
+++ b/gdb/valarith.c
d258670
@@ -193,11 +193,17 @@ value_subscripted_rvalue (struct value *array, LONGEST index, int lowerbound)
72aed9d
   struct type *array_type = check_typedef (value_type (array));
72aed9d
   struct type *elt_type = check_typedef (TYPE_TARGET_TYPE (array_type));
72aed9d
   ULONGEST elt_size = type_length_units (elt_type);
72aed9d
-  ULONGEST elt_offs = elt_size * (index - lowerbound);
d258670
+  LONGEST elt_offs = index - lowerbound;
72aed9d
+  LONGEST elt_stride = TYPE_BYTE_STRIDE (TYPE_INDEX_TYPE (array_type));
72aed9d
   struct value *v;
72aed9d
 
d258670
+  if (elt_stride != 0)
72aed9d
+    elt_offs *= elt_stride;
72aed9d
+  else
72aed9d
+    elt_offs *= elt_size;
72aed9d
+
72aed9d
   if (index < lowerbound || (!TYPE_ARRAY_UPPER_BOUND_IS_UNDEFINED (array_type)
d258670
-			     && elt_offs >= type_length_units (array_type)))
d258670
+			     && abs (elt_offs) >= type_length_units (array_type)))
72aed9d
     {
d258670
       if (type_not_associated (array_type))
d258670
         error (_("no such vector element (vector not associated)"));
72aed9d
diff --git a/gdb/valops.c b/gdb/valops.c
72aed9d
index 40392e8..24ffacb 100644
72aed9d
--- a/gdb/valops.c
72aed9d
+++ b/gdb/valops.c
72aed9d
@@ -3775,56 +3775,191 @@ value_of_this_silent (const struct language_defn *lang)
72aed9d
 struct value *
72aed9d
 value_slice (struct value *array, int lowbound, int length)
72aed9d
 {
72aed9d
+  /* Pass unaltered arguments to VALUE_SLICE_1, plus a default stride
72aed9d
+     value of '1', which returns every element between LOWBOUND and
72aed9d
+     (LOWBOUND + LENGTH).  We also provide a default CALL_COUNT of '1'
72aed9d
+     as we are only considering the highest dimension, or we are
72aed9d
+     working on a one dimensional array.  So we call VALUE_SLICE_1
72aed9d
+     exactly once.  */
72aed9d
+  return value_slice_1 (array, lowbound, length, 1, 1);
72aed9d
+}
72aed9d
+
72aed9d
+/* VALUE_SLICE_1 is called for each array dimension to calculate the number
72aed9d
+   of elements as defined by the subscript expression.
72aed9d
+   CALL_COUNT is used to determine if we are calling the function once, e.g.
72aed9d
+   we are working on the current dimension of ARRAY, or if we are calling
72aed9d
+   the function repeatedly.  In the later case we need to take elements
72aed9d
+   from the TARGET_TYPE of ARRAY.
72aed9d
+   With a CALL_COUNT greater than 1 we calculate the offsets for every element
72aed9d
+   that should be in the result array.  Then we fetch the contents and then
72aed9d
+   copy them into the result array.  The result array will have one dimension
72aed9d
+   less than the input array, so later on we need to recreate the indices and
72aed9d
+   ranges in the calling function.  */
72aed9d
+
72aed9d
+struct value *
72aed9d
+value_slice_1 (struct value *array, int lowbound, int length,
72aed9d
+	       int stride_length, int call_count)
72aed9d
+{
72aed9d
   struct type *slice_range_type, *slice_type, *range_type;
72aed9d
-  LONGEST lowerbound, upperbound;
72aed9d
-  struct value *slice;
72aed9d
-  struct type *array_type;
72aed9d
+  struct type *array_type = check_typedef (value_type (array));
72aed9d
+  struct type *elt_type = check_typedef (TYPE_TARGET_TYPE (array_type));
72aed9d
+  unsigned int elt_size, elt_offs;
72aed9d
+  LONGEST ary_high_bound, ary_low_bound;
72aed9d
+  struct value *v;
72aed9d
+  int slice_range_size, i = 0, row_count = 1, elem_count = 1;
72aed9d
 
72aed9d
-  array_type = check_typedef (value_type (array));
72aed9d
+  /* Check for legacy code if we are actually dealing with an array or
72aed9d
+     string.  */
72aed9d
   if (TYPE_CODE (array_type) != TYPE_CODE_ARRAY
72aed9d
       && TYPE_CODE (array_type) != TYPE_CODE_STRING)
72aed9d
     error (_("cannot take slice of non-array"));
72aed9d
 
72aed9d
-  range_type = TYPE_INDEX_TYPE (array_type);
72aed9d
-  if (get_discrete_bounds (range_type, &lowerbound, &upperbound) < 0)
72aed9d
-    error (_("slice from bad array or bitstring"));
72aed9d
+  ary_low_bound = TYPE_LOW_BOUND (TYPE_INDEX_TYPE (array_type));
72aed9d
+  ary_high_bound = TYPE_HIGH_BOUND (TYPE_INDEX_TYPE (array_type));
72aed9d
+
72aed9d
+  /* When we are working on a multi-dimensional array, we need to get the
72aed9d
+     attributes of the underlying type.  */
72aed9d
+  if (call_count > 1)
72aed9d
+    {
72aed9d
+      ary_low_bound = TYPE_LOW_BOUND (TYPE_INDEX_TYPE (elt_type));
72aed9d
+      ary_high_bound = TYPE_HIGH_BOUND (TYPE_INDEX_TYPE (elt_type));
72aed9d
+      elt_type = check_typedef (TYPE_TARGET_TYPE (elt_type));
72aed9d
+      row_count = TYPE_LENGTH (array_type)
72aed9d
+		    / TYPE_LENGTH (TYPE_TARGET_TYPE (array_type));
72aed9d
+    }
72aed9d
+
72aed9d
+  /* With a stride of '1', the number of elements per result row is equal to
72aed9d
+     the LENGTH of the subarray.  With non-default stride values, we skip
72aed9d
+     elements, but have to add the start element to the total number of
72aed9d
+     elements per row.  */
72aed9d
+  if (stride_length == 1)
72aed9d
+    elem_count = length;
72aed9d
+  else
72aed9d
+    elem_count = ((length - 1) / stride_length) + 1;
72aed9d
+
72aed9d
+  elt_size = TYPE_LENGTH (elt_type);
72aed9d
+  elt_offs = lowbound - ary_low_bound;
72aed9d
 
72aed9d
-  if (lowbound < lowerbound || length < 0
72aed9d
-      || lowbound + length - 1 > upperbound)
72aed9d
-    error (_("slice out of range"));
72aed9d
+  elt_offs *= elt_size;
72aed9d
+
72aed9d
+  /* Check for valid user input.  In case of Fortran this was already done
72aed9d
+     in the calling function.  */
72aed9d
+  if (call_count == 1
72aed9d
+	&& (!TYPE_ARRAY_UPPER_BOUND_IS_UNDEFINED (array_type)
72aed9d
+	      && elt_offs >= TYPE_LENGTH (array_type)))
72aed9d
+    error (_("no such vector element"));
72aed9d
+
72aed9d
+  /* CALL_COUNT is 1 when we are dealing either with the highest dimension
72aed9d
+     of the array, or a one dimensional array.  Set RANGE_TYPE accordingly.
72aed9d
+     In both cases we calculate how many rows/elements will be in the output
72aed9d
+     array by setting slice_range_size.  */
72aed9d
+  if (call_count == 1)
72aed9d
+    {
72aed9d
+      range_type = TYPE_INDEX_TYPE (array_type);
72aed9d
+      slice_range_size = ary_low_bound + elem_count - 1;
72aed9d
+
72aed9d
+      /* Check if the array bounds are valid.  */
72aed9d
+      if (get_discrete_bounds (range_type, &ary_low_bound, &ary_high_bound) < 0)
72aed9d
+	error (_("slice from bad array or bitstring"));
72aed9d
+    }
72aed9d
+  /* When CALL_COUNT is greater than 1, we are dealing with an array of arrays.
72aed9d
+     So we need to get the type below the current one and set the RANGE_TYPE
72aed9d
+     accordingly.  */
72aed9d
+  else
72aed9d
+    {
72aed9d
+      range_type = TYPE_INDEX_TYPE (TYPE_TARGET_TYPE (array_type));
72aed9d
+      slice_range_size = ary_low_bound + (row_count * elem_count) - 1;
72aed9d
+      ary_low_bound = TYPE_LOW_BOUND (range_type);
72aed9d
+    }
72aed9d
 
72aed9d
   /* FIXME-type-allocation: need a way to free this type when we are
72aed9d
-     done with it.  */
72aed9d
-  slice_range_type = create_static_range_type ((struct type *) NULL,
72aed9d
-					       TYPE_TARGET_TYPE (range_type),
72aed9d
-					       lowbound,
72aed9d
-					       lowbound + length - 1);
72aed9d
+      done with it.  */
72aed9d
 
72aed9d
+  slice_range_type = create_static_range_type (NULL, TYPE_TARGET_TYPE (range_type),
72aed9d
+					       ary_low_bound, slice_range_size);
72aed9d
   {
72aed9d
-    struct type *element_type = TYPE_TARGET_TYPE (array_type);
72aed9d
-    LONGEST offset
72aed9d
-      = (lowbound - lowerbound) * TYPE_LENGTH (check_typedef (element_type));
72aed9d
+    struct type *element_type;
72aed9d
+
72aed9d
+    /* When both CALL_COUNT and STRIDE_LENGTH equal 1, we can use the legacy
72aed9d
+       code for subarrays.  */
72aed9d
+    if (call_count == 1 && stride_length == 1)
72aed9d
+      {
72aed9d
+	element_type = TYPE_TARGET_TYPE (array_type);
72aed9d
+
72aed9d
+	slice_type = create_array_type (NULL, element_type, slice_range_type);
72aed9d
 
72aed9d
-    slice_type = create_array_type ((struct type *) NULL,
72aed9d
-				    element_type,
72aed9d
-				    slice_range_type);
72aed9d
-    TYPE_CODE (slice_type) = TYPE_CODE (array_type);
72aed9d
+	TYPE_CODE (slice_type) = TYPE_CODE (array_type);
72aed9d
 
72aed9d
-    if (VALUE_LVAL (array) == lval_memory && value_lazy (array))
72aed9d
-      slice = allocate_value_lazy (slice_type);
72aed9d
+	if (VALUE_LVAL (array) == lval_memory && value_lazy (array))
72aed9d
+	  v = allocate_value_lazy (slice_type);
72aed9d
+	else
72aed9d
+	  {
72aed9d
+	    v = allocate_value (slice_type);
72aed9d
+	    value_contents_copy (v,
72aed9d
+				 value_embedded_offset (v),
72aed9d
+				 array,
72aed9d
+				 value_embedded_offset (array) + elt_offs,
72aed9d
+				 elt_size * longest_to_int (length));
72aed9d
+	  }
72aed9d
+
72aed9d
+      }
72aed9d
+    /* With a CALL_COUNT or STRIDE_LENGTH are greater than 1 we are working
72aed9d
+       on a range of ranges.  So we copy the relevant elements into the
72aed9d
+       new array we return.  */
72aed9d
     else
72aed9d
       {
72aed9d
-	slice = allocate_value (slice_type);
72aed9d
-	value_contents_copy (slice, 0, array, offset,
72aed9d
-			     type_length_units (slice_type));
72aed9d
+	int j, offs_store = elt_offs;
72aed9d
+	LONGEST dst_offset = 0;
72aed9d
+	LONGEST src_row_length = TYPE_LENGTH (TYPE_TARGET_TYPE (array_type));
72aed9d
+
72aed9d
+	if (call_count == 1)
72aed9d
+	  {
72aed9d
+	    /* When CALL_COUNT is equal to 1 we are working on the current range
72aed9d
+	       and use these elements directly.  */
72aed9d
+	    element_type = TYPE_TARGET_TYPE (array_type);
72aed9d
+	  }
72aed9d
+	else
72aed9d
+	  {
72aed9d
+	    /* Working on an array of arrays, the type of the elements is the type
72aed9d
+	       of the subarrays' type.  */
72aed9d
+	    element_type = TYPE_TARGET_TYPE (TYPE_TARGET_TYPE (array_type));
72aed9d
+	  }
72aed9d
+
72aed9d
+	slice_type = create_array_type (NULL, element_type, slice_range_type);
72aed9d
+
72aed9d
+	 /* If we have a one dimensional array, we copy its TYPE_CODE.  For a
72aed9d
+	    multi dimensional array we copy the embedded type's TYPE_CODE.  */
72aed9d
+	if (call_count == 1)
72aed9d
+	  TYPE_CODE (slice_type) = TYPE_CODE (array_type);
72aed9d
+	else
72aed9d
+	  TYPE_CODE (slice_type) = TYPE_CODE (TYPE_TARGET_TYPE (array_type));
72aed9d
+
72aed9d
+	v = allocate_value (slice_type);
72aed9d
+
72aed9d
+	/* Iterate through the rows of the outer array and set the new offset
72aed9d
+	   for each row.  */
72aed9d
+	for (i = 0; i < row_count; i++)
72aed9d
+	  {
72aed9d
+	    elt_offs = offs_store + i * src_row_length;
72aed9d
+
72aed9d
+	    /* Iterate through the elements in each row to copy only those.  */
72aed9d
+	    for (j = 1; j <= elem_count; j++)
72aed9d
+	      {
72aed9d
+		/* Fetches the contents of ARRAY and copies them into V.  */
72aed9d
+		value_contents_copy (v, dst_offset, array, elt_offs, elt_size);
72aed9d
+		elt_offs += elt_size * stride_length;
72aed9d
+		dst_offset += elt_size;
72aed9d
+	      }
72aed9d
+	  }
72aed9d
       }
72aed9d
 
72aed9d
-    set_value_component_location (slice, array);
72aed9d
-    VALUE_FRAME_ID (slice) = VALUE_FRAME_ID (array);
72aed9d
-    set_value_offset (slice, value_offset (array) + offset);
72aed9d
+    set_value_component_location (v, array);
72aed9d
+    VALUE_REGNUM (v) = VALUE_REGNUM (array);
72aed9d
+    VALUE_FRAME_ID (v) = VALUE_FRAME_ID (array);
72aed9d
+    set_value_offset (v, value_offset (array) + elt_offs);
72aed9d
   }
72aed9d
 
72aed9d
-  return slice;
72aed9d
+  return v;
72aed9d
 }
72aed9d
 
72aed9d
 /* Create a value for a FORTRAN complex number.  Currently most of the
72aed9d
diff --git a/gdb/value.h b/gdb/value.h
72aed9d
index 0b417b4..9c37713 100644
72aed9d
--- a/gdb/value.h
72aed9d
+++ b/gdb/value.h
72aed9d
@@ -1057,6 +1057,8 @@ extern struct value *varying_to_slice (struct value *);
72aed9d
 
72aed9d
 extern struct value *value_slice (struct value *, int, int);
72aed9d
 
72aed9d
+extern struct value *value_slice_1 (struct value *, int, int, int, int);
72aed9d
+
72aed9d
 extern struct value *value_literal_complex (struct value *, struct value *,
72aed9d
 					    struct type *);
72aed9d