Blame SOURCES/gdb-vla-intel-fortran-strides.patch

b2f73e
From FEDORA_PATCHES Mon Sep 17 00:00:00 2001
b2f73e
From: Fedora GDB patches <invalid@email.com>
b2f73e
Date: Fri, 27 Oct 2017 21:07:50 +0200
b2f73e
Subject: gdb-vla-intel-fortran-strides.patch
b2f73e
b2f73e
;; VLA (Fortran dynamic arrays) from Intel + archer-jankratochvil-vla tests.
b2f73e
;;=push
b2f73e
b2f73e
git diff --stat -p gdb/master...gdb/users/bheckel/fortran-strides
b2f73e
dbfd7140bf4c0500d1f5d192be781f83f78f7922
b2f73e
b2f73e
 gdb/dwarf2loc.c                             |  46 ++-
b2f73e
 gdb/dwarf2loc.h                             |   6 +
b2f73e
 gdb/dwarf2read.c                            |  13 +-
b2f73e
 gdb/eval.c                                  | 391 +++++++++++++++++++++-----
b2f73e
 gdb/expprint.c                              |  20 +-
b2f73e
 gdb/expression.h                            |  18 +-
b2f73e
 gdb/f-exp.y                                 |  42 ++-
b2f73e
 gdb/f-valprint.c                            |   8 +-
b2f73e
 gdb/gdbtypes.c                              |  34 ++-
b2f73e
 gdb/gdbtypes.h                              |  18 +-
b2f73e
 gdb/parse.c                                 |  24 +-
b2f73e
 gdb/rust-exp.y                              |  12 +-
b2f73e
 gdb/rust-lang.c                             |  17 +-
b2f73e
 gdb/testsuite/gdb.fortran/static-arrays.exp | 421 ++++++++++++++++++++++++++++
b2f73e
 gdb/testsuite/gdb.fortran/static-arrays.f90 |  55 ++++
b2f73e
 gdb/testsuite/gdb.fortran/vla-ptype.exp     |   4 +
b2f73e
 gdb/testsuite/gdb.fortran/vla-sizeof.exp    |   4 +
b2f73e
 gdb/testsuite/gdb.fortran/vla-stride.exp    |  44 +++
b2f73e
 gdb/testsuite/gdb.fortran/vla-stride.f90    |  29 ++
b2f73e
 gdb/testsuite/gdb.fortran/vla.f90           |  10 +
b2f73e
 gdb/valarith.c                              |  10 +-
b2f73e
 gdb/valops.c                                | 197 +++++++++++--
b2f73e
 gdb/value.h                                 |   2 +
b2f73e
 23 files changed, 1242 insertions(+), 183 deletions(-)
b2f73e
b2f73e
diff --git a/gdb/eval.c b/gdb/eval.c
b2f73e
--- a/gdb/eval.c
b2f73e
+++ b/gdb/eval.c
b2f73e
@@ -372,29 +372,324 @@ init_array_element (struct value *array, struct value *element,
b2f73e
   return index;
b2f73e
 }
b2f73e
 
b2f73e
+/* Evaluates any operation on Fortran arrays or strings with at least
b2f73e
+   one user provided parameter.  Expects the input ARRAY to be either
b2f73e
+   an array, or a string.  Evaluates EXP by incrementing POS, and
b2f73e
+   writes the content from the elt stack into a local struct.  NARGS
b2f73e
+   specifies number of literal or range arguments the user provided.
b2f73e
+   NARGS must be the same number as ARRAY has dimensions.  */
b2f73e
+
b2f73e
 static struct value *
b2f73e
-value_f90_subarray (struct value *array,
b2f73e
-		    struct expression *exp, int *pos, enum noside noside)
b2f73e
+value_f90_subarray (struct value *array, struct expression *exp,
b2f73e
+		    int *pos, int nargs, enum noside noside)
b2f73e
 {
b2f73e
-  int pc = (*pos) + 1;
b2f73e
-  LONGEST low_bound, high_bound;
b2f73e
-  struct type *range = check_typedef (TYPE_INDEX_TYPE (value_type (array)));
b2f73e
-  enum range_type range_type
b2f73e
-    = (enum range_type) longest_to_int (exp->elts[pc].longconst);
b2f73e
- 
b2f73e
-  *pos += 3;
b2f73e
-
b2f73e
-  if (range_type == LOW_BOUND_DEFAULT || range_type == BOTH_BOUND_DEFAULT)
b2f73e
-    low_bound = TYPE_LOW_BOUND (range);
b2f73e
-  else
b2f73e
-    low_bound = value_as_long (evaluate_subexp (NULL_TYPE, exp, pos, noside));
b2f73e
+  int i, dim_count = 0;
b2f73e
+  struct value *new_array = array;
b2f73e
+  struct type *array_type = check_typedef (value_type (new_array));
b2f73e
+  struct type *elt_type;
b2f73e
+
b2f73e
+  typedef struct
b2f73e
+  {
b2f73e
+    enum range_type f90_range_type;
b2f73e
+    LONGEST low, high, stride;
b2f73e
+  } subscript_range;
b2f73e
+
b2f73e
+  typedef enum subscript_kind
b2f73e
+  {
b2f73e
+    SUBSCRIPT_RANGE,    /* e.g. "(lowbound:highbound)"  */
b2f73e
+    SUBSCRIPT_INDEX    /* e.g. "(literal)"  */
b2f73e
+  } kind;
b2f73e
+
b2f73e
+  /* Local struct to hold user data for Fortran subarray dimensions.  */
b2f73e
+  struct subscript_store
b2f73e
+  {
b2f73e
+    /* For every dimension, we are either working on a range or an index
b2f73e
+       expression, so we store this info separately for later.  */
b2f73e
+    enum subscript_kind kind;
b2f73e
+
b2f73e
+    /* We also store either the lower and upper bound info, or the index
b2f73e
+       number.  Before evaluation of the input values, we do not know if we are
b2f73e
+       actually working on a range of ranges, or an index in a range.  So as a
b2f73e
+       first step we store all input in a union.  The array calculation itself
b2f73e
+       deals with this later on.  */
b2f73e
+    union element_range
b2f73e
+    {
b2f73e
+      subscript_range range;
b2f73e
+      LONGEST number;
b2f73e
+    } U;
b2f73e
+  } *subscript_array;
b2f73e
+
b2f73e
+  /* Check if the number of arguments provided by the user matches
b2f73e
+     the number of dimension of the array.  A string has only one
b2f73e
+     dimension.  */
b2f73e
+  if (nargs != calc_f77_array_dims (value_type (new_array)))
b2f73e
+    error (_("Wrong number of subscripts"));
b2f73e
+
b2f73e
+  subscript_array = (struct subscript_store*) alloca (sizeof (*subscript_array) * nargs);
b2f73e
+
b2f73e
+  /* Parse the user input into the SUBSCRIPT_ARRAY to store it.  We need
b2f73e
+     to evaluate it first, as the input is from left-to-right.  The
b2f73e
+     array is stored from right-to-left.  So we have to use the user
b2f73e
+     input in reverse order.  Later on, we need the input information to
b2f73e
+     re-calculate the output array.  For multi-dimensional arrays, we
b2f73e
+     can be dealing with any possible combination of ranges and indices
b2f73e
+     for every dimension.  */
b2f73e
+  for (i = 0; i < nargs; i++)
b2f73e
+    {
b2f73e
+      struct subscript_store *index = &subscript_array[i];
b2f73e
+
b2f73e
+      /* The user input is a range, with or without lower and upper bound.
b2f73e
+	 E.g.: "p arry(2:5)", "p arry( :5)", "p arry( : )", etc.  */
b2f73e
+      if (exp->elts[*pos].opcode == OP_RANGE)
b2f73e
+	{
b2f73e
+	  int pc = (*pos) + 1;
b2f73e
+	  subscript_range *range;
b2f73e
+
b2f73e
+	  index->kind = SUBSCRIPT_RANGE;
b2f73e
+	  range = &index->U.range;
b2f73e
+
b2f73e
+	  *pos += 3;
b2f73e
+	  range->f90_range_type = (enum range_type) exp->elts[pc].longconst;
b2f73e
+
b2f73e
+	  /* If a lower bound was provided by the user, the bit has been
b2f73e
+	     set and we can assign the value from the elt stack.  Same for
b2f73e
+	     upper bound.  */
b2f73e
+	  if ((range->f90_range_type & SUBARRAY_LOW_BOUND)
b2f73e
+	      == SUBARRAY_LOW_BOUND)
b2f73e
+	    range->low = value_as_long (evaluate_subexp (NULL_TYPE, exp,
b2f73e
+							 pos, noside));
b2f73e
+	  if ((range->f90_range_type & SUBARRAY_HIGH_BOUND)
b2f73e
+	      == SUBARRAY_HIGH_BOUND)
b2f73e
+	    range->high = value_as_long (evaluate_subexp (NULL_TYPE, exp,
b2f73e
+							  pos, noside));
b2f73e
+
b2f73e
+	  /* Assign the user's stride value if provided.  */
b2f73e
+	  if ((range->f90_range_type & SUBARRAY_STRIDE) == SUBARRAY_STRIDE)
b2f73e
+	    range->stride = value_as_long (evaluate_subexp (NULL_TYPE, exp,
b2f73e
+							     pos, noside));
b2f73e
+
b2f73e
+	  /* Assign the default stride value '1'.  */
b2f73e
+	  else
b2f73e
+	    range->stride = 1;
b2f73e
 
b2f73e
-  if (range_type == HIGH_BOUND_DEFAULT || range_type == BOTH_BOUND_DEFAULT)
b2f73e
-    high_bound = TYPE_HIGH_BOUND (range);
b2f73e
-  else
b2f73e
-    high_bound = value_as_long (evaluate_subexp (NULL_TYPE, exp, pos, noside));
b2f73e
+	  /* Check the provided stride value is illegal, aka '0'.  */
b2f73e
+	  if (range->stride == 0)
b2f73e
+	    error (_("Stride must not be 0"));
b2f73e
+	}
b2f73e
+      /* User input is an index.  E.g.: "p arry(5)".  */
b2f73e
+      else
b2f73e
+	{
b2f73e
+	  struct value *val;
b2f73e
+
b2f73e
+	  index->kind = SUBSCRIPT_INDEX;
b2f73e
+
b2f73e
+	  /* Evaluate each subscript; it must be a legal integer in F77.  This
b2f73e
+	     ensures the validity of the provided index.  */
b2f73e
+	  val = evaluate_subexp_with_coercion (exp, pos, noside);
b2f73e
+	  index->U.number = value_as_long (val);
b2f73e
+	}
b2f73e
+
b2f73e
+    }
b2f73e
+
b2f73e
+  /* Traverse the array from right to left and set the high and low bounds
b2f73e
+     for later use.  */
b2f73e
+  for (i = nargs - 1; i >= 0; i--)
b2f73e
+    {
b2f73e
+      struct subscript_store *index = &subscript_array[i];
b2f73e
+      struct type *index_type = TYPE_INDEX_TYPE (array_type);
b2f73e
+
b2f73e
+      switch (index->kind)
b2f73e
+	{
b2f73e
+	case SUBSCRIPT_RANGE:
b2f73e
+	  {
b2f73e
+
b2f73e
+	    /* When we hit the first range specified by the user, we must
b2f73e
+	       treat any subsequent user entry as a range.  We simply
b2f73e
+	       increment DIM_COUNT which tells us how many times we are
b2f73e
+	       calling VALUE_SLICE_1.  */
b2f73e
+	    subscript_range *range = &index->U.range;
b2f73e
+
b2f73e
+	    /* If no lower bound was provided by the user, we take the
b2f73e
+	       default boundary.  Same for the high bound.  */
b2f73e
+	    if ((range->f90_range_type & SUBARRAY_LOW_BOUND) == 0)
b2f73e
+	      range->low = TYPE_LOW_BOUND (index_type);
b2f73e
+
b2f73e
+	    if ((range->f90_range_type & SUBARRAY_HIGH_BOUND) == 0)
b2f73e
+	      range->high = TYPE_HIGH_BOUND (index_type);
b2f73e
+
b2f73e
+	    /* Both user provided low and high bound have to be inside the
b2f73e
+	       array bounds.  Throw an error if not.  */
b2f73e
+	    if (range->low < TYPE_LOW_BOUND (index_type)
b2f73e
+		|| range->low > TYPE_HIGH_BOUND (index_type)
b2f73e
+		|| range->high < TYPE_LOW_BOUND (index_type)
b2f73e
+		|| range->high > TYPE_HIGH_BOUND (index_type))
b2f73e
+	      error (_("provided bound(s) outside array bound(s)"));
b2f73e
+
b2f73e
+	    /* For a negative stride the lower boundary must be larger than the
b2f73e
+	       upper boundary.
b2f73e
+	       For a positive stride the lower boundary must be smaller than the
b2f73e
+	       upper boundary.  */
b2f73e
+	    if ((range->stride < 0 && range->low < range->high)
b2f73e
+		|| (range->stride > 0 && range->low > range->high))
b2f73e
+	      error (_("Wrong value provided for stride and boundaries"));
b2f73e
+
b2f73e
+	  }
b2f73e
+	  break;
b2f73e
+
b2f73e
+	case SUBSCRIPT_INDEX:
b2f73e
+	  break;
b2f73e
+
b2f73e
+	}
b2f73e
+
b2f73e
+       array_type = TYPE_TARGET_TYPE (array_type);
b2f73e
+    }
b2f73e
+
b2f73e
+  /* Reset ARRAY_TYPE before slicing.*/
b2f73e
+  array_type = check_typedef (value_type (new_array));
b2f73e
+
b2f73e
+  /* Traverse the array from right to left and evaluate each corresponding
b2f73e
+     user input.  VALUE_SUBSCRIPT is called for every index, until a range
b2f73e
+     expression is evaluated.  After a range expression has been evaluated,
b2f73e
+     every subsequent expression is also treated as a range.  */
b2f73e
+  for (i = nargs - 1; i >= 0; i--)
b2f73e
+    {
b2f73e
+      struct subscript_store *index = &subscript_array[i];
b2f73e
+      struct type *index_type = TYPE_INDEX_TYPE (array_type);
b2f73e
+
b2f73e
+      switch (index->kind)
b2f73e
+	{
b2f73e
+	case SUBSCRIPT_RANGE:
b2f73e
+	  {
b2f73e
+
b2f73e
+	    /* When we hit the first range specified by the user, we must
b2f73e
+	       treat any subsequent user entry as a range.  We simply
b2f73e
+	       increment DIM_COUNT which tells us how many times we are
b2f73e
+	       calling VALUE_SLICE_1.  */
b2f73e
+	    subscript_range *range = &index->U.range;
b2f73e
+
b2f73e
+	    /* DIM_COUNT counts every user argument that is treated as a range.
b2f73e
+	       This is necessary for expressions like 'print array(7, 8:9).
b2f73e
+	       Here the first argument is a literal, but must be treated as a
b2f73e
+	       range argument to allow the correct output representation.  */
b2f73e
+	    dim_count++;
b2f73e
+
b2f73e
+	    new_array
b2f73e
+	      = value_slice_1 (new_array, range->low,
b2f73e
+			       range->high - range->low + 1,
b2f73e
+			       range->stride, dim_count);
b2f73e
+	  }
b2f73e
+	  break;
b2f73e
+
b2f73e
+	case SUBSCRIPT_INDEX:
b2f73e
+	  {
b2f73e
+	    /* DIM_COUNT only stays '0' when no range argument was processed
b2f73e
+	       before, starting from the last dimension.  This way we can
b2f73e
+	       reduce the number of dimensions from the result array.
b2f73e
+	       However, if a range has been processed before an index, we
b2f73e
+	       treat the index like a range with equal low- and high bounds
b2f73e
+	       to get the value offset right.  */
b2f73e
+	    if (dim_count == 0)
b2f73e
+	      new_array
b2f73e
+	        = value_subscripted_rvalue (new_array, index->U.number,
b2f73e
+					    f77_get_lowerbound (value_type
b2f73e
+								  (new_array)));
b2f73e
+	    else
b2f73e
+	      {
b2f73e
+		dim_count++;
b2f73e
+
b2f73e
+		/* We might end up here, because we have to treat the provided
b2f73e
+		   index like a range. But now VALUE_SUBSCRIPTED_RVALUE
b2f73e
+		   cannot do the range checks for us. So we have to make sure
b2f73e
+		   ourselves that the user provided index is inside the
b2f73e
+		   array bounds.  Throw an error if not.  */
b2f73e
+		if (index->U.number < TYPE_LOW_BOUND (index_type)
b2f73e
+		    && index->U.number > TYPE_HIGH_BOUND (index_type))
b2f73e
+		  error (_("provided bound(s) outside array bound(s)"));
b2f73e
+
b2f73e
+		if (index->U.number > TYPE_LOW_BOUND (index_type)
b2f73e
+		    && index->U.number > TYPE_HIGH_BOUND (index_type))
b2f73e
+		  error (_("provided bound(s) outside array bound(s)"));
b2f73e
+
b2f73e
+		new_array = value_slice_1 (new_array,
b2f73e
+					   index->U.number,
b2f73e
+					   1, /* COUNT is '1' element  */
b2f73e
+					   1, /* STRIDE set to '1'  */
b2f73e
+					   dim_count);
b2f73e
+	      }
b2f73e
+
b2f73e
+	  }
b2f73e
+	  break;
b2f73e
+	}
b2f73e
+      array_type = TYPE_TARGET_TYPE (array_type);
b2f73e
+    }
b2f73e
+
b2f73e
+  /* With DIM_COUNT > 1 we currently have a one dimensional array, but expect
b2f73e
+     an array of arrays, depending on how many ranges have been provided by
b2f73e
+     the user.  So we need to rebuild the array dimensions for printing it
b2f73e
+     correctly.
b2f73e
+     Starting from right to left in the user input, after we hit the first
b2f73e
+     range argument every subsequent argument is also treated as a range.
b2f73e
+     E.g.:
b2f73e
+     "p ary(3, 7, 2:15)" in Fortran has only 1 dimension, but we calculated 3
b2f73e
+     ranges.
b2f73e
+     "p ary(3, 7:12, 4)" in Fortran has only 1 dimension, but we calculated 2
b2f73e
+     ranges.
b2f73e
+     "p ary(2:4, 5, 7)" in Fortran has only 1 dimension, and we calculated 1
b2f73e
+     range.  */
b2f73e
+  if (dim_count > 1)
b2f73e
+    {
b2f73e
+      struct value *v = NULL;
b2f73e
+
b2f73e
+      elt_type = TYPE_TARGET_TYPE (value_type (new_array));
b2f73e
 
b2f73e
-  return value_slice (array, low_bound, high_bound - low_bound + 1);
b2f73e
+      /* Every SUBSCRIPT_RANGE in the user input signifies an actual range in
b2f73e
+	 the output array.  So we traverse the SUBSCRIPT_ARRAY again, looking
b2f73e
+	 for a range entry.  When we find one, we use the range info to create
b2f73e
+	 an additional range_type to set the correct bounds and dimensions for
b2f73e
+	 the output array.  In addition, we may have a stride value that is not
b2f73e
+	 '1', forcing us to adjust the number of elements in a range, according
b2f73e
+	 to the stride value.  */
b2f73e
+      for (i = 0; i < nargs; i++)
b2f73e
+	{
b2f73e
+	  struct subscript_store *index = &subscript_array[i];
b2f73e
+
b2f73e
+	  if (index->kind == SUBSCRIPT_RANGE)
b2f73e
+	    {
b2f73e
+	      struct type *range_type, *interim_array_type;
b2f73e
+
b2f73e
+	      int new_length;
b2f73e
+
b2f73e
+	      /* The length of a sub-dimension with all elements between the
b2f73e
+		 bounds plus the start element itself.  It may be modified by
b2f73e
+		 a user provided stride value.  */
b2f73e
+	      new_length = index->U.range.high - index->U.range.low;
b2f73e
+
b2f73e
+	      new_length /= index->U.range.stride;
b2f73e
+
b2f73e
+	      range_type
b2f73e
+		= create_static_range_type (NULL,
b2f73e
+					    elt_type,
b2f73e
+					    index->U.range.low,
b2f73e
+					    index->U.range.low + new_length);
b2f73e
+
b2f73e
+	      interim_array_type = create_array_type (NULL,
b2f73e
+						      elt_type,
b2f73e
+						      range_type);
b2f73e
+
b2f73e
+	      TYPE_CODE (interim_array_type)
b2f73e
+		= TYPE_CODE (value_type (new_array));
b2f73e
+
b2f73e
+	      v = allocate_value (interim_array_type);
b2f73e
+
b2f73e
+	      elt_type = value_type (v);
b2f73e
+	    }
b2f73e
+
b2f73e
+	}
b2f73e
+      value_contents_copy (v, 0, new_array, 0, TYPE_LENGTH (elt_type));
b2f73e
+      return v;
b2f73e
+    }
b2f73e
+
b2f73e
+  return new_array;
b2f73e
 }
b2f73e
 
b2f73e
 
b2f73e
@@ -1235,19 +1530,6 @@ evaluate_funcall (type *expect_type, expression *exp, int *pos,
b2f73e
   return eval_call (exp, noside, nargs, argvec, var_func_name, expect_type);
b2f73e
 }
b2f73e
 
b2f73e
-/* Helper for skipping all the arguments in an undetermined argument list.
b2f73e
-   This function was designed for use in the OP_F77_UNDETERMINED_ARGLIST
b2f73e
-   case of evaluate_subexp_standard as multiple, but not all, code paths
b2f73e
-   require a generic skip.  */
b2f73e
-
b2f73e
-static void
b2f73e
-skip_undetermined_arglist (int nargs, struct expression *exp, int *pos,
b2f73e
-			   enum noside noside)
b2f73e
-{
b2f73e
-  for (int i = 0; i < nargs; ++i)
b2f73e
-    evaluate_subexp (NULL_TYPE, exp, pos, noside);
b2f73e
-}
b2f73e
-
b2f73e
 struct value *
b2f73e
 evaluate_subexp_standard (struct type *expect_type,
b2f73e
 			  struct expression *exp, int *pos,
b2f73e
@@ -1942,33 +2224,8 @@ evaluate_subexp_standard (struct type *expect_type,
b2f73e
       switch (code)
b2f73e
 	{
b2f73e
 	case TYPE_CODE_ARRAY:
b2f73e
-	  if (exp->elts[*pos].opcode == OP_RANGE)
b2f73e
-	    return value_f90_subarray (arg1, exp, pos, noside);
b2f73e
-	  else
b2f73e
-	    {
b2f73e
-	      if (noside == EVAL_SKIP)
b2f73e
-		{
b2f73e
-		  skip_undetermined_arglist (nargs, exp, pos, noside);
b2f73e
-		  /* Return the dummy value with the correct type.  */
b2f73e
-		  return arg1;
b2f73e
-		}
b2f73e
-	      goto multi_f77_subscript;
b2f73e
-	    }
b2f73e
-
b2f73e
 	case TYPE_CODE_STRING:
b2f73e
-	  if (exp->elts[*pos].opcode == OP_RANGE)
b2f73e
-	    return value_f90_subarray (arg1, exp, pos, noside);
b2f73e
-	  else
b2f73e
-	    {
b2f73e
-	      if (noside == EVAL_SKIP)
b2f73e
-		{
b2f73e
-		  skip_undetermined_arglist (nargs, exp, pos, noside);
b2f73e
-		  /* Return the dummy value with the correct type.  */
b2f73e
-		  return arg1;
b2f73e
-		}
b2f73e
-	      arg2 = evaluate_subexp_with_coercion (exp, pos, noside);
b2f73e
-	      return value_subscript (arg1, value_as_long (arg2));
b2f73e
-	    }
b2f73e
+	  return value_f90_subarray (arg1, exp, pos, nargs, noside);
b2f73e
 
b2f73e
 	case TYPE_CODE_PTR:
b2f73e
 	case TYPE_CODE_FUNC:
b2f73e
@@ -2388,49 +2645,6 @@ evaluate_subexp_standard (struct type *expect_type,
b2f73e
 	}
b2f73e
       return (arg1);
b2f73e
 
b2f73e
-    multi_f77_subscript:
b2f73e
-      {
b2f73e
-	LONGEST subscript_array[MAX_FORTRAN_DIMS];
b2f73e
-	int ndimensions = 1, i;
b2f73e
-	struct value *array = arg1;
b2f73e
-
b2f73e
-	if (nargs > MAX_FORTRAN_DIMS)
b2f73e
-	  error (_("Too many subscripts for F77 (%d Max)"), MAX_FORTRAN_DIMS);
b2f73e
-
b2f73e
-	ndimensions = calc_f77_array_dims (type);
b2f73e
-
b2f73e
-	if (nargs != ndimensions)
b2f73e
-	  error (_("Wrong number of subscripts"));
b2f73e
-
b2f73e
-	gdb_assert (nargs > 0);
b2f73e
-
b2f73e
-	/* Now that we know we have a legal array subscript expression 
b2f73e
-	   let us actually find out where this element exists in the array.  */
b2f73e
-
b2f73e
-	/* Take array indices left to right.  */
b2f73e
-	for (i = 0; i < nargs; i++)
b2f73e
-	  {
b2f73e
-	    /* Evaluate each subscript; it must be a legal integer in F77.  */
b2f73e
-	    arg2 = evaluate_subexp_with_coercion (exp, pos, noside);
b2f73e
-
b2f73e
-	    /* Fill in the subscript array.  */
b2f73e
-
b2f73e
-	    subscript_array[i] = value_as_long (arg2);
b2f73e
-	  }
b2f73e
-
b2f73e
-	/* Internal type of array is arranged right to left.  */
b2f73e
-	for (i = nargs; i > 0; i--)
b2f73e
-	  {
b2f73e
-	    struct type *array_type = check_typedef (value_type (array));
b2f73e
-	    LONGEST index = subscript_array[i - 1];
b2f73e
-
b2f73e
-	    array = value_subscripted_rvalue (array, index,
b2f73e
-					      f77_get_lowerbound (array_type));
b2f73e
-	  }
b2f73e
-
b2f73e
-	return array;
b2f73e
-      }
b2f73e
-
b2f73e
     case BINOP_LOGICAL_AND:
b2f73e
       arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
b2f73e
       if (noside == EVAL_SKIP)
b2f73e
@@ -3350,6 +3564,9 @@ calc_f77_array_dims (struct type *array_type)
b2f73e
   int ndimen = 1;
b2f73e
   struct type *tmp_type;
b2f73e
 
b2f73e
+  if (TYPE_CODE (array_type) == TYPE_CODE_STRING)
b2f73e
+    return 1;
b2f73e
+
b2f73e
   if ((TYPE_CODE (array_type) != TYPE_CODE_ARRAY))
b2f73e
     error (_("Can't get dimensions for a non-array type"));
b2f73e
 
b2f73e
diff --git a/gdb/expprint.c b/gdb/expprint.c
b2f73e
--- a/gdb/expprint.c
b2f73e
+++ b/gdb/expprint.c
b2f73e
@@ -580,17 +580,14 @@ print_subexp_standard (struct expression *exp, int *pos,
b2f73e
 	  longest_to_int (exp->elts[pc + 1].longconst);
b2f73e
 	*pos += 2;
b2f73e
 
b2f73e
-	if (range_type == NONE_BOUND_DEFAULT_EXCLUSIVE
b2f73e
-	    || range_type == LOW_BOUND_DEFAULT_EXCLUSIVE)
b2f73e
+	if ((range_type & SUBARRAY_HIGH_BOUND_EXCLUSIVE)
b2f73e
+	    == SUBARRAY_HIGH_BOUND_EXCLUSIVE)
b2f73e
 	  fputs_filtered ("EXCLUSIVE_", stream);
b2f73e
 	fputs_filtered ("RANGE(", stream);
b2f73e
-	if (range_type == HIGH_BOUND_DEFAULT
b2f73e
-	    || range_type == NONE_BOUND_DEFAULT
b2f73e
-	    || range_type == NONE_BOUND_DEFAULT_EXCLUSIVE)
b2f73e
+	if ((range_type & SUBARRAY_LOW_BOUND) == SUBARRAY_LOW_BOUND)
b2f73e
 	  print_subexp (exp, pos, stream, PREC_ABOVE_COMMA);
b2f73e
 	fputs_filtered ("..", stream);
b2f73e
-	if (range_type == LOW_BOUND_DEFAULT
b2f73e
-	    || range_type == NONE_BOUND_DEFAULT)
b2f73e
+	if ((range_type & SUBARRAY_HIGH_BOUND) == SUBARRAY_HIGH_BOUND)
b2f73e
 	  print_subexp (exp, pos, stream, PREC_ABOVE_COMMA);
b2f73e
 	fputs_filtered (")", stream);
b2f73e
 	return;
b2f73e
@@ -1107,22 +1104,24 @@ dump_subexp_body_standard (struct expression *exp,
b2f73e
 
b2f73e
 	switch (range_type)
b2f73e
 	  {
b2f73e
-	  case BOTH_BOUND_DEFAULT:
b2f73e
+	  case SUBARRAY_NONE_BOUND:
b2f73e
 	    fputs_filtered ("Range '..'", stream);
b2f73e
 	    break;
b2f73e
-	  case LOW_BOUND_DEFAULT:
b2f73e
+	  case SUBARRAY_HIGH_BOUND:
b2f73e
 	    fputs_filtered ("Range '..EXP'", stream);
b2f73e
 	    break;
b2f73e
-	  case LOW_BOUND_DEFAULT_EXCLUSIVE:
b2f73e
-	    fputs_filtered ("ExclusiveRange '..EXP'", stream);
b2f73e
-	    break;
b2f73e
-	  case HIGH_BOUND_DEFAULT:
b2f73e
+	  case SUBARRAY_LOW_BOUND:
b2f73e
 	    fputs_filtered ("Range 'EXP..'", stream);
b2f73e
 	    break;
b2f73e
-	  case NONE_BOUND_DEFAULT:
b2f73e
+	  case (SUBARRAY_LOW_BOUND
b2f73e
+		| SUBARRAY_HIGH_BOUND
b2f73e
+		| SUBARRAY_HIGH_BOUND_EXCLUSIVE):
b2f73e
+	    fputs_filtered ("ExclusiveRange '..EXP'", stream);
b2f73e
+	    break;
b2f73e
+	  case (SUBARRAY_LOW_BOUND | SUBARRAY_HIGH_BOUND):
b2f73e
 	    fputs_filtered ("Range 'EXP..EXP'", stream);
b2f73e
 	    break;
b2f73e
-	  case NONE_BOUND_DEFAULT_EXCLUSIVE:
b2f73e
+	  case (SUBARRAY_HIGH_BOUND | SUBARRAY_HIGH_BOUND_EXCLUSIVE):
b2f73e
 	    fputs_filtered ("ExclusiveRange 'EXP..EXP'", stream);
b2f73e
 	    break;
b2f73e
 	  default:
b2f73e
@@ -1130,11 +1129,9 @@ dump_subexp_body_standard (struct expression *exp,
b2f73e
 	    break;
b2f73e
 	  }
b2f73e
 
b2f73e
-	if (range_type == HIGH_BOUND_DEFAULT
b2f73e
-	    || range_type == NONE_BOUND_DEFAULT)
b2f73e
+	if ((range_type & SUBARRAY_LOW_BOUND) == SUBARRAY_LOW_BOUND)
b2f73e
 	  elt = dump_subexp (exp, stream, elt);
b2f73e
-	if (range_type == LOW_BOUND_DEFAULT
b2f73e
-	    || range_type == NONE_BOUND_DEFAULT)
b2f73e
+	if ((range_type & SUBARRAY_HIGH_BOUND) == SUBARRAY_HIGH_BOUND)
b2f73e
 	  elt = dump_subexp (exp, stream, elt);
b2f73e
       }
b2f73e
       break;
b2f73e
diff --git a/gdb/expression.h b/gdb/expression.h
b2f73e
--- a/gdb/expression.h
b2f73e
+++ b/gdb/expression.h
b2f73e
@@ -167,28 +167,27 @@ extern void dump_raw_expression (struct expression *,
b2f73e
 				 struct ui_file *, const char *);
b2f73e
 extern void dump_prefix_expression (struct expression *, struct ui_file *);
b2f73e
 
b2f73e
-/* In an OP_RANGE expression, either bound could be empty, indicating
b2f73e
-   that its value is by default that of the corresponding bound of the
b2f73e
-   array or string.  Also, the upper end of the range can be exclusive
b2f73e
-   or inclusive.  So we have six sorts of subrange.  This enumeration
b2f73e
-   type is to identify this.  */
b2f73e
+/* In an OP_RANGE expression, either bound can be provided by the
b2f73e
+   user, or not.  In addition to this, the user can also specify a
b2f73e
+   stride value to indicated only certain elements of the array.
b2f73e
+   Also, the upper end of the range can be exclusive or inclusive.
b2f73e
+   This enumeration type is to identify this.  */
b2f73e
 
b2f73e
 enum range_type
b2f73e
-{
b2f73e
-  /* Neither the low nor the high bound was given -- so this refers to
b2f73e
-     the entire available range.  */
b2f73e
-  BOTH_BOUND_DEFAULT,
b2f73e
-  /* The low bound was not given and the high bound is inclusive.  */
b2f73e
-  LOW_BOUND_DEFAULT,
b2f73e
-  /* The high bound was not given and the low bound in inclusive.  */
b2f73e
-  HIGH_BOUND_DEFAULT,
b2f73e
-  /* Both bounds were given and both are inclusive.  */
b2f73e
-  NONE_BOUND_DEFAULT,
b2f73e
-  /* The low bound was not given and the high bound is exclusive.  */
b2f73e
-  NONE_BOUND_DEFAULT_EXCLUSIVE,
b2f73e
-  /* Both bounds were given.  The low bound is inclusive and the high
b2f73e
-     bound is exclusive.  */
b2f73e
-  LOW_BOUND_DEFAULT_EXCLUSIVE,
b2f73e
-};
b2f73e
+  {
b2f73e
+    SUBARRAY_NONE_BOUND = 0x0,		/* "( : )"  */
b2f73e
+    SUBARRAY_LOW_BOUND = 0x1,		/* "(low:)"  */
b2f73e
+    SUBARRAY_HIGH_BOUND = 0x2,		/* "(:high)"  */
b2f73e
+    SUBARRAY_STRIDE = 0x4,		/* "(::stride)"  */
b2f73e
+    /* The low bound was not given and the high bound is exclusive.
b2f73e
+       In this case we always use (SUBARRAY_HIGH_BOUND |
b2f73e
+       SUBARRAY_HIGH_BOUND_EXCLUSIVE).  */
b2f73e
+    SUBARRAY_HIGH_BOUND_EXCLUSIVE = 0x8,
b2f73e
+    /* Both bounds were given.  The low bound is inclusive and the high
b2f73e
+       bound is exclusive.  In this case, we use (SUBARRAY_LOW_BOUND |
b2f73e
+       SUBARRAY_HIGH_BOUND | SUBARRAY_HIGH_BOUND_EXCLUSIVE).  */
b2f73e
+    // SUBARRAY_LOW_BOUND_EXCLUSIVE = (SUBARRAY_LOW_BOUND
b2f73e
+    // 				    | SUBARRAY_HIGH_BOUND_EXCLUSIVE),
b2f73e
+  };
b2f73e
 
b2f73e
 #endif /* !defined (EXPRESSION_H) */
b2f73e
diff --git a/gdb/f-exp.y b/gdb/f-exp.y
b2f73e
--- a/gdb/f-exp.y
b2f73e
+++ b/gdb/f-exp.y
b2f73e
@@ -282,31 +282,63 @@ arglist :	subrange
b2f73e
    
b2f73e
 arglist	:	arglist ',' exp   %prec ABOVE_COMMA
b2f73e
 			{ pstate->arglist_len++; }
b2f73e
+	|	arglist ',' subrange	%prec ABOVE_COMMA
b2f73e
+			{ pstate->arglist_len++; }
b2f73e
 	;
b2f73e
 
b2f73e
 /* There are four sorts of subrange types in F90.  */
b2f73e
 
b2f73e
 subrange:	exp ':' exp	%prec ABOVE_COMMA
b2f73e
-			{ write_exp_elt_opcode (pstate, OP_RANGE); 
b2f73e
-			  write_exp_elt_longcst (pstate, NONE_BOUND_DEFAULT);
b2f73e
+			{ write_exp_elt_opcode (pstate, OP_RANGE);
b2f73e
+			  write_exp_elt_longcst (pstate,
b2f73e
+						 SUBARRAY_LOW_BOUND | SUBARRAY_HIGH_BOUND);
b2f73e
 			  write_exp_elt_opcode (pstate, OP_RANGE); }
b2f73e
 	;
b2f73e
 
b2f73e
 subrange:	exp ':'	%prec ABOVE_COMMA
b2f73e
 			{ write_exp_elt_opcode (pstate, OP_RANGE);
b2f73e
-			  write_exp_elt_longcst (pstate, HIGH_BOUND_DEFAULT);
b2f73e
+			  write_exp_elt_longcst (pstate, SUBARRAY_LOW_BOUND);
b2f73e
 			  write_exp_elt_opcode (pstate, OP_RANGE); }
b2f73e
 	;
b2f73e
 
b2f73e
 subrange:	':' exp	%prec ABOVE_COMMA
b2f73e
 			{ write_exp_elt_opcode (pstate, OP_RANGE);
b2f73e
-			  write_exp_elt_longcst (pstate, LOW_BOUND_DEFAULT);
b2f73e
+			  write_exp_elt_longcst (pstate, SUBARRAY_HIGH_BOUND);
b2f73e
 			  write_exp_elt_opcode (pstate, OP_RANGE); }
b2f73e
 	;
b2f73e
 
b2f73e
 subrange:	':'	%prec ABOVE_COMMA
b2f73e
 			{ write_exp_elt_opcode (pstate, OP_RANGE);
b2f73e
-			  write_exp_elt_longcst (pstate, BOTH_BOUND_DEFAULT);
b2f73e
+			  write_exp_elt_longcst (pstate, SUBARRAY_NONE_BOUND);
b2f73e
+			  write_exp_elt_opcode (pstate, OP_RANGE); }
b2f73e
+	;
b2f73e
+
b2f73e
+/* Each subrange type can have a stride argument.  */
b2f73e
+subrange:	exp ':' exp ':' exp %prec ABOVE_COMMA
b2f73e
+			{ write_exp_elt_opcode (pstate, OP_RANGE);
b2f73e
+			  write_exp_elt_longcst (pstate, SUBARRAY_LOW_BOUND
b2f73e
+						 | SUBARRAY_HIGH_BOUND
b2f73e
+						 | SUBARRAY_STRIDE);
b2f73e
+			  write_exp_elt_opcode (pstate, OP_RANGE); }
b2f73e
+	;
b2f73e
+
b2f73e
+subrange:	exp ':' ':' exp %prec ABOVE_COMMA
b2f73e
+			{ write_exp_elt_opcode (pstate, OP_RANGE);
b2f73e
+			  write_exp_elt_longcst (pstate, SUBARRAY_LOW_BOUND
b2f73e
+						 | SUBARRAY_STRIDE);
b2f73e
+			  write_exp_elt_opcode (pstate, OP_RANGE); }
b2f73e
+	;
b2f73e
+
b2f73e
+subrange:	':' exp ':' exp %prec ABOVE_COMMA
b2f73e
+			{ write_exp_elt_opcode (pstate, OP_RANGE);
b2f73e
+			  write_exp_elt_longcst (pstate, SUBARRAY_HIGH_BOUND
b2f73e
+						 | SUBARRAY_STRIDE);
b2f73e
+			  write_exp_elt_opcode (pstate, OP_RANGE); }
b2f73e
+	;
b2f73e
+
b2f73e
+subrange:	':' ':' exp %prec ABOVE_COMMA
b2f73e
+			{ write_exp_elt_opcode (pstate, OP_RANGE);
b2f73e
+			  write_exp_elt_longcst (pstate, SUBARRAY_STRIDE);
b2f73e
 			  write_exp_elt_opcode (pstate, OP_RANGE); }
b2f73e
 	;
b2f73e
 
b2f73e
diff --git a/gdb/f-valprint.c b/gdb/f-valprint.c
b2f73e
--- a/gdb/f-valprint.c
b2f73e
+++ b/gdb/f-valprint.c
b2f73e
@@ -129,6 +129,11 @@ f77_print_array_1 (int nss, int ndimensions, struct type *type,
b2f73e
 	byte_stride = dim_size;
b2f73e
       size_t offs = 0;
b2f73e
 
b2f73e
+      if (byte_stride)
b2f73e
+        dim_size = byte_stride;
b2f73e
+      else
b2f73e
+        dim_size = TYPE_LENGTH (TYPE_TARGET_TYPE (type));
b2f73e
+
b2f73e
       for (i = lowerbound;
b2f73e
 	   (i < upperbound + 1 && (*elts) < options->print_max);
b2f73e
 	   i++)
b2f73e
diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c
b2f73e
--- a/gdb/gdbtypes.c
b2f73e
+++ b/gdb/gdbtypes.c
b2f73e
@@ -936,7 +936,7 @@ create_range_type (struct type *result_type, struct type *index_type,
b2f73e
   TYPE_RANGE_DATA (result_type)->high = *high_bound;
b2f73e
   TYPE_RANGE_DATA (result_type)->bias = bias;
b2f73e
 
b2f73e
-  /* Initialize the stride to be a constant, the value will already be zero
b2f73e
+  /* bias the stride to be a constant, the value will already be zero
b2f73e
      thanks to the use of TYPE_ZALLOC above.  */
b2f73e
   TYPE_RANGE_DATA (result_type)->stride.kind = PROP_CONST;
b2f73e
 
b2f73e
@@ -1001,7 +1001,8 @@ create_static_range_type (struct type *result_type, struct type *index_type,
b2f73e
   high.kind = PROP_CONST;
b2f73e
   high.data.const_val = high_bound;
b2f73e
 
b2f73e
-  result_type = create_range_type (result_type, index_type, &low, &high, 0);
b2f73e
+  result_type = create_range_type (result_type, index_type,
b2f73e
+                                   &low, &high, 0);
b2f73e
 
b2f73e
   return result_type;
b2f73e
 }
b2f73e
@@ -1236,6 +1237,7 @@ create_array_type_with_stride (struct type *result_type,
b2f73e
       if (get_discrete_bounds (range_type, &low_bound, &high_bound) < 0)
b2f73e
 	low_bound = high_bound = 0;
b2f73e
       element_type = check_typedef (element_type);
b2f73e
+
b2f73e
       /* Be careful when setting the array length.  Ada arrays can be
b2f73e
 	 empty arrays with the high_bound being smaller than the low_bound.
b2f73e
 	 In such cases, the array length should be zero.  */
b2f73e
diff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h
b2f73e
--- a/gdb/gdbtypes.h
b2f73e
+++ b/gdb/gdbtypes.h
b2f73e
@@ -803,7 +803,6 @@ struct main_type
b2f73e
     /* * Union member used for range types.  */
b2f73e
 
b2f73e
     struct range_bounds *bounds;
b2f73e
-
b2f73e
   } flds_bnds;
b2f73e
 
b2f73e
   /* * Slot to point to additional language-specific fields of this
b2f73e
@@ -1365,6 +1364,15 @@ extern bool set_type_align (struct type *, ULONGEST);
b2f73e
 #define TYPE_BIT_STRIDE(range_type) \
b2f73e
   (TYPE_RANGE_DATA(range_type)->stride.data.const_val \
b2f73e
    * (TYPE_RANGE_DATA(range_type)->flag_is_byte_stride ? 8 : 1))
b2f73e
+#define TYPE_BYTE_STRIDE(range_type) \
b2f73e
+  TYPE_RANGE_DATA(range_type)->stride.data.const_val
b2f73e
+#define TYPE_BYTE_STRIDE_BLOCK(range_type) \
b2f73e
+  TYPE_RANGE_DATA(range_type)->stride.data.locexpr
b2f73e
+#define TYPE_BYTE_STRIDE_LOCLIST(range_type) \
b2f73e
+  TYPE_RANGE_DATA(range_type)->stride.data.loclist
b2f73e
+#define TYPE_BYTE_STRIDE_KIND(range_type) \
b2f73e
+  TYPE_RANGE_DATA(range_type)->stride.kind
b2f73e
+
b2f73e
 
b2f73e
 /* Property accessors for the type data location.  */
b2f73e
 #define TYPE_DATA_LOCATION(thistype) \
b2f73e
@@ -1400,6 +1408,9 @@ extern bool set_type_align (struct type *, ULONGEST);
b2f73e
    TYPE_HIGH_BOUND_UNDEFINED(TYPE_INDEX_TYPE(arraytype))
b2f73e
 #define TYPE_ARRAY_LOWER_BOUND_IS_UNDEFINED(arraytype) \
b2f73e
    TYPE_LOW_BOUND_UNDEFINED(TYPE_INDEX_TYPE(arraytype))
b2f73e
+#define TYPE_ARRAY_STRIDE_IS_UNDEFINED(arraytype) \
b2f73e
+   (TYPE_BYTE_STRIDE(TYPE_INDEX_TYPE(arraytype)) == 0)
b2f73e
+
b2f73e
 
b2f73e
 #define TYPE_ARRAY_UPPER_BOUND_VALUE(arraytype) \
b2f73e
    (TYPE_HIGH_BOUND(TYPE_INDEX_TYPE((arraytype))))
b2f73e
diff --git a/gdb/parse.c b/gdb/parse.c
b2f73e
--- a/gdb/parse.c
b2f73e
+++ b/gdb/parse.c
b2f73e
@@ -919,24 +919,20 @@ operator_length_standard (const struct expression *expr, int endpos,
b2f73e
 
b2f73e
     case OP_RANGE:
b2f73e
       oplen = 3;
b2f73e
+      args = 0;
b2f73e
       range_type = (enum range_type)
b2f73e
 	longest_to_int (expr->elts[endpos - 2].longconst);
b2f73e
 
b2f73e
-      switch (range_type)
b2f73e
-	{
b2f73e
-	case LOW_BOUND_DEFAULT:
b2f73e
-	case LOW_BOUND_DEFAULT_EXCLUSIVE:
b2f73e
-	case HIGH_BOUND_DEFAULT:
b2f73e
-	  args = 1;
b2f73e
-	  break;
b2f73e
-	case BOTH_BOUND_DEFAULT:
b2f73e
-	  args = 0;
b2f73e
-	  break;
b2f73e
-	case NONE_BOUND_DEFAULT:
b2f73e
-	case NONE_BOUND_DEFAULT_EXCLUSIVE:
b2f73e
-	  args = 2;
b2f73e
-	  break;
b2f73e
-	}
b2f73e
+      /* Increment the argument counter for each argument
b2f73e
+	 provided by the user.  */
b2f73e
+      if ((range_type & SUBARRAY_LOW_BOUND) == SUBARRAY_LOW_BOUND)
b2f73e
+	args++;
b2f73e
+
b2f73e
+      if ((range_type & SUBARRAY_HIGH_BOUND) == SUBARRAY_HIGH_BOUND)
b2f73e
+	args++;
b2f73e
+
b2f73e
+      if ((range_type & SUBARRAY_STRIDE) == SUBARRAY_STRIDE)
b2f73e
+	args++;
b2f73e
 
b2f73e
       break;
b2f73e
 
b2f73e
diff --git a/gdb/rust-exp.y b/gdb/rust-exp.y
b2f73e
--- a/gdb/rust-exp.y
b2f73e
+++ b/gdb/rust-exp.y
b2f73e
@@ -2492,24 +2492,28 @@ rust_parser::convert_ast_to_expression (const struct rust_op *operation,
b2f73e
 
b2f73e
     case OP_RANGE:
b2f73e
       {
b2f73e
-	enum range_type kind = BOTH_BOUND_DEFAULT;
b2f73e
+	enum range_type kind = SUBARRAY_NONE_BOUND;
b2f73e
 
b2f73e
 	if (operation->left.op != NULL)
b2f73e
 	  {
b2f73e
 	    convert_ast_to_expression (operation->left.op, top);
b2f73e
-	    kind = HIGH_BOUND_DEFAULT;
b2f73e
+	    kind = SUBARRAY_LOW_BOUND;
b2f73e
 	  }
b2f73e
 	if (operation->right.op != NULL)
b2f73e
 	  {
b2f73e
 	    convert_ast_to_expression (operation->right.op, top);
b2f73e
-	    if (kind == BOTH_BOUND_DEFAULT)
b2f73e
-	      kind = (operation->inclusive
b2f73e
-		      ? LOW_BOUND_DEFAULT : LOW_BOUND_DEFAULT_EXCLUSIVE);
b2f73e
+	    if (kind == SUBARRAY_NONE_BOUND)
b2f73e
+	      {
b2f73e
+		kind = (range_type) SUBARRAY_HIGH_BOUND;
b2f73e
+		if (!operation->inclusive)
b2f73e
+		  kind = (range_type) (kind | SUBARRAY_HIGH_BOUND_EXCLUSIVE);
b2f73e
+	      }
b2f73e
 	    else
b2f73e
 	      {
b2f73e
-		gdb_assert (kind == HIGH_BOUND_DEFAULT);
b2f73e
-		kind = (operation->inclusive
b2f73e
-			? NONE_BOUND_DEFAULT : NONE_BOUND_DEFAULT_EXCLUSIVE);
b2f73e
+		gdb_assert (kind == SUBARRAY_LOW_BOUND);
b2f73e
+		kind = (range_type) (kind | SUBARRAY_HIGH_BOUND);
b2f73e
+		if (!operation->inclusive)
b2f73e
+		  kind = (range_type) (kind | SUBARRAY_HIGH_BOUND_EXCLUSIVE);
b2f73e
 	      }
b2f73e
 	  }
b2f73e
 	else
b2f73e
diff --git a/gdb/rust-lang.c b/gdb/rust-lang.c
b2f73e
--- a/gdb/rust-lang.c
b2f73e
+++ b/gdb/rust-lang.c
b2f73e
@@ -1224,13 +1224,11 @@ rust_range (struct expression *exp, int *pos, enum noside noside)
b2f73e
   kind = (enum range_type) longest_to_int (exp->elts[*pos + 1].longconst);
b2f73e
   *pos += 3;
b2f73e
 
b2f73e
-  if (kind == HIGH_BOUND_DEFAULT || kind == NONE_BOUND_DEFAULT
b2f73e
-      || kind == NONE_BOUND_DEFAULT_EXCLUSIVE)
b2f73e
+  if ((kind & SUBARRAY_LOW_BOUND) == SUBARRAY_LOW_BOUND)
b2f73e
     low = evaluate_subexp (NULL_TYPE, exp, pos, noside);
b2f73e
-  if (kind == LOW_BOUND_DEFAULT || kind == LOW_BOUND_DEFAULT_EXCLUSIVE
b2f73e
-      || kind == NONE_BOUND_DEFAULT || kind == NONE_BOUND_DEFAULT_EXCLUSIVE)
b2f73e
+  if ((kind & SUBARRAY_HIGH_BOUND) == SUBARRAY_HIGH_BOUND)
b2f73e
     high = evaluate_subexp (NULL_TYPE, exp, pos, noside);
b2f73e
-  bool inclusive = (kind == NONE_BOUND_DEFAULT || kind == LOW_BOUND_DEFAULT);
b2f73e
+  bool inclusive = (!((kind & SUBARRAY_HIGH_BOUND_EXCLUSIVE) == SUBARRAY_HIGH_BOUND_EXCLUSIVE));
b2f73e
 
b2f73e
   if (noside == EVAL_SKIP)
b2f73e
     return value_from_longest (builtin_type (exp->gdbarch)->builtin_int, 1);
b2f73e
@@ -1319,7 +1317,7 @@ rust_compute_range (struct type *type, struct value *range,
b2f73e
 
b2f73e
   *low = 0;
b2f73e
   *high = 0;
b2f73e
-  *kind = BOTH_BOUND_DEFAULT;
b2f73e
+  *kind = SUBARRAY_NONE_BOUND;
b2f73e
 
b2f73e
   if (TYPE_NFIELDS (type) == 0)
b2f73e
     return;
b2f73e
@@ -1327,15 +1325,14 @@ rust_compute_range (struct type *type, struct value *range,
b2f73e
   i = 0;
b2f73e
   if (strcmp (TYPE_FIELD_NAME (type, 0), "start") == 0)
b2f73e
     {
b2f73e
-      *kind = HIGH_BOUND_DEFAULT;
b2f73e
+      *kind = SUBARRAY_LOW_BOUND;
b2f73e
       *low = value_as_long (value_field (range, 0));
b2f73e
       ++i;
b2f73e
     }
b2f73e
   if (TYPE_NFIELDS (type) > i
b2f73e
       && strcmp (TYPE_FIELD_NAME (type, i), "end") == 0)
b2f73e
     {
b2f73e
-      *kind = (*kind == BOTH_BOUND_DEFAULT
b2f73e
-	       ? LOW_BOUND_DEFAULT : NONE_BOUND_DEFAULT);
b2f73e
+      *kind = (range_type) (*kind | SUBARRAY_HIGH_BOUND);
b2f73e
       *high = value_as_long (value_field (range, i));
b2f73e
 
b2f73e
       if (rust_inclusive_range_type_p (type))
b2f73e
@@ -1353,7 +1350,7 @@ rust_subscript (struct expression *exp, int *pos, enum noside noside,
b2f73e
   struct type *rhstype;
b2f73e
   LONGEST low, high_bound;
b2f73e
   /* Initialized to appease the compiler.  */
b2f73e
-  enum range_type kind = BOTH_BOUND_DEFAULT;
b2f73e
+  enum range_type kind = SUBARRAY_NONE_BOUND;
b2f73e
   LONGEST high = 0;
b2f73e
   int want_slice = 0;
b2f73e
 
b2f73e
@@ -1451,7 +1448,7 @@ rust_subscript (struct expression *exp, int *pos, enum noside noside,
b2f73e
 	error (_("Cannot subscript non-array type"));
b2f73e
 
b2f73e
       if (want_slice
b2f73e
-	  && (kind == BOTH_BOUND_DEFAULT || kind == LOW_BOUND_DEFAULT))
b2f73e
+	  && ((kind & SUBARRAY_LOW_BOUND) != SUBARRAY_LOW_BOUND))
b2f73e
 	low = low_bound;
b2f73e
       if (low < 0)
b2f73e
 	error (_("Index less than zero"));
b2f73e
@@ -1469,7 +1466,7 @@ rust_subscript (struct expression *exp, int *pos, enum noside noside,
b2f73e
 	  CORE_ADDR addr;
b2f73e
 	  struct value *addrval, *tem;
b2f73e
 
b2f73e
-	  if (kind == BOTH_BOUND_DEFAULT || kind == HIGH_BOUND_DEFAULT)
b2f73e
+	  if ((kind & SUBARRAY_HIGH_BOUND) != SUBARRAY_HIGH_BOUND)
b2f73e
 	    high = high_bound;
b2f73e
 	  if (high < 0)
b2f73e
 	    error (_("High index less than zero"));
b2f73e
diff --git a/gdb/testsuite/gdb.fortran/static-arrays.exp b/gdb/testsuite/gdb.fortran/static-arrays.exp
b2f73e
new file mode 100644
b2f73e
--- /dev/null
b2f73e
+++ b/gdb/testsuite/gdb.fortran/static-arrays.exp
b2f73e
@@ -0,0 +1,421 @@
b2f73e
+# Copyright 2015 Free Software Foundation, Inc.
b2f73e
+#
b2f73e
+# Contributed by Intel Corp. <christoph.t.weinmann@intel.com>
b2f73e
+#
b2f73e
+# This program is free software; you can redistribute it and/or modify
b2f73e
+# it under the terms of the GNU General Public License as published by
b2f73e
+# the Free Software Foundation; either version 3 of the License, or
b2f73e
+# (at your option) any later version.
b2f73e
+#
b2f73e
+# This program is distributed in the hope that it will be useful,
b2f73e
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
b2f73e
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
b2f73e
+# GNU General Public License for more details.
b2f73e
+#
b2f73e
+# You should have received a copy of the GNU General Public License
b2f73e
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
b2f73e
+
b2f73e
+standard_testfile static-arrays.f90
b2f73e
+
b2f73e
+if { [prepare_for_testing $testfile.exp $testfile $srcfile {debug f90}] } {
b2f73e
+    return -1
b2f73e
+}
b2f73e
+
b2f73e
+if ![runto MAIN__] then {
b2f73e
+    perror "couldn't run to breakpoint MAIN__"
b2f73e
+    continue
b2f73e
+}
b2f73e
+
b2f73e
+gdb_breakpoint [gdb_get_line_number "BP1"]
b2f73e
+gdb_continue_to_breakpoint "BP1" ".*BP1.*"
b2f73e
+
b2f73e
+# Tests subarrays of one dimensional arrays with subrange variations
b2f73e
+gdb_test "print ar1" "\\$\[0-9\]+ = \\(1, 2, 3, 4, 5, 6, 7, 8, 9\\)" \
b2f73e
+		"print ar1."
b2f73e
+gdb_test "print ar1\(4:7\)" "\\$\[0-9\]+ = \\(4, 5, 6, 7\\)" \
b2f73e
+		"print ar1\(4:7\)"
b2f73e
+gdb_test "print ar1\(8:\)" "\\$\[0-9\]+ = \\(8, 9\\).*" \
b2f73e
+		"print ar1\(8:\)"
b2f73e
+gdb_test "print ar1\(:3\)" "\\$\[0-9\]+ = \\(1, 2, 3\\).*" \
b2f73e
+		"print ar1\(:3\)"
b2f73e
+gdb_test "print ar1\(:\)" "\\$\[0-9\]+ = \\(1, 2, 3, 4, 5, 6, 7, 8, 9\\)" \
b2f73e
+		"print ar1\(:\)"
b2f73e
+
b2f73e
+# Check assignment
b2f73e
+gdb_test_no_output "set \$my_ary = ar1\(3:8\)"
b2f73e
+gdb_test "print \$my_ary" \
b2f73e
+		"\\$\[0-9\]+ = \\(3, 4, 5, 6, 7, 8\\)" \
b2f73e
+		"Assignment of subarray to variable"
b2f73e
+gdb_test_no_output "set ar1\(5\) = 42"
b2f73e
+		gdb_test "print ar1\(3:8\)" \
b2f73e
+		"\\$\[0-9\]+ = \\(3, 4, 42, 6, 7, 8\\)" \
b2f73e
+		"print ar1\(3:8\) after assignment"
b2f73e
+gdb_test "print \$my_ary" \
b2f73e
+		"\\$\[0-9\]+ = \\(3, 4, 5, 6, 7, 8\\)" \
b2f73e
+		"Assignment of subarray to variable after original array changed"
b2f73e
+
b2f73e
+# Test for subarrays of one dimensional arrays with literals
b2f73e
+		gdb_test "print ar1\(3\)" "\\$\[0-9\]+ = 3" \
b2f73e
+		"print ar1\(3\)"
b2f73e
+
b2f73e
+# Tests for subranges of 2 dimensional arrays with subrange variations
b2f73e
+gdb_test "print ar2\(2:3, 3:4\)" \
b2f73e
+		"\\$\[0-9\]+ = \\(\\( 23, 33\\) \\( 24, 34\\) \\)" \
b2f73e
+		"print ar2\(2:3, 3:4\)."
b2f73e
+gdb_test "print ar2\(8:9,8:\)" \
b2f73e
+		"\\$\[0-9\]+ = \\(\\( 88, 98\\) \\( 89, 99\\) \\)" \
b2f73e
+		"print ar2\(8:9,8:\)"
b2f73e
+gdb_test "print ar2\(8:9,:2\)" \
b2f73e
+		"\\$\[0-9\]+ = \\(\\( 81, 91\\) \\( 82, 92\\) \\)" \
b2f73e
+		"print ar2\(8:9,:2\)"
b2f73e
+
b2f73e
+gdb_test "print ar2\(8:,8:9\)" \
b2f73e
+		"\\$\[0-9\]+ = \\(\\( 88, 98\\) \\( 89, 99\\) \\)" \
b2f73e
+		"print ar2\(8:,8:9\)"
b2f73e
+gdb_test "print ar2\(8:,8:\)" \
b2f73e
+		"\\$\[0-9\]+ = \\(\\( 88, 98\\) \\( 89, 99\\) \\)" \
b2f73e
+		"print ar2\(8:,8:\)"
b2f73e
+gdb_test "print ar2\(8:,:2\)" \
b2f73e
+		"\\$\[0-9\]+ = \\(\\( 81, 91\\) \\( 82, 92\\) \\)" \
b2f73e
+		"print ar2\(8:,:2\)"
b2f73e
+
b2f73e
+gdb_test "print ar2\(:2,2:3\)" \
b2f73e
+		"\\$\[0-9\]+ = \\(\\( 12, 22\\) \\( 13, 23\\) \\)" \
b2f73e
+		"print ar2\(:2,2:3\)"
b2f73e
+gdb_test "print ar2\(:2,8:\)" \
b2f73e
+		"\\$\[0-9\]+ = \\(\\( 18, 28\\) \\( 19, 29\\) \\)" \
b2f73e
+		"print ar2\(:2,8:\)"
b2f73e
+gdb_test "print ar2\(:2,:2\)" \
b2f73e
+		"\\$\[0-9\]+ = \\(\\( 11, 21\\) \\( 12, 22\\) \\)" \
b2f73e
+		"print ar2\(:2,:2\)"
b2f73e
+
b2f73e
+# Test subranges of 2 dimensional arrays with literals and subrange variations
b2f73e
+gdb_test "print ar2\(7, 3:6\)" \
b2f73e
+		"\\$\[0-9\]+ = \\(73, 74, 75, 76\\)" \
b2f73e
+		"print ar2\(7, 3:6\)"
b2f73e
+gdb_test "print ar2\(7,8:\)" \
b2f73e
+		"\\$\[0-9\]+ = \\(78, 79\\)" \
b2f73e
+		"print ar2\(7,8:\)"
b2f73e
+gdb_test "print ar2\(7,:2\)" \
b2f73e
+		"\\$\[0-9\]+ = \\(71, 72\\)" \
b2f73e
+		"print ar2\(7,:2\)"
b2f73e
+
b2f73e
+gdb_test "print ar2\(7:8,4\)" \
b2f73e
+		"\\$\[0-9\]+ = \\(74, 84\\)" \
b2f73e
+		"print ar2(7:8,4\)"
b2f73e
+gdb_test "print ar2\(8:,4\)" \
b2f73e
+		"\\$\[0-9\]+ = \\(84, 94\\)" \
b2f73e
+		"print ar2\(8:,4\)"
b2f73e
+gdb_test "print ar2\(:2,4\)" \
b2f73e
+		"\\$\[0-9\]+ = \\(14, 24\\)" \
b2f73e
+		"print ar2\(:2,4\)"
b2f73e
+gdb_test "print ar2\(3,4\)" \
b2f73e
+		"\\$\[0-9\]+ = 34" \
b2f73e
+		"print ar2\(3,4\)"
b2f73e
+
b2f73e
+# Test subarrays of 3 dimensional arrays with literals and subrange variations
b2f73e
+gdb_test "print ar3\(2:4,3:4,7:8\)" \
b2f73e
+		"\\$\[0-9\]+ = \\(\\( \\( 237, 337, 437\\) \\( 247, 347, 447\\)\
b2f73e
+		 \\) \\( \\( 238, 338, 438\\) \\( 248, 348, 448\\) \\) \\)" \
b2f73e
+		"print ar3\(2:4,3:4,7:8\)"
b2f73e
+gdb_test "print ar3\(2:3,4:5,8:\)" \
b2f73e
+		"\\$\[0-9\]+ = \\(\\( \\( 248, 348\\) \\( 258, 358\\) \\) \\(\
b2f73e
+		 \\( 249, 349\\) \\( 259, 359\\) \\) \\)" \
b2f73e
+		"print ar3\(2:3,4:5,8:\)"
b2f73e
+gdb_test "print ar3\(2:3,4:5,:2\)" \
b2f73e
+		"\\$\[0-9\]+ = \\(\\( \\( 241, 341\\) \\( 251, 351\\) \\) \\(\
b2f73e
+		 \\( 242, 342\\) \\( 252, 352\\) \\) \\)" \
b2f73e
+		"print ar3\(2:3,4:5,:2\)"
b2f73e
+
b2f73e
+gdb_test "print ar3\(2:3,8:,7:8\)" \
b2f73e
+		"\\$\[0-9\]+ = \\(\\( \\( 287, 387\\) \\( 297, 397\\) \\) \\(\
b2f73e
+		 \\( 288, 388\\) \\( 298, 398\\) \\) \\)" \
b2f73e
+		"print ar3\(2:3,8:,7:8\)"
b2f73e
+gdb_test "print ar3\(2:3,8:,8:\)" \
b2f73e
+		"\\$\[0-9\]+ = \\(\\( \\( 288, 388\\) \\( 298, 398\\) \\) \\(\
b2f73e
+		 \\( 289, 389\\) \\( 299, 399\\) \\) \\)" \
b2f73e
+		"print ar3\(2:3,8:,8:\)"
b2f73e
+gdb_test "print ar3\(2:3,8:,:2\)" \
b2f73e
+		"\\$\[0-9\]+ = \\(\\( \\( 281, 381\\) \\( 291, 391\\) \\) \\(\
b2f73e
+		 \\( 282, 382\\) \\( 292, 392\\) \\) \\)" \
b2f73e
+		"print ar3\(2:3,8:,:2\)"
b2f73e
+
b2f73e
+gdb_test "print ar3\(2:3,:2,7:8\)" \
b2f73e
+		"\\$\[0-9\]+ = \\(\\( \\( 217, 317\\) \\( 227, 327\\) \\) \\(\
b2f73e
+		 \\( 218, 318\\) \\( 228, 328\\) \\) \\)" \
b2f73e
+		"print ar3\(2:3,:2,7:8\)"
b2f73e
+gdb_test "print ar3\(2:3,:2,8:\)" \
b2f73e
+		"\\$\[0-9\]+ = \\(\\( \\( 218, 318\\) \\( 228, 328\\) \\) \\(\
b2f73e
+		 \\( 219, 319\\) \\( 229, 329\\) \\) \\)" \
b2f73e
+		"print ar3\(2:3,:2,8:\)"
b2f73e
+gdb_test "print ar3\(2:3,:2,:2\)" \
b2f73e
+		"\\$\[0-9\]+ = \\(\\( \\( 211, 311\\) \\( 221, 321\\) \\) \\(\
b2f73e
+		 \\( 212, 312\\) \\( 222, 322\\) \\) \\)" \
b2f73e
+		"print ar3\(2:3,:2,:2\)"
b2f73e
+
b2f73e
+gdb_test "print ar3\(8:,3:4,7:8\)" \
b2f73e
+		"\\$\[0-9\]+ = \\(\\( \\( 837, 937\\) \\( 847, 947\\) \\) \\(\
b2f73e
+		 \\( 838, 938\\) \\( 848, 948\\) \\) \\)" \
b2f73e
+		"print ar3\(8:,3:4,7:8\)"
b2f73e
+gdb_test "print ar3\(8:,4:5,8:\)" \
b2f73e
+		"\\$\[0-9\]+ = \\(\\( \\( 848, 948\\) \\( 858, 958\\) \\) \\(\
b2f73e
+		 \\( 849, 949\\) \\( 859, 959\\) \\) \\)" \
b2f73e
+		"print ar3\(8:,4:5,8:\)"
b2f73e
+gdb_test "print ar3\(8:,4:5,:2\)" \
b2f73e
+		"\\$\[0-9\]+ = \\(\\( \\( 841, 941\\) \\( 851, 951\\) \\) \\(\
b2f73e
+		 \\( 842, 942\\) \\( 852, 952\\) \\) \\)" \
b2f73e
+		"print ar3\(8:,4:5,:2\)"
b2f73e
+
b2f73e
+gdb_test "print ar3\(8:,8:,7:8\)" \
b2f73e
+		"\\$\[0-9\]+ = \\(\\( \\( 887, 987\\) \\( 897, 997\\) \\) \\(\
b2f73e
+		 \\( 888, 988\\) \\( 898, 998\\) \\) \\)" \
b2f73e
+		"print ar3\(8:,8:,7:8\)"
b2f73e
+gdb_test "print ar3\(8:,8:,8:\)" \
b2f73e
+		"\\$\[0-9\]+ = \\(\\( \\( 888, 988\\) \\( 898, 998\\) \\) \\(\
b2f73e
+		 \\( 889, 989\\) \\( 899, 999\\) \\) \\)" \
b2f73e
+		"print ar3\(8:,8:,8:\)"
b2f73e
+gdb_test "print ar3\(8:,8:,:2\)" \
b2f73e
+		"\\$\[0-9\]+ = \\(\\( \\( 881, 981\\) \\( 891, 991\\) \\) \\(\
b2f73e
+		 \\( 882, 982\\) \\( 892, 992\\) \\) \\)" \
b2f73e
+		"print ar3\(8:,8:,:2\)"
b2f73e
+
b2f73e
+gdb_test "print ar3\(8:,:2,7:8\)" \
b2f73e
+		"\\$\[0-9\]+ = \\(\\( \\( 817, 917\\) \\( 827, 927\\) \\) \\(\
b2f73e
+		 \\( 818, 918\\) \\( 828, 928\\) \\) \\)" \
b2f73e
+		"print ar3\(8:,:2,7:8\)"
b2f73e
+gdb_test "print ar3\(8:,:2,8:\)" \
b2f73e
+		"\\$\[0-9\]+ = \\(\\( \\( 818, 918\\) \\( 828, 928\\) \\) \\(\
b2f73e
+		 \\( 819, 919\\) \\( 829, 929\\) \\) \\)" \
b2f73e
+		"print ar3\(8:,:2,8:\)"
b2f73e
+gdb_test "print ar3\(8:,:2,:2\)" \
b2f73e
+		"\\$\[0-9\]+ = \\(\\( \\( 811, 911\\) \\( 821, 921\\) \\) \\(\
b2f73e
+		 \\( 812, 912\\) \\( 822, 922\\) \\) \\)" \
b2f73e
+		"print ar3\(8:,:2,:2\)"
b2f73e
+
b2f73e
+
b2f73e
+gdb_test "print ar3\(:2,3:4,7:8\)" \
b2f73e
+		"\\$\[0-9\]+ = \\(\\( \\( 137, 237\\) \\( 147, 247\\) \\) \\(\
b2f73e
+		 \\( 138, 238\\) \\( 148, 248\\) \\) \\)" \
b2f73e
+		"print ar3 \(:2,3:4,7:8\)."
b2f73e
+gdb_test "print ar3\(:2,3:4,8:\)" \
b2f73e
+		"\\$\[0-9\]+ = \\(\\( \\( 138, 238\\) \\( 148, 248\\) \\) \\(\
b2f73e
+		 \\( 139, 239\\) \\( 149, 249\\) \\) \\)" \
b2f73e
+		"print ar3\(:2,3:4,8:\)"
b2f73e
+gdb_test "print ar3\(:2,3:4,:2\)" \
b2f73e
+		"\\$\[0-9\]+ = \\(\\( \\( 131, 231\\) \\( 141, 241\\) \\) \\(\
b2f73e
+		 \\( 132, 232\\) \\( 142, 242\\) \\) \\)" \
b2f73e
+		"print ar3\(:2,3:4,:2\)"
b2f73e
+
b2f73e
+gdb_test "print ar3\(:2,8:,7:8\)" "\\$\[0-9\]+ = \\(\\( \\( 187, 287\\) \\(\
b2f73e
+		 197, 297\\) \\) \\( \\( 188, 288\\) \\( 198, 298\\) \\) \\)" \
b2f73e
+		"print ar3\(:2,8:,7:8\)"
b2f73e
+gdb_test "print ar3\(:2,8:,8:\)" "\\$\[0-9\]+ = \\(\\( \\( 188, 288\\) \\( 198,\
b2f73e
+		 298\\) \\) \\( \\( 189, 289\\) \\( 199, 299\\) \\) \\)" \
b2f73e
+		"print ar3\(:2,8:,8:\)"
b2f73e
+gdb_test "print ar3\(:2,8:,:2\)" "\\$\[0-9\]+ = \\(\\( \\( 181, 281\\) \\( 191,\
b2f73e
+		 291\\) \\) \\( \\( 182, 282\\) \\( 192, 292\\) \\) \\)" \
b2f73e
+		"print ar3\(:2,8:,:2\)"
b2f73e
+
b2f73e
+gdb_test "print ar3\(:2,:2,7:8\)" \
b2f73e
+		"\\$\[0-9\]+ = \\(\\( \\( 117, 217\\) \\( 127, 227\\) \\) \\(\
b2f73e
+		 \\( 118, 218\\) \\( 128, 228\\) \\) \\)" \
b2f73e
+		"print ar3\(:2,:2,7:8\)"
b2f73e
+gdb_test "print ar3\(:2,:2,8:\)" \
b2f73e
+		"\\$\[0-9\]+ = \\(\\( \\( 118, 218\\) \\( 128, 228\\) \\) \\(\
b2f73e
+		 \\( 119, 219\\) \\( 129, 229\\) \\) \\)" \
b2f73e
+		"print ar3\(:2,:2,8:\)"
b2f73e
+gdb_test "print ar3\(:2,:2,:2\)" \
b2f73e
+		"\\$\[0-9\]+ = \\(\\( \\( 111, 211\\) \\( 121, 221\\) \\) \\(\
b2f73e
+		 \\( 112, 212\\) \\( 122, 222\\) \\) \\)" \
b2f73e
+		"print ar3\(:2,:2,:2\)"
b2f73e
+
b2f73e
+#Tests for subarrays of 3 dimensional arrays with literals and subranges
b2f73e
+gdb_test "print ar3\(3,3:4,7:8\)" \
b2f73e
+		"\\$\[0-9\]+ = \\(\\( 337, 347\\) \\( 338, 348\\) \\)" \
b2f73e
+		"print ar3\(3,3:4,7:8\)"
b2f73e
+gdb_test "print ar3\(3,4:5,8:\)" \
b2f73e
+		"\\$\[0-9\]+ = \\(\\( 348, 358\\) \\( 349, 359\\) \\)" \
b2f73e
+		"print ar3\(3,4:5,8:\)"
b2f73e
+gdb_test "print ar3\(3,4:5,:2\)" \
b2f73e
+		"\\$\[0-9\]+ = \\(\\( 341, 351\\) \\( 342, 352\\) \\)" \
b2f73e
+		"print ar3\(3,4:5,:2\)"
b2f73e
+gdb_test "print ar3\(3,4:5,3\)" \
b2f73e
+		"\\$\[0-9\]+ = \\(343, 353\\)" \
b2f73e
+		"print ar3\(3,4:5,3\)"
b2f73e
+
b2f73e
+gdb_test "print ar3\(2,8:,7:8\)" \
b2f73e
+		"\\$\[0-9\]+ = \\(\\( 287, 297\\) \\( 288, 298\\) \\)" \
b2f73e
+		"print ar3\(2,8:,7:8\)"
b2f73e
+gdb_test "print ar3\(2,8:,8:\)" \
b2f73e
+		"\\$\[0-9\]+ = \\(\\( 288, 298\\) \\( 289, 299\\) \\)" \
b2f73e
+		"print ar3\(2,8:,8:\)"
b2f73e
+gdb_test "print ar3\(2,8:,:2\)"\
b2f73e
+		"\\$\[0-9\]+ = \\(\\( 281, 291\\) \\( 282, 292\\) \\)" \
b2f73e
+		"print ar3\(2,8:,:2\)"
b2f73e
+gdb_test "print ar3\(2,8:,3\)" \
b2f73e
+		"\\$\[0-9\]+ = \\(283, 293\\)" \
b2f73e
+		"print ar3\(2,8:,3\)"
b2f73e
+
b2f73e
+gdb_test "print ar3\(2,:2,7:8\)" \
b2f73e
+		"\\$\[0-9\]+ = \\(\\( 217, 227\\) \\( 218, 228\\) \\)" \
b2f73e
+		"print ar3\(2,:2,7:8\)"
b2f73e
+gdb_test "print ar3\(2,:2,8:\)" \
b2f73e
+		"\\$\[0-9\]+ = \\(\\( 218, 228\\) \\( 219, 229\\) \\)" \
b2f73e
+		"print ar3\(2,:2,8:\)"
b2f73e
+gdb_test "print ar3\(2,:2,:2\)" \
b2f73e
+		"\\$\[0-9\]+ = \\(\\( 211, 221\\) \\( 212, 222\\) \\)" \
b2f73e
+		"print ar3\(2,:2,:2\)"
b2f73e
+gdb_test "print ar3\(2,:2,3\)" \
b2f73e
+		"\\$\[0-9\]+ = \\(213, 223\\)" \
b2f73e
+		"print ar3\(2,:2,3\)"
b2f73e
+
b2f73e
+gdb_test "print ar3\(3,4,7:8\)" \
b2f73e
+		"\\$\[0-9\]+ = \\(347, 348\\)" \
b2f73e
+		"print ar3\(3,4,7:8\)"
b2f73e
+gdb_test "print ar3\(3,4,8:\)" \
b2f73e
+		"\\$\[0-9\]+ = \\(348, 349\\)" \
b2f73e
+i		"print ar3\(3,4,8:\)"
b2f73e
+gdb_test "print ar3\(3,4,:2\)" \
b2f73e
+		"\\$\[0-9\]+ = \\(341, 342\\)" \
b2f73e
+		"print ar3\(3,4,:2\)"
b2f73e
+gdb_test "print ar3\(5,6,7\)" \
b2f73e
+		"\\$\[0-9\]+ = 567" \
b2f73e
+		"print ar3\(5,6,7\)"
b2f73e
+
b2f73e
+gdb_test "print ar3\(3:4,6,7:8\)" \
b2f73e
+		"\\$\[0-9\]+ = \\(\\( 367, 467\\) \\( 368, 468\\) \\)" \
b2f73e
+		"print ar3\(3:4,6,7:8\)"
b2f73e
+gdb_test "print ar3\(3:4,6,8:\)" \
b2f73e
+		"\\$\[0-9\]+ = \\(\\( 368, 468\\) \\( 369, 469\\) \\)" \
b2f73e
+		"print ar3\(3:4,6,8:\)"
b2f73e
+gdb_test "print ar3\(3:4,6,:2\)" \
b2f73e
+		"\\$\[0-9\]+ = \\(\\( 361, 461\\) \\( 362, 462\\) \\)" \
b2f73e
+		"print ar3\(3:4,6,:2\)"
b2f73e
+gdb_test "print ar3\(3:4,6,5\)" \
b2f73e
+		"\\$\[0-9\]+ = \\(365, 465\\)" \
b2f73e
+		"print ar3\(3:4,6,5\)"
b2f73e
+
b2f73e
+gdb_test "print ar3\(8:,6,7:8\)" \
b2f73e
+		"\\$\[0-9\]+ = \\(\\( 867, 967\\) \\( 868, 968\\) \\)" \
b2f73e
+		"print ar3\(8:,6,7:8\)"
b2f73e
+gdb_test "print ar3\(8:,6,8:\)" \
b2f73e
+		"\\$\[0-9\]+ = \\(\\( 868, 968\\) \\( 869, 969\\) \\)" \
b2f73e
+		"print ar3\(8:,6,8:\)"
b2f73e
+gdb_test "print ar3\(8:,6,:2\)" \
b2f73e
+		"\\$\[0-9\]+ = \\(\\( 861, 961\\) \\( 862, 962\\) \\)" \
b2f73e
+		"print ar3\(8:,6,:2\)"
b2f73e
+gdb_test "print ar3\(8:,6,5\)" \
b2f73e
+		"\\$\[0-9\]+ = \\(865, 965\\)" \
b2f73e
+		"print ar3\(8:,6,5\)"
b2f73e
+
b2f73e
+gdb_test "print ar3\(:2,6,7:8\)" \
b2f73e
+		"\\$\[0-9\]+ = \\(\\( 167, 267\\) \\( 168, 268\\) \\)" \
b2f73e
+		"print ar3\(:2,6,7:8\)"
b2f73e
+gdb_test "print ar3\(:2,6,8:\)" \
b2f73e
+		"\\$\[0-9\]+ = \\(\\( 168, 268\\) \\( 169, 269\\) \\)" \
b2f73e
+		"print ar3\(:2,6,8:\)"
b2f73e
+gdb_test "print ar3\(:2,6,:2\)" \
b2f73e
+		"\\$\[0-9\]+ = \\(\\( 161, 261\\) \\( 162, 262\\) \\)" \
b2f73e
+		"print ar3\(:2,6,:2\)"
b2f73e
+gdb_test "print ar3\(:2,6,5\)" \
b2f73e
+		"\\$\[0-9\]+ = \\(165, 265\\)" \
b2f73e
+		"print ar3\(:2,6,5\)"
b2f73e
+
b2f73e
+gdb_test "print ar3\(3:4,5:6,4\)" \
b2f73e
+		"\\$\[0-9\]+ = \\(\\( 354, 454\\) \\( 364, 464\\) \\)" \
b2f73e
+		"print ar2\(3:4,5:6,4\)"
b2f73e
+gdb_test "print ar3\(8:,5:6,4\)" \
b2f73e
+		"\\$\[0-9\]+ = \\(\\( 854, 954\\) \\( 864, 964\\) \\)" \
b2f73e
+		"print ar2\(8:,5:6,4\)"
b2f73e
+gdb_test "print ar3\(:2,5:6,4\)" \
b2f73e
+		"\\$\[0-9\]+ = \\(\\( 154, 254\\) \\( 164, 264\\) \\)" \
b2f73e
+		"print ar2\(:2,5:6,4\)"
b2f73e
+
b2f73e
+# Stride > 1
b2f73e
+gdb_test "print ar1\(2:6:2\)" \
b2f73e
+		"\\$\[0-9\]+ = \\(2, 4, 6\\)" \
b2f73e
+		"print ar1\(2:6:2\)"
b2f73e
+gdb_test "print ar2\(2:6:2,3:4\)" \
b2f73e
+		"\\$\[0-9\]+ = \\(\\( 23, 43, 63\\) \\( 24, 44, 64\\) \\)" \
b2f73e
+		"print ar2\(2:6:2,3:4\)"
b2f73e
+gdb_test "print ar2\(2:6:2,3\)" \
b2f73e
+		"\\$\[0-9\]+ = \\(23, 43, 63\\)" \
b2f73e
+		"print ar2\(2:6:2,3\)"
b2f73e
+gdb_test "print ar3\(2:6:2,3:5:2,4:7:3\)" \
b2f73e
+		"\\$\[0-9\]+ = \\(\\( \\( 234, 434, 634\\) \\( 254, 454, 654\\)\
b2f73e
+		 \\) \\( \\( 237, 437, 637\\) \\( 257, 457, 657\\) \\) \\)" \
b2f73e
+		"print ar3\(2:6:2,3:5:2,4:7:3\)"
b2f73e
+gdb_test "print ar3\(2:6:2,5,4:7:3\)" \
b2f73e
+		"\\$\[0-9\]+ = \\(\\( 254, 454, 654\\) \\( 257, 457, 657\\)\
b2f73e
+		 \\)" \
b2f73e
+		"print ar3\(2:6:2,5,4:7:3\)"
b2f73e
+
b2f73e
+# Stride < 0
b2f73e
+gdb_test "print ar1\(8:2:-2\)" \
b2f73e
+		"\\$\[0-9\]+ = \\(8, 6, 4, 2\\)" \
b2f73e
+		"print ar1\(8:2:-2\)"
b2f73e
+gdb_test "print ar2\(8:2:-2,3:4\)" \
b2f73e
+		"\\$\[0-9\]+ = \\(\\( 83, 63, 43, 23\\) \\( 84, 64, 44, 24\\)\
b2f73e
+		 \\)" \
b2f73e
+		"print ar2\(8:2:-2,3:4\)"
b2f73e
+gdb_test "print ar2\(2:6:2,3\)" \
b2f73e
+		"\\$\[0-9\]+ = \\(23, 43, 63\\)" \
b2f73e
+		"print ar2\(2:6:2,3\)"
b2f73e
+gdb_test "print ar3\(2:3,7:3:-4,4:7:3\)" \
b2f73e
+		"\\$\[0-9\]+ = \\(\\( \\( 274, 374\\) \\( 234, 334\\) \\) \\(\
b2f73e
+		 \\( 277, 377\\) \\( 237, 337\\) \\) \\)" \
b2f73e
+		"print ar3\(2:3,7:3:-4,4:7:3\)"
b2f73e
+gdb_test "print ar3\(2:6:2,5,7:4:-3\)" \
b2f73e
+		"\\$\[0-9\]+ = \\(\\( 257, 457, 657\\) \\( 254, 454, 654\\)\
b2f73e
+		 \\)" \
b2f73e
+		"print ar3\(2:6:2,5,7:4:-3\)"
b2f73e
+
b2f73e
+# Tests with negative and mixed indices
b2f73e
+gdb_test "p ar4\(2:4, -2:1, -15:-14\)" \
b2f73e
+		"\\$\[0-9\]+ = \\(\\( \\( 261, 361, 461\\) \\( 271, 371, 471\\)\
b2f73e
+		 \\( 281, 381, 481\\) \\( 291, 391, 491\\) \\) \\( \\( 262,\
b2f73e
+		 362, 462\\) \\( 272, 372, 472\\) \\( 282, 382, 482\\) \\( 292,\
b2f73e
+		 392, 492\\) \\) \\)" \
b2f73e
+		"print ar4(2:4, -2:1, -15:-14)"
b2f73e
+
b2f73e
+gdb_test "p ar4\(7,-6:2:3,-7\)" \
b2f73e
+                "\\$\[0-9\]+ = \\(729, 759, 789\\)" \
b2f73e
+                "print ar4(7,-6:2:3,-7)"
b2f73e
+
b2f73e
+gdb_test "p ar4\(9:2:-2, -6:2:3, -6:-15:-3\)" \
b2f73e
+                "\\$\[0-9\]+ = \\(\\( \\( 930, 730, 530, 330\\) \\( 960, 760,\
b2f73e
+		 560, 360\\) \\( 990, 790, 590, 390\\) \\) \\( \\( 927, 727,\
b2f73e
+		 527, 327\\) \\( 957, 757, 557, 357\\) \\( 987, 787, 587,\
b2f73e
+		 387\\) \\) \\( \\( 924, 724, 524, 324\\) \\( 954, 754, 554,\
b2f73e
+		 354\\) \\( 984, 784, 584, 384\\) \\) \\( \\( 921, 721, 521,\
b2f73e
+		 321\\) \\( 951, 751, 551, 351\\) \\( 981, 781, 581, 381\\) \\)\
b2f73e
+		 \\)" \
b2f73e
+                "print ar4(9:2:-2, -6:2:3, -6:-15:-3)"
b2f73e
+
b2f73e
+gdb_test "p ar4\(:,:,:\)" \
b2f73e
+                "\\$\[0-9\]+ = \\(\\( \\( 111, 211, 311, 411, 511, 611, 711,\
b2f73e
+		 811, .*" \
b2f73e
+                "print ar4(:,:,:)"
b2f73e
+
b2f73e
+# Provoke error messages for bad user input
b2f73e
+gdb_test "print ar1\(0:4\)" \
b2f73e
+		"provided bound\\(s\\) outside array bound\\(s\\)" \
b2f73e
+		"print ar1\(0:4\)"
b2f73e
+gdb_test "print ar1\(8:12\)" \
b2f73e
+		"provided bound\\(s\\) outside array bound\\(s\\)" \
b2f73e
+		"print ar1\(8:12\)"
b2f73e
+gdb_test "print ar1\(8:2:\)" \
b2f73e
+		"A syntax error in expression, near `\\)'." \
b2f73e
+		"print ar1\(8:2:\)"
b2f73e
+gdb_test "print ar1\(8:2:2\)" \
b2f73e
+		"Wrong value provided for stride and boundaries" \
b2f73e
+		"print ar1\(8:2:2\)"
b2f73e
+gdb_test "print ar1\(2:8:-2\)" \
b2f73e
+		"Wrong value provided for stride and boundaries" \
b2f73e
+		"print ar1\(2:8:-2\)"
b2f73e
+gdb_test "print ar1\(2:7:0\)" \
b2f73e
+		"Stride must not be 0" \
b2f73e
+		"print ar1\(2:7:0\)"
b2f73e
+gdb_test "print ar1\(3:7\) = 42" \
b2f73e
+		"Invalid cast." \
b2f73e
+		"Assignment of value to subarray"
b2f73e
diff --git a/gdb/testsuite/gdb.fortran/static-arrays.f90 b/gdb/testsuite/gdb.fortran/static-arrays.f90
b2f73e
new file mode 100644
b2f73e
--- /dev/null
b2f73e
+++ b/gdb/testsuite/gdb.fortran/static-arrays.f90
b2f73e
@@ -0,0 +1,55 @@
b2f73e
+! Copyright 2015 Free Software Foundation, Inc.
b2f73e
+!
b2f73e
+! Contributed by Intel Corp. <christoph.t.weinmann@intel.com>
b2f73e
+!
b2f73e
+! This program is free software; you can redistribute it and/or modify
b2f73e
+! it under the terms of the GNU General Public License as published by
b2f73e
+! the Free Software Foundation; either version 3 of the License, or
b2f73e
+! (at your option) any later version.
b2f73e
+!
b2f73e
+! This program is distributed in the hope that it will be useful,
b2f73e
+! but WITHOUT ANY WARRANTY; without even the implied warranty of
b2f73e
+! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
b2f73e
+! GNU General Public License for more details.
b2f73e
+!
b2f73e
+! You should have received a copy of the GNU General Public License
b2f73e
+! along with this program.  If not, see <http://www.gnu.org/licenses/>.
b2f73e
+
b2f73e
+subroutine sub
b2f73e
+  integer, dimension(9) :: ar1
b2f73e
+  integer, dimension(9,9) :: ar2
b2f73e
+  integer, dimension(9,9,9) :: ar3
b2f73e
+  integer, dimension(10,-7:3, -15:-5) :: ar4
b2f73e
+  integer :: i,j,k
b2f73e
+
b2f73e
+  ar1 = 1
b2f73e
+  ar2 = 1
b2f73e
+  ar3 = 1
b2f73e
+  ar4 = 4
b2f73e
+
b2f73e
+  ! Resulting array ar3 looks like ((( 111, 112, 113, 114,...)))
b2f73e
+  do i = 1, 9, 1
b2f73e
+    ar1(i) = i
b2f73e
+    do j = 1, 9, 1
b2f73e
+      ar2(i,j) = i*10 + j
b2f73e
+      do k = 1, 9, 1
b2f73e
+        ar3(i,j,k) = i*100 + j*10 + k
b2f73e
+      end do
b2f73e
+    end do
b2f73e
+  end do
b2f73e
+
b2f73e
+  do i = 1, 10, 1
b2f73e
+    do j = -7, 3, 1
b2f73e
+      do k = -15, -5, 1
b2f73e
+        ar4(i,j,k) = i*100 + (j+8)*10 + (k+16)
b2f73e
+      end do
b2f73e
+    end do
b2f73e
+  end do
b2f73e
+
b2f73e
+  ar1(1) = 11  !BP1
b2f73e
+  return
b2f73e
+end
b2f73e
+
b2f73e
+program testprog
b2f73e
+  call sub
b2f73e
+end
b2f73e
diff --git a/gdb/testsuite/gdb.fortran/vla-sizeof.exp b/gdb/testsuite/gdb.fortran/vla-sizeof.exp
b2f73e
--- a/gdb/testsuite/gdb.fortran/vla-sizeof.exp
b2f73e
+++ b/gdb/testsuite/gdb.fortran/vla-sizeof.exp
b2f73e
@@ -32,7 +32,8 @@ gdb_test "print sizeof(vla1)" " = 0" "print sizeof non-allocated vla1"
b2f73e
 gdb_test "print sizeof(vla1(3,2,1))" \
b2f73e
     "no such vector element \\(vector not allocated\\)" \
b2f73e
     "print sizeof non-allocated indexed vla1"
b2f73e
-gdb_test "print sizeof(vla1(3:4,2,1))" "array not allocated" \
b2f73e
+gdb_test "print sizeof(vla1(3:4,2,1))" \
b2f73e
+    "provided bound\\(s\\) outside array bound\\(s\\)" \
b2f73e
     "print sizeof non-allocated sliced vla1"
b2f73e
 
b2f73e
 # Try to access value in allocated VLA
b2f73e
@@ -41,7 +42,7 @@ gdb_continue_to_breakpoint "vla1-allocated"
b2f73e
 gdb_test "print sizeof(vla1)" " = 4000" "print sizeof allocated vla1"
b2f73e
 gdb_test "print sizeof(vla1(3,2,1))" "4" \
b2f73e
     "print sizeof element from allocated vla1"
b2f73e
-gdb_test "print sizeof(vla1(3:4,2,1))" "800" \
b2f73e
+gdb_test "print sizeof(vla1(3:4,2,1))" "8" \
b2f73e
     "print sizeof sliced vla1"
b2f73e
 
b2f73e
 # Try to access values in undefined pointer to VLA (dangling)
b2f73e
@@ -49,7 +50,8 @@ gdb_test "print sizeof(pvla)" " = 0" "print sizeof non-associated pvla"
b2f73e
 gdb_test "print sizeof(pvla(3,2,1))" \
b2f73e
     "no such vector element \\(vector not associated\\)" \
b2f73e
     "print sizeof non-associated indexed pvla"
b2f73e
-gdb_test "print sizeof(pvla(3:4,2,1))" "array not associated" \
b2f73e
+gdb_test "print sizeof(pvla(3:4,2,1))" \
b2f73e
+    "provided bound\\(s\\) outside array bound\\(s\\)" \
b2f73e
     "print sizeof non-associated sliced pvla"
b2f73e
 
b2f73e
 # Try to access values in pointer to VLA and compare them
b2f73e
@@ -58,7 +60,8 @@ gdb_continue_to_breakpoint "pvla-associated"
b2f73e
 gdb_test "print sizeof(pvla)" " = 4000" "print sizeof associated pvla"
b2f73e
 gdb_test "print sizeof(pvla(3,2,1))" "4" \
b2f73e
     "print sizeof element from associated pvla"
b2f73e
-gdb_test "print sizeof(pvla(3:4,2,1))" "800" "print sizeof sliced pvla"
b2f73e
+
b2f73e
+gdb_test "print sizeof(pvla(3:4,2,1))" "8" "print sizeof sliced pvla"
b2f73e
 
b2f73e
 gdb_breakpoint [gdb_get_line_number "vla1-neg-bounds-v1"]
b2f73e
 gdb_continue_to_breakpoint "vla1-neg-bounds-v1"
b2f73e
diff --git a/gdb/testsuite/gdb.fortran/vla-stride.exp b/gdb/testsuite/gdb.fortran/vla-stride.exp
b2f73e
new file mode 100644
b2f73e
--- /dev/null
b2f73e
+++ b/gdb/testsuite/gdb.fortran/vla-stride.exp
b2f73e
@@ -0,0 +1,47 @@
b2f73e
+# Copyright 2016 Free Software Foundation, Inc.
b2f73e
+
b2f73e
+# This program is free software; you can redistribute it and/or modify
b2f73e
+# it under the terms of the GNU General Public License as published by
b2f73e
+# the Free Software Foundation; either version 3 of the License, or
b2f73e
+# (at your option) any later version.
b2f73e
+#
b2f73e
+# This program is distributed in the hope that it will be useful,
b2f73e
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
b2f73e
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
b2f73e
+# GNU General Public License for more details.
b2f73e
+#
b2f73e
+# You should have received a copy of the GNU General Public License
b2f73e
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
b2f73e
+
b2f73e
+standard_testfile ".f90"
b2f73e
+
b2f73e
+if { [prepare_for_testing ${testfile}.exp ${testfile} ${srcfile} \
b2f73e
+    {debug f90 quiet}] } {
b2f73e
+    return -1
b2f73e
+}
b2f73e
+
b2f73e
+if ![runto MAIN__] then {
b2f73e
+    perror "couldn't run to breakpoint MAIN__"
b2f73e
+    continue
b2f73e
+}
b2f73e
+
b2f73e
+gdb_test_no_output "set max-value-size unlimited" \
b2f73e
+    "set max-value-size to unlimited"
b2f73e
+
b2f73e
+gdb_breakpoint [gdb_get_line_number "re-reverse-elements"]
b2f73e
+gdb_continue_to_breakpoint "re-reverse-elements"
b2f73e
+gdb_test "print pvla" " = \\\(1, 2, 3, 4, 5, 6, 7, 8, 9, 10\\\)" \
b2f73e
+  "print re-reverse-elements"
b2f73e
+gdb_test "print pvla(1)" " = 1" "print first re-reverse-element"
b2f73e
+gdb_test "print pvla(10)" " = 10" "print last re-reverse-element"
b2f73e
+
b2f73e
+gdb_breakpoint [gdb_get_line_number "odd-elements"]
b2f73e
+gdb_continue_to_breakpoint "odd-elements"
b2f73e
+gdb_test "print pvla" " = \\\(1, 3, 5, 7, 9\\\)" "print odd-elements"
b2f73e
+gdb_test "print pvla(1)" " = 1" "print first odd-element"
b2f73e
+gdb_test "print pvla(5)" " = 9" "print last odd-element"
b2f73e
+
b2f73e
+gdb_breakpoint [gdb_get_line_number "single-element"]
b2f73e
+gdb_continue_to_breakpoint "single-element"
b2f73e
+gdb_test "print pvla" " = \\\(5\\\)" "print single-element"
b2f73e
+gdb_test "print pvla(1)" " = 5" "print one single-element"
b2f73e
diff --git a/gdb/testsuite/gdb.fortran/vla-stride.f90 b/gdb/testsuite/gdb.fortran/vla-stride.f90
b2f73e
new file mode 100644
b2f73e
--- /dev/null
b2f73e
+++ b/gdb/testsuite/gdb.fortran/vla-stride.f90
b2f73e
@@ -0,0 +1,29 @@
b2f73e
+! Copyright 2016 Free Software Foundation, Inc.
b2f73e
+!
b2f73e
+! This program is free software; you can redistribute it and/or modify
b2f73e
+! it under the terms of the GNU General Public License as published by
b2f73e
+! the Free Software Foundation; either version 3 of the License, or
b2f73e
+! (at your option) any later version.
b2f73e
+!
b2f73e
+! This program is distributed in the hope that it will be useful,
b2f73e
+! but WITHOUT ANY WARRANTY; without even the implied warranty of
b2f73e
+! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
b2f73e
+! GNU General Public License for more details.
b2f73e
+!
b2f73e
+! You should have received a copy of the GNU General Public License
b2f73e
+! along with this program.  If not, see <http://www.gnu.org/licenses/>.
b2f73e
+
b2f73e
+program vla_stride
b2f73e
+  integer, target, allocatable :: vla (:)
b2f73e
+  integer, pointer :: pvla (:)
b2f73e
+
b2f73e
+  allocate(vla(10))
b2f73e
+  vla = (/ (I, I = 1,10) /)
b2f73e
+
b2f73e
+  pvla => vla(10:1:-1)
b2f73e
+  pvla => pvla(10:1:-1)
b2f73e
+  pvla => vla(1:10:2)   ! re-reverse-elements
b2f73e
+  pvla => vla(5:4:-2)   ! odd-elements
b2f73e
+
b2f73e
+  pvla => null()        ! single-element
b2f73e
+end program vla_stride
b2f73e
diff --git a/gdb/valops.c b/gdb/valops.c
b2f73e
--- a/gdb/valops.c
b2f73e
+++ b/gdb/valops.c
b2f73e
@@ -3797,13 +3797,42 @@ value_of_this_silent (const struct language_defn *lang)
b2f73e
 
b2f73e
 struct value *
b2f73e
 value_slice (struct value *array, int lowbound, int length)
b2f73e
+{
b2f73e
+  /* Pass unaltered arguments to VALUE_SLICE_1, plus a default stride
b2f73e
+     value of '1', which returns every element between LOWBOUND and
b2f73e
+     (LOWBOUND + LENGTH).  We also provide a default CALL_COUNT of '1'
b2f73e
+     as we are only considering the highest dimension, or we are
b2f73e
+     working on a one dimensional array.  So we call VALUE_SLICE_1
b2f73e
+     exactly once.  */
b2f73e
+  return value_slice_1 (array, lowbound, length, 1, 1);
b2f73e
+}
b2f73e
+
b2f73e
+/* VALUE_SLICE_1 is called for each array dimension to calculate the number
b2f73e
+   of elements as defined by the subscript expression.
b2f73e
+   CALL_COUNT is used to determine if we are calling the function once, e.g.
b2f73e
+   we are working on the current dimension of ARRAY, or if we are calling
b2f73e
+   the function repeatedly.  In the later case we need to take elements
b2f73e
+   from the TARGET_TYPE of ARRAY.
b2f73e
+   With a CALL_COUNT greater than 1 we calculate the offsets for every element
b2f73e
+   that should be in the result array.  Then we fetch the contents and then
b2f73e
+   copy them into the result array.  The result array will have one dimension
b2f73e
+   less than the input array, so later on we need to recreate the indices and
b2f73e
+   ranges in the calling function.  */
b2f73e
+
b2f73e
+struct value *
b2f73e
+value_slice_1 (struct value *array, int lowbound, int length,
b2f73e
+	       int stride_length, int call_count)
b2f73e
 {
b2f73e
   struct type *slice_range_type, *slice_type, *range_type;
b2f73e
-  LONGEST lowerbound, upperbound;
b2f73e
-  struct value *slice;
b2f73e
-  struct type *array_type;
b2f73e
+  struct type *array_type = check_typedef (value_type (array));
b2f73e
+  struct type *elt_type = check_typedef (TYPE_TARGET_TYPE (array_type));
b2f73e
+  unsigned int elt_size, elt_offs;
b2f73e
+  LONGEST ary_high_bound, ary_low_bound;
b2f73e
+  struct value *v;
b2f73e
+  int slice_range_size, i = 0, row_count = 1, elem_count = 1;
b2f73e
 
b2f73e
-  array_type = check_typedef (value_type (array));
b2f73e
+  /* Check for legacy code if we are actually dealing with an array or
b2f73e
+     string.  */
b2f73e
   if (TYPE_CODE (array_type) != TYPE_CODE_ARRAY
b2f73e
       && TYPE_CODE (array_type) != TYPE_CODE_STRING)
b2f73e
     error (_("cannot take slice of non-array"));
b2f73e
@@ -3813,45 +3842,155 @@ value_slice (struct value *array, int lowbound, int length)
b2f73e
   if (type_not_associated (array_type))
b2f73e
     error (_("array not associated"));
b2f73e
 
b2f73e
-  range_type = TYPE_INDEX_TYPE (array_type);
b2f73e
-  if (get_discrete_bounds (range_type, &lowerbound, &upperbound) < 0)
b2f73e
-    error (_("slice from bad array or bitstring"));
b2f73e
+  ary_low_bound = TYPE_LOW_BOUND (TYPE_INDEX_TYPE (array_type));
b2f73e
+  ary_high_bound = TYPE_HIGH_BOUND (TYPE_INDEX_TYPE (array_type));
b2f73e
+
b2f73e
+  /* When we are working on a multi-dimensional array, we need to get the
b2f73e
+     attributes of the underlying type.  */
b2f73e
+  if (call_count > 1)
b2f73e
+    {
b2f73e
+      ary_low_bound = TYPE_LOW_BOUND (TYPE_INDEX_TYPE (elt_type));
b2f73e
+      ary_high_bound = TYPE_HIGH_BOUND (TYPE_INDEX_TYPE (elt_type));
b2f73e
+      elt_type = check_typedef (TYPE_TARGET_TYPE (elt_type));
b2f73e
+      row_count = TYPE_LENGTH (array_type)
b2f73e
+		    / TYPE_LENGTH (TYPE_TARGET_TYPE (array_type));
b2f73e
+    }
b2f73e
+
b2f73e
+  /* With a stride of '1', the number of elements per result row is equal to
b2f73e
+     the LENGTH of the subarray.  With non-default stride values, we skip
b2f73e
+     elements, but have to add the start element to the total number of
b2f73e
+     elements per row.  */
b2f73e
+  if (stride_length == 1)
b2f73e
+    elem_count = length;
b2f73e
+  else
b2f73e
+    elem_count = ((length - 1) / stride_length) + 1;
b2f73e
+
b2f73e
+  elt_size = TYPE_LENGTH (elt_type);
b2f73e
+  elt_offs = lowbound - ary_low_bound;
b2f73e
 
b2f73e
-  if (lowbound < lowerbound || length < 0
b2f73e
-      || lowbound + length - 1 > upperbound)
b2f73e
-    error (_("slice out of range"));
b2f73e
+  elt_offs *= elt_size;
b2f73e
+
b2f73e
+  /* Check for valid user input.  In case of Fortran this was already done
b2f73e
+     in the calling function.  */
b2f73e
+  if (call_count == 1
b2f73e
+	&& (!TYPE_ARRAY_UPPER_BOUND_IS_UNDEFINED (array_type)
b2f73e
+	      && elt_offs >= TYPE_LENGTH (array_type)))
b2f73e
+    error (_("no such vector element"));
b2f73e
+
b2f73e
+  /* CALL_COUNT is 1 when we are dealing either with the highest dimension
b2f73e
+     of the array, or a one dimensional array.  Set RANGE_TYPE accordingly.
b2f73e
+     In both cases we calculate how many rows/elements will be in the output
b2f73e
+     array by setting slice_range_size.  */
b2f73e
+  if (call_count == 1)
b2f73e
+    {
b2f73e
+      range_type = TYPE_INDEX_TYPE (array_type);
b2f73e
+      slice_range_size = ary_low_bound + elem_count - 1;
b2f73e
+
b2f73e
+      /* Check if the array bounds are valid.  */
b2f73e
+      if (get_discrete_bounds (range_type, &ary_low_bound, &ary_high_bound) < 0)
b2f73e
+	error (_("slice from bad array or bitstring"));
b2f73e
+    }
b2f73e
+  /* When CALL_COUNT is greater than 1, we are dealing with an array of arrays.
b2f73e
+     So we need to get the type below the current one and set the RANGE_TYPE
b2f73e
+     accordingly.  */
b2f73e
+  else
b2f73e
+    {
b2f73e
+      range_type = TYPE_INDEX_TYPE (TYPE_TARGET_TYPE (array_type));
b2f73e
+      slice_range_size = ary_low_bound + (row_count * elem_count) - 1;
b2f73e
+      ary_low_bound = TYPE_LOW_BOUND (range_type);
b2f73e
+    }
b2f73e
 
b2f73e
   /* FIXME-type-allocation: need a way to free this type when we are
b2f73e
-     done with it.  */
b2f73e
-  slice_range_type = create_static_range_type (NULL,
b2f73e
-					       TYPE_TARGET_TYPE (range_type),
b2f73e
-					       lowbound,
b2f73e
-					       lowbound + length - 1);
b2f73e
+      done with it.  */
b2f73e
 
b2f73e
+  slice_range_type = create_static_range_type (NULL, TYPE_TARGET_TYPE (range_type),
b2f73e
+					       ary_low_bound, slice_range_size);
b2f73e
   {
b2f73e
-    struct type *element_type = TYPE_TARGET_TYPE (array_type);
b2f73e
-    LONGEST offset
b2f73e
-      = (lowbound - lowerbound) * TYPE_LENGTH (check_typedef (element_type));
b2f73e
+    struct type *element_type;
b2f73e
+
b2f73e
+    /* When both CALL_COUNT and STRIDE_LENGTH equal 1, we can use the legacy
b2f73e
+       code for subarrays.  */
b2f73e
+    if (call_count == 1 && stride_length == 1)
b2f73e
+      {
b2f73e
+	element_type = TYPE_TARGET_TYPE (array_type);
b2f73e
+
b2f73e
+	slice_type = create_array_type (NULL, element_type, slice_range_type);
b2f73e
 
b2f73e
-    slice_type = create_array_type (NULL,
b2f73e
-				    element_type,
b2f73e
-				    slice_range_type);
b2f73e
-    TYPE_CODE (slice_type) = TYPE_CODE (array_type);
b2f73e
+	TYPE_CODE (slice_type) = TYPE_CODE (array_type);
b2f73e
 
b2f73e
-    if (VALUE_LVAL (array) == lval_memory && value_lazy (array))
b2f73e
-      slice = allocate_value_lazy (slice_type);
b2f73e
+	if (VALUE_LVAL (array) == lval_memory && value_lazy (array))
b2f73e
+	  v = allocate_value_lazy (slice_type);
b2f73e
+	else
b2f73e
+	  {
b2f73e
+	    v = allocate_value (slice_type);
b2f73e
+	    value_contents_copy (v,
b2f73e
+				 value_embedded_offset (v),
b2f73e
+				 array,
b2f73e
+				 value_embedded_offset (array) + elt_offs,
b2f73e
+				 elt_size * longest_to_int (length));
b2f73e
+	  }
b2f73e
+
b2f73e
+      }
b2f73e
+    /* With a CALL_COUNT or STRIDE_LENGTH are greater than 1 we are working
b2f73e
+       on a range of ranges.  So we copy the relevant elements into the
b2f73e
+       new array we return.  */
b2f73e
     else
b2f73e
       {
b2f73e
-	slice = allocate_value (slice_type);
b2f73e
-	value_contents_copy (slice, 0, array, offset,
b2f73e
-			     type_length_units (slice_type));
b2f73e
+	int j, offs_store = elt_offs;
b2f73e
+	LONGEST dst_offset = 0;
b2f73e
+	LONGEST src_row_length = TYPE_LENGTH (TYPE_TARGET_TYPE (array_type));
b2f73e
+
b2f73e
+	if (call_count == 1)
b2f73e
+	  {
b2f73e
+	    /* When CALL_COUNT is equal to 1 we are working on the current range
b2f73e
+	       and use these elements directly.  */
b2f73e
+	    element_type = TYPE_TARGET_TYPE (array_type);
b2f73e
+	  }
b2f73e
+	else
b2f73e
+	  {
b2f73e
+	    /* Working on an array of arrays, the type of the elements is the type
b2f73e
+	       of the subarrays' type.  */
b2f73e
+	    element_type = TYPE_TARGET_TYPE (TYPE_TARGET_TYPE (array_type));
b2f73e
+	  }
b2f73e
+
b2f73e
+	slice_type = create_array_type (NULL, element_type, slice_range_type);
b2f73e
+
b2f73e
+	 /* If we have a one dimensional array, we copy its TYPE_CODE.  For a
b2f73e
+	    multi dimensional array we copy the embedded type's TYPE_CODE.  */
b2f73e
+	if (call_count == 1)
b2f73e
+	  TYPE_CODE (slice_type) = TYPE_CODE (array_type);
b2f73e
+	else
b2f73e
+	  TYPE_CODE (slice_type) = TYPE_CODE (TYPE_TARGET_TYPE (array_type));
b2f73e
+
b2f73e
+	v = allocate_value (slice_type);
b2f73e
+
b2f73e
+	/* Iterate through the rows of the outer array and set the new offset
b2f73e
+	   for each row.  */
b2f73e
+	for (i = 0; i < row_count; i++)
b2f73e
+	  {
b2f73e
+	    elt_offs = offs_store + i * src_row_length;
b2f73e
+
b2f73e
+	    /* Iterate through the elements in each row to copy only those.  */
b2f73e
+	    for (j = 1; j <= elem_count; j++)
b2f73e
+	      {
b2f73e
+		/* Fetches the contents of ARRAY and copies them into V.  */
b2f73e
+		value_contents_copy (v, dst_offset, array, elt_offs, elt_size);
b2f73e
+		elt_offs += elt_size * stride_length;
b2f73e
+		dst_offset += elt_size;
b2f73e
+	      }
b2f73e
+	  }
b2f73e
       }
b2f73e
 
b2f73e
-    set_value_component_location (slice, array);
b2f73e
-    set_value_offset (slice, value_offset (array) + offset);
b2f73e
+    set_value_component_location (v, array);
b2f73e
+    if (VALUE_LVAL (v) == lval_register)
b2f73e
+      {
b2f73e
+	VALUE_REGNUM (v) = VALUE_REGNUM (array);
b2f73e
+	VALUE_NEXT_FRAME_ID (v) = VALUE_NEXT_FRAME_ID (array);
b2f73e
+      }
b2f73e
+    set_value_offset (v, value_offset (array) + elt_offs);
b2f73e
   }
b2f73e
 
b2f73e
-  return slice;
b2f73e
+  return v;
b2f73e
 }
b2f73e
 
b2f73e
 /* Create a value for a FORTRAN complex number.  Currently most of the
b2f73e
diff --git a/gdb/value.h b/gdb/value.h
b2f73e
--- a/gdb/value.h
b2f73e
+++ b/gdb/value.h
b2f73e
@@ -1145,6 +1145,8 @@ extern struct value *varying_to_slice (struct value *);
b2f73e
 
b2f73e
 extern struct value *value_slice (struct value *, int, int);
b2f73e
 
b2f73e
+extern struct value *value_slice_1 (struct value *, int, int, int, int);
b2f73e
+
b2f73e
 extern struct value *value_literal_complex (struct value *, struct value *,
b2f73e
 					    struct type *);
b2f73e