]> git.pld-linux.org Git - packages/gdb.git/blob - gdb-vla-intel-fortran-strides.patch
- updated to 14.1 + rebased Fedora buildid patches set
[packages/gdb.git] / gdb-vla-intel-fortran-strides.patch
1 From FEDORA_PATCHES Mon Sep 17 00:00:00 2001
2 From: Fedora GDB patches <invalid@email.com>
3 Date: Fri, 27 Oct 2017 21:07:50 +0200
4 Subject: gdb-vla-intel-fortran-strides.patch
5
6 FileName: gdb-vla-intel-fortran-strides.patch
7
8 ;; VLA (Fortran dynamic arrays) from Intel + archer-jankratochvil-vla tests.
9 ;;=push
10
11 git diff --stat -p gdb/master...gdb/users/bheckel/fortran-strides
12 dbfd7140bf4c0500d1f5d192be781f83f78f7922
13
14  gdb/dwarf2loc.c                             |  46 ++-
15  gdb/dwarf2loc.h                             |   6 +
16  gdb/dwarf2read.c                            |  13 +-
17  gdb/eval.c                                  | 391 +++++++++++++++++++++-----
18  gdb/expprint.c                              |  20 +-
19  gdb/expression.h                            |  18 +-
20  gdb/f-exp.y                                 |  42 ++-
21  gdb/f-valprint.c                            |   8 +-
22  gdb/gdbtypes.c                              |  34 ++-
23  gdb/gdbtypes.h                              |  18 +-
24  gdb/parse.c                                 |  24 +-
25  gdb/rust-exp.y                              |  12 +-
26  gdb/rust-lang.c                             |  17 +-
27  gdb/testsuite/gdb.fortran/static-arrays.exp | 421 ++++++++++++++++++++++++++++
28  gdb/testsuite/gdb.fortran/static-arrays.f90 |  55 ++++
29  gdb/testsuite/gdb.fortran/vla-ptype.exp     |   4 +
30  gdb/testsuite/gdb.fortran/vla-sizeof.exp    |   4 +
31  gdb/testsuite/gdb.fortran/vla-stride.exp    |  44 +++
32  gdb/testsuite/gdb.fortran/vla-stride.f90    |  29 ++
33  gdb/testsuite/gdb.fortran/vla.f90           |  10 +
34  gdb/valarith.c                              |  10 +-
35  gdb/valops.c                                | 197 +++++++++++--
36  gdb/value.h                                 |   2 +
37  23 files changed, 1242 insertions(+), 183 deletions(-)
38 ---
39  gdb/dwarf2loc.c                             |  46 ++-
40  gdb/dwarf2loc.h                             |   6 +
41  gdb/dwarf2read.c                            |  13 +-
42  gdb/eval.c                                  | 391 +++++++++++++++++++++-----
43  gdb/expprint.c                              |  20 +-
44  gdb/expression.h                            |  18 +-
45  gdb/f-exp.y                                 |  42 ++-
46  gdb/f-valprint.c                            |   8 +-
47  gdb/gdbtypes.c                              |  34 ++-
48  gdb/gdbtypes.h                              |  18 +-
49  gdb/parse.c                                 |  24 +-
50  gdb/rust-exp.y                              |  12 +-
51  gdb/rust-lang.c                             |  17 +-
52  gdb/testsuite/gdb.fortran/static-arrays.exp | 421 ++++++++++++++++++++++++++++
53  gdb/testsuite/gdb.fortran/static-arrays.f90 |  55 ++++
54  gdb/testsuite/gdb.fortran/vla-ptype.exp     |   4 +
55  gdb/testsuite/gdb.fortran/vla-sizeof.exp    |   4 +
56  gdb/testsuite/gdb.fortran/vla-stride.exp    |  44 +++
57  gdb/testsuite/gdb.fortran/vla-stride.f90    |  29 ++
58  gdb/testsuite/gdb.fortran/vla.f90           |  10 +
59  gdb/valarith.c                              |  10 +-
60  gdb/valops.c                                | 199 +++++++++++--
61  gdb/value.h                                 |   2 +
62  23 files changed, 1245 insertions(+), 182 deletions(-)
63  create mode 100644 gdb/testsuite/gdb.fortran/static-arrays.exp
64  create mode 100644 gdb/testsuite/gdb.fortran/static-arrays.f90
65  create mode 100644 gdb/testsuite/gdb.fortran/vla-stride.exp
66  create mode 100644 gdb/testsuite/gdb.fortran/vla-stride.f90
67
68 diff --git a/gdb/dwarf2loc.c b/gdb/dwarf2loc.c
69 index 51f133f1b5..5105c8d23a 100644
70 --- a/gdb/dwarf2loc.c
71 +++ b/gdb/dwarf2loc.c
72 @@ -2601,11 +2601,14 @@ dwarf2_locexpr_baton_eval (const struct dwarf2_locexpr_baton *dlbaton,
73  /* See dwarf2loc.h.  */
74  
75  int
76 -dwarf2_evaluate_property (const struct dynamic_prop *prop,
77 +dwarf2_evaluate_property_signed (const struct dynamic_prop *prop,
78                           struct frame_info *frame,
79                           struct property_addr_info *addr_stack,
80 -                         CORE_ADDR *value)
81 +                         CORE_ADDR *value,
82 +                         int is_signed)
83  {
84 +  int rc = 0;
85 +
86    if (prop == NULL)
87      return 0;
88  
89 @@ -2629,7 +2632,7 @@ dwarf2_evaluate_property (const struct dynamic_prop *prop,
90  
91                 *value = value_as_address (val);
92               }
93 -           return 1;
94 +           rc = 1;
95           }
96        }
97        break;
98 @@ -2651,7 +2654,7 @@ dwarf2_evaluate_property (const struct dynamic_prop *prop,
99             if (!value_optimized_out (val))
100               {
101                 *value = value_as_address (val);
102 -               return 1;
103 +               rc = 1;
104               }
105           }
106        }
107 @@ -2659,8 +2662,8 @@ dwarf2_evaluate_property (const struct dynamic_prop *prop,
108  
109      case PROP_CONST:
110        *value = prop->data.const_val;
111 -      return 1;
112 -
113 +      rc = 1;
114 +      break;
115      case PROP_ADDR_OFFSET:
116        {
117         struct dwarf2_property_baton *baton
118 @@ -2681,11 +2684,38 @@ dwarf2_evaluate_property (const struct dynamic_prop *prop,
119           val = value_at (baton->offset_info.type,
120                           pinfo->addr + baton->offset_info.offset);
121         *value = value_as_address (val);
122 -       return 1;
123 +       rc = 1;
124        }
125 +      break;
126      }
127  
128 -  return 0;
129 +  if (rc == 1 && is_signed == 1)
130 +    {
131 +      /* If we have a valid return candidate and it's value is signed,
132 +         we have to sign-extend the value because CORE_ADDR on 64bit machine has
133 +         8 bytes but address size of an 32bit application is 4 bytes.  */
134 +      struct gdbarch * gdbarch = target_gdbarch ();
135 +      const int addr_bit = gdbarch_addr_bit (gdbarch);
136 +      const CORE_ADDR neg_mask = ((~0) <<  (addr_bit - 1));
137 +
138 +      /* Check if signed bit is set and sign-extend values.  */
139 +      if (*value & (neg_mask))
140 +       *value |= (neg_mask );
141 +    }
142 +  return rc;
143 +}
144 +
145 +int
146 +dwarf2_evaluate_property (const struct dynamic_prop *prop,
147 +                         struct frame_info *frame,
148 +                         struct property_addr_info *addr_stack,
149 +                         CORE_ADDR *value)
150 +{
151 +  return dwarf2_evaluate_property_signed (prop,
152 +                                  frame,
153 +                                  addr_stack,
154 +                                  value,
155 +                                  0);
156  }
157  
158  /* See dwarf2loc.h.  */
159 diff --git a/gdb/dwarf2loc.h b/gdb/dwarf2loc.h
160 index f82e7b2d11..74f0597359 100644
161 --- a/gdb/dwarf2loc.h
162 +++ b/gdb/dwarf2loc.h
163 @@ -143,6 +143,12 @@ int dwarf2_evaluate_property (const struct dynamic_prop *prop,
164                               struct property_addr_info *addr_stack,
165                               CORE_ADDR *value);
166  
167 +int dwarf2_evaluate_property_signed (const struct dynamic_prop *prop,
168 +                             struct frame_info *frame,
169 +                             struct property_addr_info *addr_stack,
170 +                             CORE_ADDR *value,
171 +                             int is_signed);
172 +
173  /* A helper for the compiler interface that compiles a single dynamic
174     property to C code.
175  
176 diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
177 index 58da0fc1f9..8fc1f7ec45 100644
178 --- a/gdb/dwarf2read.c
179 +++ b/gdb/dwarf2read.c
180 @@ -17551,7 +17551,7 @@ read_subrange_type (struct die_info *die, struct dwarf2_cu *cu)
181    struct type *base_type, *orig_base_type;
182    struct type *range_type;
183    struct attribute *attr;
184 -  struct dynamic_prop low, high;
185 +  struct dynamic_prop low, high, stride;
186    int low_default_is_valid;
187    int high_bound_is_count = 0;
188    const char *name;
189 @@ -17571,7 +17571,9 @@ read_subrange_type (struct die_info *die, struct dwarf2_cu *cu)
190  
191    low.kind = PROP_CONST;
192    high.kind = PROP_CONST;
193 +  stride.kind = PROP_CONST;
194    high.data.const_val = 0;
195 +  stride.data.const_val = 0;
196  
197    /* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow
198       omitting DW_AT_lower_bound.  */
199 @@ -17604,6 +17606,13 @@ read_subrange_type (struct die_info *die, struct dwarf2_cu *cu)
200        break;
201      }
202  
203 +  attr = dwarf2_attr (die, DW_AT_byte_stride, cu);
204 +  if (attr)
205 +    if (!attr_to_dynamic_prop (attr, die, cu, &stride))
206 +        complaint (&symfile_complaints, _("Missing DW_AT_byte_stride "
207 +                  "- DIE at 0x%x [in module %s]"),
208 +             to_underlying (die->sect_off), objfile_name (cu->objfile));
209 +
210    attr = dwarf2_attr (die, DW_AT_lower_bound, cu);
211    if (attr)
212      attr_to_dynamic_prop (attr, die, cu, &low);
213 @@ -17680,7 +17689,7 @@ read_subrange_type (struct die_info *die, struct dwarf2_cu *cu)
214        && !TYPE_UNSIGNED (base_type) && (high.data.const_val & negative_mask))
215      high.data.const_val |= negative_mask;
216  
217 -  range_type = create_range_type (NULL, orig_base_type, &low, &high);
218 +  range_type = create_range_type (NULL, orig_base_type, &low, &high, &stride);
219  
220    if (high_bound_is_count)
221      TYPE_RANGE_DATA (range_type)->flag_upper_bound_is_count = 1;
222 diff --git a/gdb/eval.c b/gdb/eval.c
223 index 6f74c41b9f..d9bca2791d 100644
224 --- a/gdb/eval.c
225 +++ b/gdb/eval.c
226 @@ -384,29 +384,325 @@ init_array_element (struct value *array, struct value *element,
227    return index;
228  }
229  
230 +/* Evaluates any operation on Fortran arrays or strings with at least
231 +   one user provided parameter.  Expects the input ARRAY to be either
232 +   an array, or a string.  Evaluates EXP by incrementing POS, and
233 +   writes the content from the elt stack into a local struct.  NARGS
234 +   specifies number of literal or range arguments the user provided.
235 +   NARGS must be the same number as ARRAY has dimensions.  */
236 +
237  static struct value *
238 -value_f90_subarray (struct value *array,
239 -                   struct expression *exp, int *pos, enum noside noside)
240 +value_f90_subarray (struct value *array, struct expression *exp,
241 +                   int *pos, int nargs, enum noside noside)
242  {
243 -  int pc = (*pos) + 1;
244 +  int i, dim_count = 0;
245    LONGEST low_bound, high_bound;
246 -  struct type *range = check_typedef (TYPE_INDEX_TYPE (value_type (array)));
247 -  enum range_type range_type
248 -    = (enum range_type) longest_to_int (exp->elts[pc].longconst);
249
250 -  *pos += 3;
251 -
252 -  if (range_type == LOW_BOUND_DEFAULT || range_type == BOTH_BOUND_DEFAULT)
253 -    low_bound = TYPE_LOW_BOUND (range);
254 -  else
255 -    low_bound = value_as_long (evaluate_subexp (NULL_TYPE, exp, pos, noside));
256 +  struct value *new_array = array;
257 +  struct type *array_type = check_typedef (value_type (new_array));
258 +  struct type *elt_type;
259 +
260 +  typedef struct subscript_range
261 +  {
262 +    enum range_type f90_range_type;
263 +    LONGEST low, high, stride;
264 +  } subscript_range;
265 +
266 +  typedef enum subscript_kind
267 +  {
268 +    SUBSCRIPT_RANGE,    /* e.g. "(lowbound:highbound)"  */
269 +    SUBSCRIPT_INDEX    /* e.g. "(literal)"  */
270 +  } kind;
271 +
272 +  /* Local struct to hold user data for Fortran subarray dimensions.  */
273 +  struct subscript_store
274 +  {
275 +    /* For every dimension, we are either working on a range or an index
276 +       expression, so we store this info separately for later.  */
277 +    enum subscript_kind kind;
278 +
279 +    /* We also store either the lower and upper bound info, or the index
280 +       number.  Before evaluation of the input values, we do not know if we are
281 +       actually working on a range of ranges, or an index in a range.  So as a
282 +       first step we store all input in a union.  The array calculation itself
283 +       deals with this later on.  */
284 +    union element_range
285 +    {
286 +      subscript_range range;
287 +      LONGEST number;
288 +    } U;
289 +  } *subscript_array;
290 +
291 +  /* Check if the number of arguments provided by the user matches
292 +     the number of dimension of the array.  A string has only one
293 +     dimension.  */
294 +  if (nargs != calc_f77_array_dims (value_type (new_array)))
295 +    error (_("Wrong number of subscripts"));
296 +
297 +  subscript_array = (struct subscript_store*) alloca (sizeof (*subscript_array) * nargs);
298 +
299 +  /* Parse the user input into the SUBSCRIPT_ARRAY to store it.  We need
300 +     to evaluate it first, as the input is from left-to-right.  The
301 +     array is stored from right-to-left.  So we have to use the user
302 +     input in reverse order.  Later on, we need the input information to
303 +     re-calculate the output array.  For multi-dimensional arrays, we
304 +     can be dealing with any possible combination of ranges and indices
305 +     for every dimension.  */
306 +  for (i = 0; i < nargs; i++)
307 +    {
308 +      struct subscript_store *index = &subscript_array[i];
309  
310 -  if (range_type == HIGH_BOUND_DEFAULT || range_type == BOTH_BOUND_DEFAULT)
311 -    high_bound = TYPE_HIGH_BOUND (range);
312 -  else
313 -    high_bound = value_as_long (evaluate_subexp (NULL_TYPE, exp, pos, noside));
314 +      /* The user input is a range, with or without lower and upper bound.
315 +        E.g.: "p arry(2:5)", "p arry( :5)", "p arry( : )", etc.  */
316 +      if (exp->elts[*pos].opcode == OP_RANGE)
317 +       {
318 +         int pc = (*pos) + 1;
319 +         subscript_range *range;
320 +
321 +         index->kind = SUBSCRIPT_RANGE;
322 +         range = &index->U.range;
323 +
324 +         *pos += 3;
325 +         range->f90_range_type = (enum range_type) exp->elts[pc].longconst;
326 +
327 +         /* If a lower bound was provided by the user, the bit has been
328 +            set and we can assign the value from the elt stack.  Same for
329 +            upper bound.  */
330 +         if ((range->f90_range_type & SUBARRAY_LOW_BOUND)
331 +             == SUBARRAY_LOW_BOUND)
332 +           range->low = value_as_long (evaluate_subexp (NULL_TYPE, exp,
333 +                                                        pos, noside));
334 +         if ((range->f90_range_type & SUBARRAY_HIGH_BOUND)
335 +             == SUBARRAY_HIGH_BOUND)
336 +           range->high = value_as_long (evaluate_subexp (NULL_TYPE, exp,
337 +                                                         pos, noside));
338 +
339 +         /* Assign the user's stride value if provided.  */
340 +         if ((range->f90_range_type & SUBARRAY_STRIDE) == SUBARRAY_STRIDE)
341 +           range->stride = value_as_long (evaluate_subexp (NULL_TYPE, exp,
342 +                                                            pos, noside));
343 +
344 +         /* Assign the default stride value '1'.  */
345 +         else
346 +           range->stride = 1;
347 +
348 +         /* Check the provided stride value is illegal, aka '0'.  */
349 +         if (range->stride == 0)
350 +           error (_("Stride must not be 0"));
351 +       }
352 +      /* User input is an index.  E.g.: "p arry(5)".  */
353 +      else
354 +       {
355 +         struct value *val;
356 +
357 +         index->kind = SUBSCRIPT_INDEX;
358 +
359 +         /* Evaluate each subscript; it must be a legal integer in F77.  This
360 +            ensures the validity of the provided index.  */
361 +         val = evaluate_subexp_with_coercion (exp, pos, noside);
362 +         index->U.number = value_as_long (val);
363 +       }
364 +
365 +    }
366 +
367 +  /* Traverse the array from right to left and set the high and low bounds
368 +     for later use.  */
369 +  for (i = nargs - 1; i >= 0; i--)
370 +    {
371 +      struct subscript_store *index = &subscript_array[i];
372 +      struct type *index_type = TYPE_INDEX_TYPE (array_type);
373 +
374 +      switch (index->kind)
375 +       {
376 +       case SUBSCRIPT_RANGE:
377 +         {
378 +
379 +           /* When we hit the first range specified by the user, we must
380 +              treat any subsequent user entry as a range.  We simply
381 +              increment DIM_COUNT which tells us how many times we are
382 +              calling VALUE_SLICE_1.  */
383 +           subscript_range *range = &index->U.range;
384 +
385 +           /* If no lower bound was provided by the user, we take the
386 +              default boundary.  Same for the high bound.  */
387 +           if ((range->f90_range_type & SUBARRAY_LOW_BOUND) == 0)
388 +             range->low = TYPE_LOW_BOUND (index_type);
389 +
390 +           if ((range->f90_range_type & SUBARRAY_HIGH_BOUND) == 0)
391 +             range->high = TYPE_HIGH_BOUND (index_type);
392 +
393 +           /* Both user provided low and high bound have to be inside the
394 +              array bounds.  Throw an error if not.  */
395 +           if (range->low < TYPE_LOW_BOUND (index_type)
396 +               || range->low > TYPE_HIGH_BOUND (index_type)
397 +               || range->high < TYPE_LOW_BOUND (index_type)
398 +               || range->high > TYPE_HIGH_BOUND (index_type))
399 +             error (_("provided bound(s) outside array bound(s)"));
400 +
401 +           /* For a negative stride the lower boundary must be larger than the
402 +              upper boundary.
403 +              For a positive stride the lower boundary must be smaller than the
404 +              upper boundary.  */
405 +           if ((range->stride < 0 && range->low < range->high)
406 +               || (range->stride > 0 && range->low > range->high))
407 +             error (_("Wrong value provided for stride and boundaries"));
408 +
409 +         }
410 +         break;
411 +
412 +       case SUBSCRIPT_INDEX:
413 +         break;
414 +
415 +       }
416 +
417 +       array_type = TYPE_TARGET_TYPE (array_type);
418 +    }
419 +
420 +  /* Reset ARRAY_TYPE before slicing.*/
421 +  array_type = check_typedef (value_type (new_array));
422 +
423 +  /* Traverse the array from right to left and evaluate each corresponding
424 +     user input.  VALUE_SUBSCRIPT is called for every index, until a range
425 +     expression is evaluated.  After a range expression has been evaluated,
426 +     every subsequent expression is also treated as a range.  */
427 +  for (i = nargs - 1; i >= 0; i--)
428 +    {
429 +      struct subscript_store *index = &subscript_array[i];
430 +      struct type *index_type = TYPE_INDEX_TYPE (array_type);
431 +
432 +      switch (index->kind)
433 +       {
434 +       case SUBSCRIPT_RANGE:
435 +         {
436 +
437 +           /* When we hit the first range specified by the user, we must
438 +              treat any subsequent user entry as a range.  We simply
439 +              increment DIM_COUNT which tells us how many times we are
440 +              calling VALUE_SLICE_1.  */
441 +           subscript_range *range = &index->U.range;
442 +
443 +           /* DIM_COUNT counts every user argument that is treated as a range.
444 +              This is necessary for expressions like 'print array(7, 8:9).
445 +              Here the first argument is a literal, but must be treated as a
446 +              range argument to allow the correct output representation.  */
447 +           dim_count++;
448 +
449 +           new_array
450 +             = value_slice_1 (new_array, range->low,
451 +                              range->high - range->low + 1,
452 +                              range->stride, dim_count);
453 +         }
454 +         break;
455 +
456 +       case SUBSCRIPT_INDEX:
457 +         {
458 +           /* DIM_COUNT only stays '0' when no range argument was processed
459 +              before, starting from the last dimension.  This way we can
460 +              reduce the number of dimensions from the result array.
461 +              However, if a range has been processed before an index, we
462 +              treat the index like a range with equal low- and high bounds
463 +              to get the value offset right.  */
464 +           if (dim_count == 0)
465 +             new_array
466 +               = value_subscripted_rvalue (new_array, index->U.number,
467 +                                           f77_get_lowerbound (value_type
468 +                                                                 (new_array)));
469 +           else
470 +             {
471 +               dim_count++;
472 +
473 +               /* We might end up here, because we have to treat the provided
474 +                  index like a range. But now VALUE_SUBSCRIPTED_RVALUE
475 +                  cannot do the range checks for us. So we have to make sure
476 +                  ourselves that the user provided index is inside the
477 +                  array bounds.  Throw an error if not.  */
478 +               if (index->U.number < TYPE_LOW_BOUND (index_type)
479 +                   && index->U.number > TYPE_HIGH_BOUND (index_type))
480 +                 error (_("provided bound(s) outside array bound(s)"));
481 +
482 +               if (index->U.number > TYPE_LOW_BOUND (index_type)
483 +                   && index->U.number > TYPE_HIGH_BOUND (index_type))
484 +                 error (_("provided bound(s) outside array bound(s)"));
485 +
486 +               new_array = value_slice_1 (new_array,
487 +                                          index->U.number,
488 +                                          1, /* COUNT is '1' element  */
489 +                                          1, /* STRIDE set to '1'  */
490 +                                          dim_count);
491 +             }
492 +
493 +         }
494 +         break;
495 +       }
496 +      array_type = TYPE_TARGET_TYPE (array_type);
497 +    }
498 +
499 +  /* With DIM_COUNT > 1 we currently have a one dimensional array, but expect
500 +     an array of arrays, depending on how many ranges have been provided by
501 +     the user.  So we need to rebuild the array dimensions for printing it
502 +     correctly.
503 +     Starting from right to left in the user input, after we hit the first
504 +     range argument every subsequent argument is also treated as a range.
505 +     E.g.:
506 +     "p ary(3, 7, 2:15)" in Fortran has only 1 dimension, but we calculated 3
507 +     ranges.
508 +     "p ary(3, 7:12, 4)" in Fortran has only 1 dimension, but we calculated 2
509 +     ranges.
510 +     "p ary(2:4, 5, 7)" in Fortran has only 1 dimension, and we calculated 1
511 +     range.  */
512 +  if (dim_count > 1)
513 +    {
514 +      struct value *v = NULL;
515 +
516 +      elt_type = TYPE_TARGET_TYPE (value_type (new_array));
517 +
518 +      /* Every SUBSCRIPT_RANGE in the user input signifies an actual range in
519 +        the output array.  So we traverse the SUBSCRIPT_ARRAY again, looking
520 +        for a range entry.  When we find one, we use the range info to create
521 +        an additional range_type to set the correct bounds and dimensions for
522 +        the output array.  In addition, we may have a stride value that is not
523 +        '1', forcing us to adjust the number of elements in a range, according
524 +        to the stride value.  */
525 +      for (i = 0; i < nargs; i++)
526 +       {
527 +         struct subscript_store *index = &subscript_array[i];
528 +
529 +         if (index->kind == SUBSCRIPT_RANGE)
530 +           {
531 +             struct type *range_type, *interim_array_type;
532 +
533 +             int new_length;
534  
535 -  return value_slice (array, low_bound, high_bound - low_bound + 1);
536 +             /* The length of a sub-dimension with all elements between the
537 +                bounds plus the start element itself.  It may be modified by
538 +                a user provided stride value.  */
539 +             new_length = index->U.range.high - index->U.range.low;
540 +
541 +             new_length /= index->U.range.stride;
542 +
543 +             range_type
544 +               = create_static_range_type (NULL,
545 +                                           elt_type,
546 +                                           index->U.range.low,
547 +                                           index->U.range.low + new_length);
548 +
549 +             interim_array_type = create_array_type (NULL,
550 +                                                     elt_type,
551 +                                                     range_type);
552 +
553 +             TYPE_CODE (interim_array_type)
554 +               = TYPE_CODE (value_type (new_array));
555 +
556 +             v = allocate_value (interim_array_type);
557 +
558 +             elt_type = value_type (v);
559 +           }
560 +
561 +       }
562 +      value_contents_copy (v, 0, new_array, 0, TYPE_LENGTH (elt_type));
563 +      return v;
564 +    }
565 +
566 +  return new_array;
567  }
568  
569  
570 @@ -1928,19 +2224,8 @@ evaluate_subexp_standard (struct type *expect_type,
571        switch (code)
572         {
573         case TYPE_CODE_ARRAY:
574 -         if (exp->elts[*pos].opcode == OP_RANGE)
575 -           return value_f90_subarray (arg1, exp, pos, noside);
576 -         else
577 -           goto multi_f77_subscript;
578 -
579         case TYPE_CODE_STRING:
580 -         if (exp->elts[*pos].opcode == OP_RANGE)
581 -           return value_f90_subarray (arg1, exp, pos, noside);
582 -         else
583 -           {
584 -             arg2 = evaluate_subexp_with_coercion (exp, pos, noside);
585 -             return value_subscript (arg1, value_as_long (arg2));
586 -           }
587 +         return value_f90_subarray (arg1, exp, pos, nargs, noside);
588  
589         case TYPE_CODE_PTR:
590         case TYPE_CODE_FUNC:
591 @@ -2336,49 +2621,6 @@ evaluate_subexp_standard (struct type *expect_type,
592         }
593        return (arg1);
594  
595 -    multi_f77_subscript:
596 -      {
597 -       LONGEST subscript_array[MAX_FORTRAN_DIMS];
598 -       int ndimensions = 1, i;
599 -       struct value *array = arg1;
600 -
601 -       if (nargs > MAX_FORTRAN_DIMS)
602 -         error (_("Too many subscripts for F77 (%d Max)"), MAX_FORTRAN_DIMS);
603 -
604 -       ndimensions = calc_f77_array_dims (type);
605 -
606 -       if (nargs != ndimensions)
607 -         error (_("Wrong number of subscripts"));
608 -
609 -       gdb_assert (nargs > 0);
610 -
611 -       /* Now that we know we have a legal array subscript expression 
612 -          let us actually find out where this element exists in the array.  */
613 -
614 -       /* Take array indices left to right.  */
615 -       for (i = 0; i < nargs; i++)
616 -         {
617 -           /* Evaluate each subscript; it must be a legal integer in F77.  */
618 -           arg2 = evaluate_subexp_with_coercion (exp, pos, noside);
619 -
620 -           /* Fill in the subscript array.  */
621 -
622 -           subscript_array[i] = value_as_long (arg2);
623 -         }
624 -
625 -       /* Internal type of array is arranged right to left.  */
626 -       for (i = nargs; i > 0; i--)
627 -         {
628 -           struct type *array_type = check_typedef (value_type (array));
629 -           LONGEST index = subscript_array[i - 1];
630 -
631 -           array = value_subscripted_rvalue (array, index,
632 -                                             f77_get_lowerbound (array_type));
633 -         }
634 -
635 -       return array;
636 -      }
637 -
638      case BINOP_LOGICAL_AND:
639        arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
640        if (noside == EVAL_SKIP)
641 @@ -3282,6 +3524,9 @@ calc_f77_array_dims (struct type *array_type)
642    int ndimen = 1;
643    struct type *tmp_type;
644  
645 +  if (TYPE_CODE (array_type) == TYPE_CODE_STRING)
646 +    return 1;
647 +
648    if ((TYPE_CODE (array_type) != TYPE_CODE_ARRAY))
649      error (_("Can't get dimensions for a non-array type"));
650  
651 diff --git a/gdb/expprint.c b/gdb/expprint.c
652 index ac5ae0fea1..41bb357a27 100644
653 --- a/gdb/expprint.c
654 +++ b/gdb/expprint.c
655 @@ -581,12 +581,10 @@ print_subexp_standard (struct expression *exp, int *pos,
656         *pos += 2;
657  
658         fputs_filtered ("RANGE(", stream);
659 -       if (range_type == HIGH_BOUND_DEFAULT
660 -           || range_type == NONE_BOUND_DEFAULT)
661 +       if ((range_type & SUBARRAY_LOW_BOUND) == SUBARRAY_LOW_BOUND)
662           print_subexp (exp, pos, stream, PREC_ABOVE_COMMA);
663         fputs_filtered ("..", stream);
664 -       if (range_type == LOW_BOUND_DEFAULT
665 -           || range_type == NONE_BOUND_DEFAULT)
666 +       if ((range_type & SUBARRAY_HIGH_BOUND) == SUBARRAY_HIGH_BOUND)
667           print_subexp (exp, pos, stream, PREC_ABOVE_COMMA);
668         fputs_filtered (")", stream);
669         return;
670 @@ -1094,16 +1092,16 @@ dump_subexp_body_standard (struct expression *exp,
671  
672         switch (range_type)
673           {
674 -         case BOTH_BOUND_DEFAULT:
675 +         case SUBARRAY_NONE_BOUND:
676             fputs_filtered ("Range '..'", stream);
677             break;
678 -         case LOW_BOUND_DEFAULT:
679 +         case SUBARRAY_HIGH_BOUND:
680             fputs_filtered ("Range '..EXP'", stream);
681             break;
682 -         case HIGH_BOUND_DEFAULT:
683 +         case SUBARRAY_LOW_BOUND:
684             fputs_filtered ("Range 'EXP..'", stream);
685             break;
686 -         case NONE_BOUND_DEFAULT:
687 +         case (SUBARRAY_LOW_BOUND | SUBARRAY_HIGH_BOUND):
688             fputs_filtered ("Range 'EXP..EXP'", stream);
689             break;
690           default:
691 @@ -1111,11 +1109,9 @@ dump_subexp_body_standard (struct expression *exp,
692             break;
693           }
694  
695 -       if (range_type == HIGH_BOUND_DEFAULT
696 -           || range_type == NONE_BOUND_DEFAULT)
697 +       if ((range_type & SUBARRAY_LOW_BOUND) == SUBARRAY_LOW_BOUND)
698           elt = dump_subexp (exp, stream, elt);
699 -       if (range_type == LOW_BOUND_DEFAULT
700 -           || range_type == NONE_BOUND_DEFAULT)
701 +       if ((range_type & SUBARRAY_HIGH_BOUND) == SUBARRAY_HIGH_BOUND)
702           elt = dump_subexp (exp, stream, elt);
703        }
704        break;
705 diff --git a/gdb/expression.h b/gdb/expression.h
706 index a783ea5fef..be24792eb6 100644
707 --- a/gdb/expression.h
708 +++ b/gdb/expression.h
709 @@ -153,17 +153,17 @@ extern void dump_raw_expression (struct expression *,
710                                  struct ui_file *, const char *);
711  extern void dump_prefix_expression (struct expression *, struct ui_file *);
712  
713 -/* In an OP_RANGE expression, either bound could be empty, indicating
714 -   that its value is by default that of the corresponding bound of the
715 -   array or string.  So we have four sorts of subrange.  This
716 -   enumeration type is to identify this.  */
717 -   
718 +/* In an OP_RANGE expression, either bound can be provided by the user, or not.
719 +   In addition to this, the user can also specify a stride value to indicated
720 +   only certain elements of the array.  This enumeration type is to identify
721 +   this.  */
722 +
723  enum range_type
724    {
725 -    BOTH_BOUND_DEFAULT,                /* "(:)"  */
726 -    LOW_BOUND_DEFAULT,         /* "(:high)"  */
727 -    HIGH_BOUND_DEFAULT,                /* "(low:)"  */
728 -    NONE_BOUND_DEFAULT         /* "(low:high)"  */
729 +    SUBARRAY_NONE_BOUND = 0x0,         /* "( : )"  */
730 +    SUBARRAY_LOW_BOUND = 0x1,          /* "(low:)"  */
731 +    SUBARRAY_HIGH_BOUND = 0x2,         /* "(:high)"  */
732 +    SUBARRAY_STRIDE = 0x4              /* "(::stride)"  */
733    };
734  
735  #endif /* !defined (EXPRESSION_H) */
736 diff --git a/gdb/f-exp.y b/gdb/f-exp.y
737 index 6495e03cc5..cd89bb7ca2 100644
738 --- a/gdb/f-exp.y
739 +++ b/gdb/f-exp.y
740 @@ -257,31 +257,63 @@ arglist : subrange
741     
742  arglist        :       arglist ',' exp   %prec ABOVE_COMMA
743                         { arglist_len++; }
744 +       |       arglist ',' subrange    %prec ABOVE_COMMA
745 +                       { arglist_len++; }
746         ;
747  
748  /* There are four sorts of subrange types in F90.  */
749  
750  subrange:      exp ':' exp     %prec ABOVE_COMMA
751 -                       { write_exp_elt_opcode (pstate, OP_RANGE); 
752 -                         write_exp_elt_longcst (pstate, NONE_BOUND_DEFAULT);
753 +                       { write_exp_elt_opcode (pstate, OP_RANGE);
754 +                         write_exp_elt_longcst (pstate,
755 +                                                SUBARRAY_LOW_BOUND | SUBARRAY_HIGH_BOUND);
756                           write_exp_elt_opcode (pstate, OP_RANGE); }
757         ;
758  
759  subrange:      exp ':' %prec ABOVE_COMMA
760                         { write_exp_elt_opcode (pstate, OP_RANGE);
761 -                         write_exp_elt_longcst (pstate, HIGH_BOUND_DEFAULT);
762 +                         write_exp_elt_longcst (pstate, SUBARRAY_LOW_BOUND);
763                           write_exp_elt_opcode (pstate, OP_RANGE); }
764         ;
765  
766  subrange:      ':' exp %prec ABOVE_COMMA
767                         { write_exp_elt_opcode (pstate, OP_RANGE);
768 -                         write_exp_elt_longcst (pstate, LOW_BOUND_DEFAULT);
769 +                         write_exp_elt_longcst (pstate, SUBARRAY_HIGH_BOUND);
770                           write_exp_elt_opcode (pstate, OP_RANGE); }
771         ;
772  
773  subrange:      ':'     %prec ABOVE_COMMA
774                         { write_exp_elt_opcode (pstate, OP_RANGE);
775 -                         write_exp_elt_longcst (pstate, BOTH_BOUND_DEFAULT);
776 +                         write_exp_elt_longcst (pstate, SUBARRAY_NONE_BOUND);
777 +                         write_exp_elt_opcode (pstate, OP_RANGE); }
778 +       ;
779 +
780 +/* Each subrange type can have a stride argument.  */
781 +subrange:      exp ':' exp ':' exp %prec ABOVE_COMMA
782 +                       { write_exp_elt_opcode (pstate, OP_RANGE);
783 +                         write_exp_elt_longcst (pstate, SUBARRAY_LOW_BOUND
784 +                                                | SUBARRAY_HIGH_BOUND
785 +                                                | SUBARRAY_STRIDE);
786 +                         write_exp_elt_opcode (pstate, OP_RANGE); }
787 +       ;
788 +
789 +subrange:      exp ':' ':' exp %prec ABOVE_COMMA
790 +                       { write_exp_elt_opcode (pstate, OP_RANGE);
791 +                         write_exp_elt_longcst (pstate, SUBARRAY_LOW_BOUND
792 +                                                | SUBARRAY_STRIDE);
793 +                         write_exp_elt_opcode (pstate, OP_RANGE); }
794 +       ;
795 +
796 +subrange:      ':' exp ':' exp %prec ABOVE_COMMA
797 +                       { write_exp_elt_opcode (pstate, OP_RANGE);
798 +                         write_exp_elt_longcst (pstate, SUBARRAY_HIGH_BOUND
799 +                                                | SUBARRAY_STRIDE);
800 +                         write_exp_elt_opcode (pstate, OP_RANGE); }
801 +       ;
802 +
803 +subrange:      ':' ':' exp %prec ABOVE_COMMA
804 +                       { write_exp_elt_opcode (pstate, OP_RANGE);
805 +                         write_exp_elt_longcst (pstate, SUBARRAY_STRIDE);
806                           write_exp_elt_opcode (pstate, OP_RANGE); }
807         ;
808  
809 diff --git a/gdb/f-valprint.c b/gdb/f-valprint.c
810 index 903f2af638..b4067a8460 100644
811 --- a/gdb/f-valprint.c
812 +++ b/gdb/f-valprint.c
813 @@ -119,8 +119,14 @@ f77_print_array_1 (int nss, int ndimensions, struct type *type,
814  
815    if (nss != ndimensions)
816      {
817 -      size_t dim_size = TYPE_LENGTH (TYPE_TARGET_TYPE (type));
818 +      size_t dim_size;
819        size_t offs = 0;
820 +      LONGEST byte_stride = abs (TYPE_BYTE_STRIDE (range_type));
821 +
822 +      if (byte_stride)
823 +        dim_size = byte_stride;
824 +      else
825 +        dim_size = TYPE_LENGTH (TYPE_TARGET_TYPE (type));
826  
827        for (i = lowerbound;
828            (i < upperbound + 1 && (*elts) < options->print_max);
829 diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c
830 index 43fe56e487..a72e2b3e0a 100644
831 --- a/gdb/gdbtypes.c
832 +++ b/gdb/gdbtypes.c
833 @@ -902,7 +902,8 @@ operator== (const range_bounds &l, const range_bounds &r)
834  struct type *
835  create_range_type (struct type *result_type, struct type *index_type,
836                    const struct dynamic_prop *low_bound,
837 -                  const struct dynamic_prop *high_bound)
838 +                  const struct dynamic_prop *high_bound,
839 +                  const struct dynamic_prop *stride)
840  {
841    if (result_type == NULL)
842      result_type = alloc_type_copy (index_type);
843 @@ -917,6 +918,7 @@ create_range_type (struct type *result_type, struct type *index_type,
844      TYPE_ZALLOC (result_type, sizeof (struct range_bounds));
845    TYPE_RANGE_DATA (result_type)->low = *low_bound;
846    TYPE_RANGE_DATA (result_type)->high = *high_bound;
847 +  TYPE_RANGE_DATA (result_type)->stride = *stride;
848  
849    if (low_bound->kind == PROP_CONST && low_bound->data.const_val >= 0)
850      TYPE_UNSIGNED (result_type) = 1;
851 @@ -945,7 +947,7 @@ struct type *
852  create_static_range_type (struct type *result_type, struct type *index_type,
853                           LONGEST low_bound, LONGEST high_bound)
854  {
855 -  struct dynamic_prop low, high;
856 +  struct dynamic_prop low, high, stride;
857  
858    low.kind = PROP_CONST;
859    low.data.const_val = low_bound;
860 @@ -953,7 +955,11 @@ create_static_range_type (struct type *result_type, struct type *index_type,
861    high.kind = PROP_CONST;
862    high.data.const_val = high_bound;
863  
864 -  result_type = create_range_type (result_type, index_type, &low, &high);
865 +  stride.kind = PROP_CONST;
866 +  stride.data.const_val = 0;
867 +
868 +  result_type = create_range_type (result_type, index_type,
869 +                                   &low, &high, &stride);
870  
871    return result_type;
872  }
873 @@ -1171,16 +1177,20 @@ create_array_type_with_stride (struct type *result_type,
874        && (!type_not_associated (result_type)
875           && !type_not_allocated (result_type)))
876      {
877 -      LONGEST low_bound, high_bound;
878 +      LONGEST low_bound, high_bound, byte_stride;
879  
880        if (get_discrete_bounds (range_type, &low_bound, &high_bound) < 0)
881         low_bound = high_bound = 0;
882        element_type = check_typedef (element_type);
883 +      byte_stride = abs (TYPE_BYTE_STRIDE (range_type));
884 +
885        /* Be careful when setting the array length.  Ada arrays can be
886          empty arrays with the high_bound being smaller than the low_bound.
887          In such cases, the array length should be zero.  */
888        if (high_bound < low_bound)
889         TYPE_LENGTH (result_type) = 0;
890 +      else if (byte_stride > 0)
891 +       TYPE_LENGTH (result_type) = byte_stride * (high_bound - low_bound + 1);
892        else if (bit_stride > 0)
893         TYPE_LENGTH (result_type) =
894           (bit_stride * (high_bound - low_bound + 1) + 7) / 8;
895 @@ -1992,12 +2002,12 @@ resolve_dynamic_range (struct type *dyn_range_type,
896    CORE_ADDR value;
897    struct type *static_range_type, *static_target_type;
898    const struct dynamic_prop *prop;
899 -  struct dynamic_prop low_bound, high_bound;
900 +  struct dynamic_prop low_bound, high_bound, stride;
901  
902    gdb_assert (TYPE_CODE (dyn_range_type) == TYPE_CODE_RANGE);
903  
904    prop = &TYPE_RANGE_DATA (dyn_range_type)->low;
905 -  if (dwarf2_evaluate_property (prop, NULL, addr_stack, &value))
906 +  if (dwarf2_evaluate_property_signed (prop, NULL, addr_stack, &value, 1))
907      {
908        low_bound.kind = PROP_CONST;
909        low_bound.data.const_val = value;
910 @@ -2009,7 +2019,7 @@ resolve_dynamic_range (struct type *dyn_range_type,
911      }
912  
913    prop = &TYPE_RANGE_DATA (dyn_range_type)->high;
914 -  if (dwarf2_evaluate_property (prop, NULL, addr_stack, &value))
915 +  if (dwarf2_evaluate_property_signed (prop, NULL, addr_stack, &value, 1))
916      {
917        high_bound.kind = PROP_CONST;
918        high_bound.data.const_val = value;
919 @@ -2024,12 +2034,20 @@ resolve_dynamic_range (struct type *dyn_range_type,
920        high_bound.data.const_val = 0;
921      }
922  
923 +  prop = &TYPE_RANGE_DATA (dyn_range_type)->stride;
924 +  if (dwarf2_evaluate_property_signed (prop, NULL, addr_stack, &value, 1))
925 +    {
926 +      stride.kind = PROP_CONST;
927 +      stride.data.const_val = value;
928 +    }
929 +
930    static_target_type
931      = resolve_dynamic_type_internal (TYPE_TARGET_TYPE (dyn_range_type),
932                                      addr_stack, 0);
933    static_range_type = create_range_type (copy_type (dyn_range_type),
934                                          static_target_type,
935 -                                        &low_bound, &high_bound);
936 +                                        &low_bound, &high_bound, &stride);
937 +
938    TYPE_RANGE_DATA (static_range_type)->flag_bound_evaluated = 1;
939    return static_range_type;
940  }
941 diff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h
942 index 92ca85c295..179238ce82 100644
943 --- a/gdb/gdbtypes.h
944 +++ b/gdb/gdbtypes.h
945 @@ -560,6 +560,10 @@ struct range_bounds
946  
947    struct dynamic_prop high;
948  
949 +  /* * Stride of range.  */
950 +
951 +  struct dynamic_prop stride;
952 +
953    /* True if HIGH range bound contains the number of elements in the
954       subrange. This affects how the final hight bound is computed.  */
955  
956 @@ -731,7 +735,6 @@ struct main_type
957      /* * Union member used for range types.  */
958  
959      struct range_bounds *bounds;
960 -
961    } flds_bnds;
962  
963    /* * Slot to point to additional language-specific fields of this
964 @@ -1253,6 +1256,15 @@ extern void allocate_gnat_aux_type (struct type *);
965    TYPE_RANGE_DATA(range_type)->high.kind
966  #define TYPE_LOW_BOUND_KIND(range_type) \
967    TYPE_RANGE_DATA(range_type)->low.kind
968 +#define TYPE_BYTE_STRIDE(range_type) \
969 +  TYPE_RANGE_DATA(range_type)->stride.data.const_val
970 +#define TYPE_BYTE_STRIDE_BLOCK(range_type) \
971 +  TYPE_RANGE_DATA(range_type)->stride.data.locexpr
972 +#define TYPE_BYTE_STRIDE_LOCLIST(range_type) \
973 +  TYPE_RANGE_DATA(range_type)->stride.data.loclist
974 +#define TYPE_BYTE_STRIDE_KIND(range_type) \
975 +  TYPE_RANGE_DATA(range_type)->stride.kind
976 +
977  
978  /* Property accessors for the type data location.  */
979  #define TYPE_DATA_LOCATION(thistype) \
980 @@ -1287,6 +1299,9 @@ extern void allocate_gnat_aux_type (struct type *);
981     TYPE_HIGH_BOUND_UNDEFINED(TYPE_INDEX_TYPE(arraytype))
982  #define TYPE_ARRAY_LOWER_BOUND_IS_UNDEFINED(arraytype) \
983     TYPE_LOW_BOUND_UNDEFINED(TYPE_INDEX_TYPE(arraytype))
984 +#define TYPE_ARRAY_STRIDE_IS_UNDEFINED(arraytype) \
985 +   (TYPE_BYTE_STRIDE(TYPE_INDEX_TYPE(arraytype)) == 0)
986 +
987  
988  #define TYPE_ARRAY_UPPER_BOUND_VALUE(arraytype) \
989     (TYPE_HIGH_BOUND(TYPE_INDEX_TYPE((arraytype))))
990 @@ -1818,6 +1833,7 @@ extern struct type *create_array_type_with_stride
991     struct dynamic_prop *, unsigned int);
992  
993  extern struct type *create_range_type (struct type *, struct type *,
994 +                                      const struct dynamic_prop *,
995                                        const struct dynamic_prop *,
996                                        const struct dynamic_prop *);
997  
998 diff --git a/gdb/parse.c b/gdb/parse.c
999 index 8b2bb22c76..e1bf3edbe2 100644
1000 --- a/gdb/parse.c
1001 +++ b/gdb/parse.c
1002 @@ -984,22 +984,20 @@ operator_length_standard (const struct expression *expr, int endpos,
1003  
1004      case OP_RANGE:
1005        oplen = 3;
1006 +      args = 0;
1007        range_type = (enum range_type)
1008         longest_to_int (expr->elts[endpos - 2].longconst);
1009  
1010 -      switch (range_type)
1011 -       {
1012 -       case LOW_BOUND_DEFAULT:
1013 -       case HIGH_BOUND_DEFAULT:
1014 -         args = 1;
1015 -         break;
1016 -       case BOTH_BOUND_DEFAULT:
1017 -         args = 0;
1018 -         break;
1019 -       case NONE_BOUND_DEFAULT:
1020 -         args = 2;
1021 -         break;
1022 -       }
1023 +      /* Increment the argument counter for each argument
1024 +        provided by the user.  */
1025 +      if ((range_type & SUBARRAY_LOW_BOUND) == SUBARRAY_LOW_BOUND)
1026 +       args++;
1027 +
1028 +      if ((range_type & SUBARRAY_HIGH_BOUND) == SUBARRAY_HIGH_BOUND)
1029 +       args++;
1030 +
1031 +      if ((range_type & SUBARRAY_STRIDE) == SUBARRAY_STRIDE)
1032 +       args++;
1033  
1034        break;
1035  
1036 diff --git a/gdb/rust-exp.y b/gdb/rust-exp.y
1037 index 199e87671e..397a92dfdb 100644
1038 --- a/gdb/rust-exp.y
1039 +++ b/gdb/rust-exp.y
1040 @@ -2448,23 +2448,17 @@ convert_ast_to_expression (struct parser_state *state,
1041  
1042      case OP_RANGE:
1043        {
1044 -       enum range_type kind = BOTH_BOUND_DEFAULT;
1045 +       enum range_type kind = SUBARRAY_NONE_BOUND;
1046  
1047         if (operation->left.op != NULL)
1048           {
1049             convert_ast_to_expression (state, operation->left.op, top);
1050 -           kind = HIGH_BOUND_DEFAULT;
1051 +           kind = SUBARRAY_LOW_BOUND;
1052           }
1053         if (operation->right.op != NULL)
1054           {
1055             convert_ast_to_expression (state, operation->right.op, top);
1056 -           if (kind == BOTH_BOUND_DEFAULT)
1057 -             kind = LOW_BOUND_DEFAULT;
1058 -           else
1059 -             {
1060 -               gdb_assert (kind == HIGH_BOUND_DEFAULT);
1061 -               kind = NONE_BOUND_DEFAULT;
1062 -             }
1063 +           kind = (range_type) (kind | SUBARRAY_HIGH_BOUND);
1064           }
1065         write_exp_elt_opcode (state, OP_RANGE);
1066         write_exp_elt_longcst (state, kind);
1067 diff --git a/gdb/rust-lang.c b/gdb/rust-lang.c
1068 index f7bec33a42..cb924e084d 100644
1069 --- a/gdb/rust-lang.c
1070 +++ b/gdb/rust-lang.c
1071 @@ -1366,9 +1366,9 @@ rust_range (struct expression *exp, int *pos, enum noside noside)
1072    kind = (enum range_type) longest_to_int (exp->elts[*pos + 1].longconst);
1073    *pos += 3;
1074  
1075 -  if (kind == HIGH_BOUND_DEFAULT || kind == NONE_BOUND_DEFAULT)
1076 +  if ((kind & SUBARRAY_LOW_BOUND) == SUBARRAY_LOW_BOUND)
1077      low = evaluate_subexp (NULL_TYPE, exp, pos, noside);
1078 -  if (kind == LOW_BOUND_DEFAULT || kind == NONE_BOUND_DEFAULT)
1079 +  if ((kind & SUBARRAY_HIGH_BOUND) == SUBARRAY_HIGH_BOUND)
1080      high = evaluate_subexp (NULL_TYPE, exp, pos, noside);
1081  
1082    if (noside == EVAL_SKIP)
1083 @@ -1457,7 +1457,7 @@ rust_compute_range (struct type *type, struct value *range,
1084  
1085    *low = 0;
1086    *high = 0;
1087 -  *kind = BOTH_BOUND_DEFAULT;
1088 +  *kind = SUBARRAY_NONE_BOUND;
1089  
1090    if (TYPE_NFIELDS (type) == 0)
1091      return;
1092 @@ -1465,15 +1465,14 @@ rust_compute_range (struct type *type, struct value *range,
1093    i = 0;
1094    if (strcmp (TYPE_FIELD_NAME (type, 0), "start") == 0)
1095      {
1096 -      *kind = HIGH_BOUND_DEFAULT;
1097 +      *kind = SUBARRAY_LOW_BOUND;
1098        *low = value_as_long (value_field (range, 0));
1099        ++i;
1100      }
1101    if (TYPE_NFIELDS (type) > i
1102        && strcmp (TYPE_FIELD_NAME (type, i), "end") == 0)
1103      {
1104 -      *kind = (*kind == BOTH_BOUND_DEFAULT
1105 -              ? LOW_BOUND_DEFAULT : NONE_BOUND_DEFAULT);
1106 +      *kind = (range_type) (*kind | SUBARRAY_HIGH_BOUND);
1107        *high = value_as_long (value_field (range, i));
1108      }
1109  }
1110 @@ -1488,7 +1487,7 @@ rust_subscript (struct expression *exp, int *pos, enum noside noside,
1111    struct type *rhstype;
1112    LONGEST low, high_bound;
1113    /* Initialized to appease the compiler.  */
1114 -  enum range_type kind = BOTH_BOUND_DEFAULT;
1115 +  enum range_type kind = SUBARRAY_NONE_BOUND;
1116    LONGEST high = 0;
1117    int want_slice = 0;
1118  
1119 @@ -1586,7 +1585,7 @@ rust_subscript (struct expression *exp, int *pos, enum noside noside,
1120         error (_("Cannot subscript non-array type"));
1121  
1122        if (want_slice
1123 -         && (kind == BOTH_BOUND_DEFAULT || kind == LOW_BOUND_DEFAULT))
1124 +         && ((kind & SUBARRAY_LOW_BOUND) != SUBARRAY_LOW_BOUND))
1125         low = low_bound;
1126        if (low < 0)
1127         error (_("Index less than zero"));
1128 @@ -1604,7 +1603,7 @@ rust_subscript (struct expression *exp, int *pos, enum noside noside,
1129           CORE_ADDR addr;
1130           struct value *addrval, *tem;
1131  
1132 -         if (kind == BOTH_BOUND_DEFAULT || kind == HIGH_BOUND_DEFAULT)
1133 +         if ((kind & SUBARRAY_HIGH_BOUND) != SUBARRAY_HIGH_BOUND)
1134             high = high_bound;
1135           if (high < 0)
1136             error (_("High index less than zero"));
1137 diff --git a/gdb/testsuite/gdb.fortran/static-arrays.exp b/gdb/testsuite/gdb.fortran/static-arrays.exp
1138 new file mode 100644
1139 index 0000000000..cc9ecc04ab
1140 --- /dev/null
1141 +++ b/gdb/testsuite/gdb.fortran/static-arrays.exp
1142 @@ -0,0 +1,421 @@
1143 +# Copyright 2015 Free Software Foundation, Inc.
1144 +#
1145 +# Contributed by Intel Corp. <christoph.t.weinmann@intel.com>
1146 +#
1147 +# This program is free software; you can redistribute it and/or modify
1148 +# it under the terms of the GNU General Public License as published by
1149 +# the Free Software Foundation; either version 3 of the License, or
1150 +# (at your option) any later version.
1151 +#
1152 +# This program is distributed in the hope that it will be useful,
1153 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1154 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1155 +# GNU General Public License for more details.
1156 +#
1157 +# You should have received a copy of the GNU General Public License
1158 +# along with this program.  If not, see <http://www.gnu.org/licenses/>.
1159 +
1160 +standard_testfile static-arrays.f90
1161 +
1162 +if { [prepare_for_testing $testfile.exp $testfile $srcfile {debug f90}] } {
1163 +    return -1
1164 +}
1165 +
1166 +if ![runto MAIN__] then {
1167 +    perror "couldn't run to breakpoint MAIN__"
1168 +    continue
1169 +}
1170 +
1171 +gdb_breakpoint [gdb_get_line_number "BP1"]
1172 +gdb_continue_to_breakpoint "BP1" ".*BP1.*"
1173 +
1174 +# Tests subarrays of one dimensional arrays with subrange variations
1175 +gdb_test "print ar1" "\\$\[0-9\]+ = \\(1, 2, 3, 4, 5, 6, 7, 8, 9\\)" \
1176 +               "print ar1."
1177 +gdb_test "print ar1\(4:7\)" "\\$\[0-9\]+ = \\(4, 5, 6, 7\\)" \
1178 +               "print ar1\(4:7\)"
1179 +gdb_test "print ar1\(8:\)" "\\$\[0-9\]+ = \\(8, 9\\).*" \
1180 +               "print ar1\(8:\)"
1181 +gdb_test "print ar1\(:3\)" "\\$\[0-9\]+ = \\(1, 2, 3\\).*" \
1182 +               "print ar1\(:3\)"
1183 +gdb_test "print ar1\(:\)" "\\$\[0-9\]+ = \\(1, 2, 3, 4, 5, 6, 7, 8, 9\\)" \
1184 +               "print ar1\(:\)"
1185 +
1186 +# Check assignment
1187 +gdb_test_no_output "set \$my_ary = ar1\(3:8\)"
1188 +gdb_test "print \$my_ary" \
1189 +               "\\$\[0-9\]+ = \\(3, 4, 5, 6, 7, 8\\)" \
1190 +               "Assignment of subarray to variable"
1191 +gdb_test_no_output "set ar1\(5\) = 42"
1192 +               gdb_test "print ar1\(3:8\)" \
1193 +               "\\$\[0-9\]+ = \\(3, 4, 42, 6, 7, 8\\)" \
1194 +               "print ar1\(3:8\) after assignment"
1195 +gdb_test "print \$my_ary" \
1196 +               "\\$\[0-9\]+ = \\(3, 4, 5, 6, 7, 8\\)" \
1197 +               "Assignment of subarray to variable after original array changed"
1198 +
1199 +# Test for subarrays of one dimensional arrays with literals
1200 +               gdb_test "print ar1\(3\)" "\\$\[0-9\]+ = 3" \
1201 +               "print ar1\(3\)"
1202 +
1203 +# Tests for subranges of 2 dimensional arrays with subrange variations
1204 +gdb_test "print ar2\(2:3, 3:4\)" \
1205 +               "\\$\[0-9\]+ = \\(\\( 23, 33\\) \\( 24, 34\\) \\)" \
1206 +               "print ar2\(2:3, 3:4\)."
1207 +gdb_test "print ar2\(8:9,8:\)" \
1208 +               "\\$\[0-9\]+ = \\(\\( 88, 98\\) \\( 89, 99\\) \\)" \
1209 +               "print ar2\(8:9,8:\)"
1210 +gdb_test "print ar2\(8:9,:2\)" \
1211 +               "\\$\[0-9\]+ = \\(\\( 81, 91\\) \\( 82, 92\\) \\)" \
1212 +               "print ar2\(8:9,:2\)"
1213 +
1214 +gdb_test "print ar2\(8:,8:9\)" \
1215 +               "\\$\[0-9\]+ = \\(\\( 88, 98\\) \\( 89, 99\\) \\)" \
1216 +               "print ar2\(8:,8:9\)"
1217 +gdb_test "print ar2\(8:,8:\)" \
1218 +               "\\$\[0-9\]+ = \\(\\( 88, 98\\) \\( 89, 99\\) \\)" \
1219 +               "print ar2\(8:,8:\)"
1220 +gdb_test "print ar2\(8:,:2\)" \
1221 +               "\\$\[0-9\]+ = \\(\\( 81, 91\\) \\( 82, 92\\) \\)" \
1222 +               "print ar2\(8:,:2\)"
1223 +
1224 +gdb_test "print ar2\(:2,2:3\)" \
1225 +               "\\$\[0-9\]+ = \\(\\( 12, 22\\) \\( 13, 23\\) \\)" \
1226 +               "print ar2\(:2,2:3\)"
1227 +gdb_test "print ar2\(:2,8:\)" \
1228 +               "\\$\[0-9\]+ = \\(\\( 18, 28\\) \\( 19, 29\\) \\)" \
1229 +               "print ar2\(:2,8:\)"
1230 +gdb_test "print ar2\(:2,:2\)" \
1231 +               "\\$\[0-9\]+ = \\(\\( 11, 21\\) \\( 12, 22\\) \\)" \
1232 +               "print ar2\(:2,:2\)"
1233 +
1234 +# Test subranges of 2 dimensional arrays with literals and subrange variations
1235 +gdb_test "print ar2\(7, 3:6\)" \
1236 +               "\\$\[0-9\]+ = \\(73, 74, 75, 76\\)" \
1237 +               "print ar2\(7, 3:6\)"
1238 +gdb_test "print ar2\(7,8:\)" \
1239 +               "\\$\[0-9\]+ = \\(78, 79\\)" \
1240 +               "print ar2\(7,8:\)"
1241 +gdb_test "print ar2\(7,:2\)" \
1242 +               "\\$\[0-9\]+ = \\(71, 72\\)" \
1243 +               "print ar2\(7,:2\)"
1244 +
1245 +gdb_test "print ar2\(7:8,4\)" \
1246 +               "\\$\[0-9\]+ = \\(74, 84\\)" \
1247 +               "print ar2(7:8,4\)"
1248 +gdb_test "print ar2\(8:,4\)" \
1249 +               "\\$\[0-9\]+ = \\(84, 94\\)" \
1250 +               "print ar2\(8:,4\)"
1251 +gdb_test "print ar2\(:2,4\)" \
1252 +               "\\$\[0-9\]+ = \\(14, 24\\)" \
1253 +               "print ar2\(:2,4\)"
1254 +gdb_test "print ar2\(3,4\)" \
1255 +               "\\$\[0-9\]+ = 34" \
1256 +               "print ar2\(3,4\)"
1257 +
1258 +# Test subarrays of 3 dimensional arrays with literals and subrange variations
1259 +gdb_test "print ar3\(2:4,3:4,7:8\)" \
1260 +               "\\$\[0-9\]+ = \\(\\( \\( 237, 337, 437\\) \\( 247, 347, 447\\)\
1261 +                \\) \\( \\( 238, 338, 438\\) \\( 248, 348, 448\\) \\) \\)" \
1262 +               "print ar3\(2:4,3:4,7:8\)"
1263 +gdb_test "print ar3\(2:3,4:5,8:\)" \
1264 +               "\\$\[0-9\]+ = \\(\\( \\( 248, 348\\) \\( 258, 358\\) \\) \\(\
1265 +                \\( 249, 349\\) \\( 259, 359\\) \\) \\)" \
1266 +               "print ar3\(2:3,4:5,8:\)"
1267 +gdb_test "print ar3\(2:3,4:5,:2\)" \
1268 +               "\\$\[0-9\]+ = \\(\\( \\( 241, 341\\) \\( 251, 351\\) \\) \\(\
1269 +                \\( 242, 342\\) \\( 252, 352\\) \\) \\)" \
1270 +               "print ar3\(2:3,4:5,:2\)"
1271 +
1272 +gdb_test "print ar3\(2:3,8:,7:8\)" \
1273 +               "\\$\[0-9\]+ = \\(\\( \\( 287, 387\\) \\( 297, 397\\) \\) \\(\
1274 +                \\( 288, 388\\) \\( 298, 398\\) \\) \\)" \
1275 +               "print ar3\(2:3,8:,7:8\)"
1276 +gdb_test "print ar3\(2:3,8:,8:\)" \
1277 +               "\\$\[0-9\]+ = \\(\\( \\( 288, 388\\) \\( 298, 398\\) \\) \\(\
1278 +                \\( 289, 389\\) \\( 299, 399\\) \\) \\)" \
1279 +               "print ar3\(2:3,8:,8:\)"
1280 +gdb_test "print ar3\(2:3,8:,:2\)" \
1281 +               "\\$\[0-9\]+ = \\(\\( \\( 281, 381\\) \\( 291, 391\\) \\) \\(\
1282 +                \\( 282, 382\\) \\( 292, 392\\) \\) \\)" \
1283 +               "print ar3\(2:3,8:,:2\)"
1284 +
1285 +gdb_test "print ar3\(2:3,:2,7:8\)" \
1286 +               "\\$\[0-9\]+ = \\(\\( \\( 217, 317\\) \\( 227, 327\\) \\) \\(\
1287 +                \\( 218, 318\\) \\( 228, 328\\) \\) \\)" \
1288 +               "print ar3\(2:3,:2,7:8\)"
1289 +gdb_test "print ar3\(2:3,:2,8:\)" \
1290 +               "\\$\[0-9\]+ = \\(\\( \\( 218, 318\\) \\( 228, 328\\) \\) \\(\
1291 +                \\( 219, 319\\) \\( 229, 329\\) \\) \\)" \
1292 +               "print ar3\(2:3,:2,8:\)"
1293 +gdb_test "print ar3\(2:3,:2,:2\)" \
1294 +               "\\$\[0-9\]+ = \\(\\( \\( 211, 311\\) \\( 221, 321\\) \\) \\(\
1295 +                \\( 212, 312\\) \\( 222, 322\\) \\) \\)" \
1296 +               "print ar3\(2:3,:2,:2\)"
1297 +
1298 +gdb_test "print ar3\(8:,3:4,7:8\)" \
1299 +               "\\$\[0-9\]+ = \\(\\( \\( 837, 937\\) \\( 847, 947\\) \\) \\(\
1300 +                \\( 838, 938\\) \\( 848, 948\\) \\) \\)" \
1301 +               "print ar3\(8:,3:4,7:8\)"
1302 +gdb_test "print ar3\(8:,4:5,8:\)" \
1303 +               "\\$\[0-9\]+ = \\(\\( \\( 848, 948\\) \\( 858, 958\\) \\) \\(\
1304 +                \\( 849, 949\\) \\( 859, 959\\) \\) \\)" \
1305 +               "print ar3\(8:,4:5,8:\)"
1306 +gdb_test "print ar3\(8:,4:5,:2\)" \
1307 +               "\\$\[0-9\]+ = \\(\\( \\( 841, 941\\) \\( 851, 951\\) \\) \\(\
1308 +                \\( 842, 942\\) \\( 852, 952\\) \\) \\)" \
1309 +               "print ar3\(8:,4:5,:2\)"
1310 +
1311 +gdb_test "print ar3\(8:,8:,7:8\)" \
1312 +               "\\$\[0-9\]+ = \\(\\( \\( 887, 987\\) \\( 897, 997\\) \\) \\(\
1313 +                \\( 888, 988\\) \\( 898, 998\\) \\) \\)" \
1314 +               "print ar3\(8:,8:,7:8\)"
1315 +gdb_test "print ar3\(8:,8:,8:\)" \
1316 +               "\\$\[0-9\]+ = \\(\\( \\( 888, 988\\) \\( 898, 998\\) \\) \\(\
1317 +                \\( 889, 989\\) \\( 899, 999\\) \\) \\)" \
1318 +               "print ar3\(8:,8:,8:\)"
1319 +gdb_test "print ar3\(8:,8:,:2\)" \
1320 +               "\\$\[0-9\]+ = \\(\\( \\( 881, 981\\) \\( 891, 991\\) \\) \\(\
1321 +                \\( 882, 982\\) \\( 892, 992\\) \\) \\)" \
1322 +               "print ar3\(8:,8:,:2\)"
1323 +
1324 +gdb_test "print ar3\(8:,:2,7:8\)" \
1325 +               "\\$\[0-9\]+ = \\(\\( \\( 817, 917\\) \\( 827, 927\\) \\) \\(\
1326 +                \\( 818, 918\\) \\( 828, 928\\) \\) \\)" \
1327 +               "print ar3\(8:,:2,7:8\)"
1328 +gdb_test "print ar3\(8:,:2,8:\)" \
1329 +               "\\$\[0-9\]+ = \\(\\( \\( 818, 918\\) \\( 828, 928\\) \\) \\(\
1330 +                \\( 819, 919\\) \\( 829, 929\\) \\) \\)" \
1331 +               "print ar3\(8:,:2,8:\)"
1332 +gdb_test "print ar3\(8:,:2,:2\)" \
1333 +               "\\$\[0-9\]+ = \\(\\( \\( 811, 911\\) \\( 821, 921\\) \\) \\(\
1334 +                \\( 812, 912\\) \\( 822, 922\\) \\) \\)" \
1335 +               "print ar3\(8:,:2,:2\)"
1336 +
1337 +
1338 +gdb_test "print ar3\(:2,3:4,7:8\)" \
1339 +               "\\$\[0-9\]+ = \\(\\( \\( 137, 237\\) \\( 147, 247\\) \\) \\(\
1340 +                \\( 138, 238\\) \\( 148, 248\\) \\) \\)" \
1341 +               "print ar3 \(:2,3:4,7:8\)."
1342 +gdb_test "print ar3\(:2,3:4,8:\)" \
1343 +               "\\$\[0-9\]+ = \\(\\( \\( 138, 238\\) \\( 148, 248\\) \\) \\(\
1344 +                \\( 139, 239\\) \\( 149, 249\\) \\) \\)" \
1345 +               "print ar3\(:2,3:4,8:\)"
1346 +gdb_test "print ar3\(:2,3:4,:2\)" \
1347 +               "\\$\[0-9\]+ = \\(\\( \\( 131, 231\\) \\( 141, 241\\) \\) \\(\
1348 +                \\( 132, 232\\) \\( 142, 242\\) \\) \\)" \
1349 +               "print ar3\(:2,3:4,:2\)"
1350 +
1351 +gdb_test "print ar3\(:2,8:,7:8\)" "\\$\[0-9\]+ = \\(\\( \\( 187, 287\\) \\(\
1352 +                197, 297\\) \\) \\( \\( 188, 288\\) \\( 198, 298\\) \\) \\)" \
1353 +               "print ar3\(:2,8:,7:8\)"
1354 +gdb_test "print ar3\(:2,8:,8:\)" "\\$\[0-9\]+ = \\(\\( \\( 188, 288\\) \\( 198,\
1355 +                298\\) \\) \\( \\( 189, 289\\) \\( 199, 299\\) \\) \\)" \
1356 +               "print ar3\(:2,8:,8:\)"
1357 +gdb_test "print ar3\(:2,8:,:2\)" "\\$\[0-9\]+ = \\(\\( \\( 181, 281\\) \\( 191,\
1358 +                291\\) \\) \\( \\( 182, 282\\) \\( 192, 292\\) \\) \\)" \
1359 +               "print ar3\(:2,8:,:2\)"
1360 +
1361 +gdb_test "print ar3\(:2,:2,7:8\)" \
1362 +               "\\$\[0-9\]+ = \\(\\( \\( 117, 217\\) \\( 127, 227\\) \\) \\(\
1363 +                \\( 118, 218\\) \\( 128, 228\\) \\) \\)" \
1364 +               "print ar3\(:2,:2,7:8\)"
1365 +gdb_test "print ar3\(:2,:2,8:\)" \
1366 +               "\\$\[0-9\]+ = \\(\\( \\( 118, 218\\) \\( 128, 228\\) \\) \\(\
1367 +                \\( 119, 219\\) \\( 129, 229\\) \\) \\)" \
1368 +               "print ar3\(:2,:2,8:\)"
1369 +gdb_test "print ar3\(:2,:2,:2\)" \
1370 +               "\\$\[0-9\]+ = \\(\\( \\( 111, 211\\) \\( 121, 221\\) \\) \\(\
1371 +                \\( 112, 212\\) \\( 122, 222\\) \\) \\)" \
1372 +               "print ar3\(:2,:2,:2\)"
1373 +
1374 +#Tests for subarrays of 3 dimensional arrays with literals and subranges
1375 +gdb_test "print ar3\(3,3:4,7:8\)" \
1376 +               "\\$\[0-9\]+ = \\(\\( 337, 347\\) \\( 338, 348\\) \\)" \
1377 +               "print ar3\(3,3:4,7:8\)"
1378 +gdb_test "print ar3\(3,4:5,8:\)" \
1379 +               "\\$\[0-9\]+ = \\(\\( 348, 358\\) \\( 349, 359\\) \\)" \
1380 +               "print ar3\(3,4:5,8:\)"
1381 +gdb_test "print ar3\(3,4:5,:2\)" \
1382 +               "\\$\[0-9\]+ = \\(\\( 341, 351\\) \\( 342, 352\\) \\)" \
1383 +               "print ar3\(3,4:5,:2\)"
1384 +gdb_test "print ar3\(3,4:5,3\)" \
1385 +               "\\$\[0-9\]+ = \\(343, 353\\)" \
1386 +               "print ar3\(3,4:5,3\)"
1387 +
1388 +gdb_test "print ar3\(2,8:,7:8\)" \
1389 +               "\\$\[0-9\]+ = \\(\\( 287, 297\\) \\( 288, 298\\) \\)" \
1390 +               "print ar3\(2,8:,7:8\)"
1391 +gdb_test "print ar3\(2,8:,8:\)" \
1392 +               "\\$\[0-9\]+ = \\(\\( 288, 298\\) \\( 289, 299\\) \\)" \
1393 +               "print ar3\(2,8:,8:\)"
1394 +gdb_test "print ar3\(2,8:,:2\)"\
1395 +               "\\$\[0-9\]+ = \\(\\( 281, 291\\) \\( 282, 292\\) \\)" \
1396 +               "print ar3\(2,8:,:2\)"
1397 +gdb_test "print ar3\(2,8:,3\)" \
1398 +               "\\$\[0-9\]+ = \\(283, 293\\)" \
1399 +               "print ar3\(2,8:,3\)"
1400 +
1401 +gdb_test "print ar3\(2,:2,7:8\)" \
1402 +               "\\$\[0-9\]+ = \\(\\( 217, 227\\) \\( 218, 228\\) \\)" \
1403 +               "print ar3\(2,:2,7:8\)"
1404 +gdb_test "print ar3\(2,:2,8:\)" \
1405 +               "\\$\[0-9\]+ = \\(\\( 218, 228\\) \\( 219, 229\\) \\)" \
1406 +               "print ar3\(2,:2,8:\)"
1407 +gdb_test "print ar3\(2,:2,:2\)" \
1408 +               "\\$\[0-9\]+ = \\(\\( 211, 221\\) \\( 212, 222\\) \\)" \
1409 +               "print ar3\(2,:2,:2\)"
1410 +gdb_test "print ar3\(2,:2,3\)" \
1411 +               "\\$\[0-9\]+ = \\(213, 223\\)" \
1412 +               "print ar3\(2,:2,3\)"
1413 +
1414 +gdb_test "print ar3\(3,4,7:8\)" \
1415 +               "\\$\[0-9\]+ = \\(347, 348\\)" \
1416 +               "print ar3\(3,4,7:8\)"
1417 +gdb_test "print ar3\(3,4,8:\)" \
1418 +               "\\$\[0-9\]+ = \\(348, 349\\)" \
1419 +i              "print ar3\(3,4,8:\)"
1420 +gdb_test "print ar3\(3,4,:2\)" \
1421 +               "\\$\[0-9\]+ = \\(341, 342\\)" \
1422 +               "print ar3\(3,4,:2\)"
1423 +gdb_test "print ar3\(5,6,7\)" \
1424 +               "\\$\[0-9\]+ = 567" \
1425 +               "print ar3\(5,6,7\)"
1426 +
1427 +gdb_test "print ar3\(3:4,6,7:8\)" \
1428 +               "\\$\[0-9\]+ = \\(\\( 367, 467\\) \\( 368, 468\\) \\)" \
1429 +               "print ar3\(3:4,6,7:8\)"
1430 +gdb_test "print ar3\(3:4,6,8:\)" \
1431 +               "\\$\[0-9\]+ = \\(\\( 368, 468\\) \\( 369, 469\\) \\)" \
1432 +               "print ar3\(3:4,6,8:\)"
1433 +gdb_test "print ar3\(3:4,6,:2\)" \
1434 +               "\\$\[0-9\]+ = \\(\\( 361, 461\\) \\( 362, 462\\) \\)" \
1435 +               "print ar3\(3:4,6,:2\)"
1436 +gdb_test "print ar3\(3:4,6,5\)" \
1437 +               "\\$\[0-9\]+ = \\(365, 465\\)" \
1438 +               "print ar3\(3:4,6,5\)"
1439 +
1440 +gdb_test "print ar3\(8:,6,7:8\)" \
1441 +               "\\$\[0-9\]+ = \\(\\( 867, 967\\) \\( 868, 968\\) \\)" \
1442 +               "print ar3\(8:,6,7:8\)"
1443 +gdb_test "print ar3\(8:,6,8:\)" \
1444 +               "\\$\[0-9\]+ = \\(\\( 868, 968\\) \\( 869, 969\\) \\)" \
1445 +               "print ar3\(8:,6,8:\)"
1446 +gdb_test "print ar3\(8:,6,:2\)" \
1447 +               "\\$\[0-9\]+ = \\(\\( 861, 961\\) \\( 862, 962\\) \\)" \
1448 +               "print ar3\(8:,6,:2\)"
1449 +gdb_test "print ar3\(8:,6,5\)" \
1450 +               "\\$\[0-9\]+ = \\(865, 965\\)" \
1451 +               "print ar3\(8:,6,5\)"
1452 +
1453 +gdb_test "print ar3\(:2,6,7:8\)" \
1454 +               "\\$\[0-9\]+ = \\(\\( 167, 267\\) \\( 168, 268\\) \\)" \
1455 +               "print ar3\(:2,6,7:8\)"
1456 +gdb_test "print ar3\(:2,6,8:\)" \
1457 +               "\\$\[0-9\]+ = \\(\\( 168, 268\\) \\( 169, 269\\) \\)" \
1458 +               "print ar3\(:2,6,8:\)"
1459 +gdb_test "print ar3\(:2,6,:2\)" \
1460 +               "\\$\[0-9\]+ = \\(\\( 161, 261\\) \\( 162, 262\\) \\)" \
1461 +               "print ar3\(:2,6,:2\)"
1462 +gdb_test "print ar3\(:2,6,5\)" \
1463 +               "\\$\[0-9\]+ = \\(165, 265\\)" \
1464 +               "print ar3\(:2,6,5\)"
1465 +
1466 +gdb_test "print ar3\(3:4,5:6,4\)" \
1467 +               "\\$\[0-9\]+ = \\(\\( 354, 454\\) \\( 364, 464\\) \\)" \
1468 +               "print ar2\(3:4,5:6,4\)"
1469 +gdb_test "print ar3\(8:,5:6,4\)" \
1470 +               "\\$\[0-9\]+ = \\(\\( 854, 954\\) \\( 864, 964\\) \\)" \
1471 +               "print ar2\(8:,5:6,4\)"
1472 +gdb_test "print ar3\(:2,5:6,4\)" \
1473 +               "\\$\[0-9\]+ = \\(\\( 154, 254\\) \\( 164, 264\\) \\)" \
1474 +               "print ar2\(:2,5:6,4\)"
1475 +
1476 +# Stride > 1
1477 +gdb_test "print ar1\(2:6:2\)" \
1478 +               "\\$\[0-9\]+ = \\(2, 4, 6\\)" \
1479 +               "print ar1\(2:6:2\)"
1480 +gdb_test "print ar2\(2:6:2,3:4\)" \
1481 +               "\\$\[0-9\]+ = \\(\\( 23, 43, 63\\) \\( 24, 44, 64\\) \\)" \
1482 +               "print ar2\(2:6:2,3:4\)"
1483 +gdb_test "print ar2\(2:6:2,3\)" \
1484 +               "\\$\[0-9\]+ = \\(23, 43, 63\\)" \
1485 +               "print ar2\(2:6:2,3\)"
1486 +gdb_test "print ar3\(2:6:2,3:5:2,4:7:3\)" \
1487 +               "\\$\[0-9\]+ = \\(\\( \\( 234, 434, 634\\) \\( 254, 454, 654\\)\
1488 +                \\) \\( \\( 237, 437, 637\\) \\( 257, 457, 657\\) \\) \\)" \
1489 +               "print ar3\(2:6:2,3:5:2,4:7:3\)"
1490 +gdb_test "print ar3\(2:6:2,5,4:7:3\)" \
1491 +               "\\$\[0-9\]+ = \\(\\( 254, 454, 654\\) \\( 257, 457, 657\\)\
1492 +                \\)" \
1493 +               "print ar3\(2:6:2,5,4:7:3\)"
1494 +
1495 +# Stride < 0
1496 +gdb_test "print ar1\(8:2:-2\)" \
1497 +               "\\$\[0-9\]+ = \\(8, 6, 4, 2\\)" \
1498 +               "print ar1\(8:2:-2\)"
1499 +gdb_test "print ar2\(8:2:-2,3:4\)" \
1500 +               "\\$\[0-9\]+ = \\(\\( 83, 63, 43, 23\\) \\( 84, 64, 44, 24\\)\
1501 +                \\)" \
1502 +               "print ar2\(8:2:-2,3:4\)"
1503 +gdb_test "print ar2\(2:6:2,3\)" \
1504 +               "\\$\[0-9\]+ = \\(23, 43, 63\\)" \
1505 +               "print ar2\(2:6:2,3\)"
1506 +gdb_test "print ar3\(2:3,7:3:-4,4:7:3\)" \
1507 +               "\\$\[0-9\]+ = \\(\\( \\( 274, 374\\) \\( 234, 334\\) \\) \\(\
1508 +                \\( 277, 377\\) \\( 237, 337\\) \\) \\)" \
1509 +               "print ar3\(2:3,7:3:-4,4:7:3\)"
1510 +gdb_test "print ar3\(2:6:2,5,7:4:-3\)" \
1511 +               "\\$\[0-9\]+ = \\(\\( 257, 457, 657\\) \\( 254, 454, 654\\)\
1512 +                \\)" \
1513 +               "print ar3\(2:6:2,5,7:4:-3\)"
1514 +
1515 +# Tests with negative and mixed indices
1516 +gdb_test "p ar4\(2:4, -2:1, -15:-14\)" \
1517 +               "\\$\[0-9\]+ = \\(\\( \\( 261, 361, 461\\) \\( 271, 371, 471\\)\
1518 +                \\( 281, 381, 481\\) \\( 291, 391, 491\\) \\) \\( \\( 262,\
1519 +                362, 462\\) \\( 272, 372, 472\\) \\( 282, 382, 482\\) \\( 292,\
1520 +                392, 492\\) \\) \\)" \
1521 +               "print ar4(2:4, -2:1, -15:-14)"
1522 +
1523 +gdb_test "p ar4\(7,-6:2:3,-7\)" \
1524 +                "\\$\[0-9\]+ = \\(729, 759, 789\\)" \
1525 +                "print ar4(7,-6:2:3,-7)"
1526 +
1527 +gdb_test "p ar4\(9:2:-2, -6:2:3, -6:-15:-3\)" \
1528 +                "\\$\[0-9\]+ = \\(\\( \\( 930, 730, 530, 330\\) \\( 960, 760,\
1529 +                560, 360\\) \\( 990, 790, 590, 390\\) \\) \\( \\( 927, 727,\
1530 +                527, 327\\) \\( 957, 757, 557, 357\\) \\( 987, 787, 587,\
1531 +                387\\) \\) \\( \\( 924, 724, 524, 324\\) \\( 954, 754, 554,\
1532 +                354\\) \\( 984, 784, 584, 384\\) \\) \\( \\( 921, 721, 521,\
1533 +                321\\) \\( 951, 751, 551, 351\\) \\( 981, 781, 581, 381\\) \\)\
1534 +                \\)" \
1535 +                "print ar4(9:2:-2, -6:2:3, -6:-15:-3)"
1536 +
1537 +gdb_test "p ar4\(:,:,:\)" \
1538 +                "\\$\[0-9\]+ = \\(\\( \\( 111, 211, 311, 411, 511, 611, 711,\
1539 +                811, .*" \
1540 +                "print ar4(:,:,:)"
1541 +
1542 +# Provoke error messages for bad user input
1543 +gdb_test "print ar1\(0:4\)" \
1544 +               "provided bound\\(s\\) outside array bound\\(s\\)" \
1545 +               "print ar1\(0:4\)"
1546 +gdb_test "print ar1\(8:12\)" \
1547 +               "provided bound\\(s\\) outside array bound\\(s\\)" \
1548 +               "print ar1\(8:12\)"
1549 +gdb_test "print ar1\(8:2:\)" \
1550 +               "A syntax error in expression, near `\\)'." \
1551 +               "print ar1\(8:2:\)"
1552 +gdb_test "print ar1\(8:2:2\)" \
1553 +               "Wrong value provided for stride and boundaries" \
1554 +               "print ar1\(8:2:2\)"
1555 +gdb_test "print ar1\(2:8:-2\)" \
1556 +               "Wrong value provided for stride and boundaries" \
1557 +               "print ar1\(2:8:-2\)"
1558 +gdb_test "print ar1\(2:7:0\)" \
1559 +               "Stride must not be 0" \
1560 +               "print ar1\(2:7:0\)"
1561 +gdb_test "print ar1\(3:7\) = 42" \
1562 +               "Invalid cast." \
1563 +               "Assignment of value to subarray"
1564 diff --git a/gdb/testsuite/gdb.fortran/static-arrays.f90 b/gdb/testsuite/gdb.fortran/static-arrays.f90
1565 new file mode 100644
1566 index 0000000000..f22fcbe124
1567 --- /dev/null
1568 +++ b/gdb/testsuite/gdb.fortran/static-arrays.f90
1569 @@ -0,0 +1,55 @@
1570 +! Copyright 2015 Free Software Foundation, Inc.
1571 +!
1572 +! Contributed by Intel Corp. <christoph.t.weinmann@intel.com>
1573 +!
1574 +! This program is free software; you can redistribute it and/or modify
1575 +! it under the terms of the GNU General Public License as published by
1576 +! the Free Software Foundation; either version 3 of the License, or
1577 +! (at your option) any later version.
1578 +!
1579 +! This program is distributed in the hope that it will be useful,
1580 +! but WITHOUT ANY WARRANTY; without even the implied warranty of
1581 +! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1582 +! GNU General Public License for more details.
1583 +!
1584 +! You should have received a copy of the GNU General Public License
1585 +! along with this program.  If not, see <http://www.gnu.org/licenses/>.
1586 +
1587 +subroutine sub
1588 +  integer, dimension(9) :: ar1
1589 +  integer, dimension(9,9) :: ar2
1590 +  integer, dimension(9,9,9) :: ar3
1591 +  integer, dimension(10,-7:3, -15:-5) :: ar4
1592 +  integer :: i,j,k
1593 +
1594 +  ar1 = 1
1595 +  ar2 = 1
1596 +  ar3 = 1
1597 +  ar4 = 4
1598 +
1599 +  ! Resulting array ar3 looks like ((( 111, 112, 113, 114,...)))
1600 +  do i = 1, 9, 1
1601 +    ar1(i) = i
1602 +    do j = 1, 9, 1
1603 +      ar2(i,j) = i*10 + j
1604 +      do k = 1, 9, 1
1605 +        ar3(i,j,k) = i*100 + j*10 + k
1606 +      end do
1607 +    end do
1608 +  end do
1609 +
1610 +  do i = 1, 10, 1
1611 +    do j = -7, 3, 1
1612 +      do k = -15, -5, 1
1613 +        ar4(i,j,k) = i*100 + (j+8)*10 + (k+16)
1614 +      end do
1615 +    end do
1616 +  end do
1617 +
1618 +  ar1(1) = 11  !BP1
1619 +  return
1620 +end
1621 +
1622 +program testprog
1623 +  call sub
1624 +end
1625 diff --git a/gdb/testsuite/gdb.fortran/vla-ptype.exp b/gdb/testsuite/gdb.fortran/vla-ptype.exp
1626 index 5f367348b0..5351a0aa2e 100644
1627 --- a/gdb/testsuite/gdb.fortran/vla-ptype.exp
1628 +++ b/gdb/testsuite/gdb.fortran/vla-ptype.exp
1629 @@ -98,3 +98,7 @@ gdb_test "ptype vla2" "type = <not allocated>" "ptype vla2 not allocated"
1630  gdb_test "ptype vla2(5, 45, 20)" \
1631    "no such vector element \\\(vector not allocated\\\)" \
1632    "ptype vla2(5, 45, 20) not allocated"
1633 +
1634 +gdb_breakpoint [gdb_get_line_number "vla1-neg-bounds"]
1635 +gdb_continue_to_breakpoint "vla1-neg-bounds"
1636 +gdb_test "ptype vla1" "type = $real \\(-2:1,-5:4,-3:-1\\)" "ptype vla1 negative bounds"
1637 diff --git a/gdb/testsuite/gdb.fortran/vla-sizeof.exp b/gdb/testsuite/gdb.fortran/vla-sizeof.exp
1638 index 3113983ba4..83bc849619 100644
1639 --- a/gdb/testsuite/gdb.fortran/vla-sizeof.exp
1640 +++ b/gdb/testsuite/gdb.fortran/vla-sizeof.exp
1641 @@ -44,3 +44,7 @@ gdb_test "print sizeof(pvla)" " = 0" "print sizeof non-associated pvla"
1642  gdb_breakpoint [gdb_get_line_number "pvla-associated"]
1643  gdb_continue_to_breakpoint "pvla-associated"
1644  gdb_test "print sizeof(pvla)" " = 4000" "print sizeof associated pvla"
1645 +
1646 +gdb_breakpoint [gdb_get_line_number "vla1-neg-bounds"]
1647 +gdb_continue_to_breakpoint "vla1-neg-bounds"
1648 +gdb_test "print sizeof(vla1)" " = 480" "print sizeof vla1 negative bounds"
1649 diff --git a/gdb/testsuite/gdb.fortran/vla-stride.exp b/gdb/testsuite/gdb.fortran/vla-stride.exp
1650 new file mode 100644
1651 index 0000000000..dcf15e5daf
1652 --- /dev/null
1653 +++ b/gdb/testsuite/gdb.fortran/vla-stride.exp
1654 @@ -0,0 +1,44 @@
1655 +# Copyright 2016 Free Software Foundation, Inc.
1656 +
1657 +# This program is free software; you can redistribute it and/or modify
1658 +# it under the terms of the GNU General Public License as published by
1659 +# the Free Software Foundation; either version 3 of the License, or
1660 +# (at your option) any later version.
1661 +#
1662 +# This program is distributed in the hope that it will be useful,
1663 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1664 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1665 +# GNU General Public License for more details.
1666 +#
1667 +# You should have received a copy of the GNU General Public License
1668 +# along with this program.  If not, see <http://www.gnu.org/licenses/>.
1669 +
1670 +standard_testfile ".f90"
1671 +
1672 +if { [prepare_for_testing ${testfile}.exp ${testfile} ${srcfile} \
1673 +    {debug f90 quiet}] } {
1674 +    return -1
1675 +}
1676 +
1677 +if ![runto MAIN__] then {
1678 +    perror "couldn't run to breakpoint MAIN__"
1679 +    continue
1680 +}
1681 +
1682 +gdb_breakpoint [gdb_get_line_number "re-reverse-elements"]
1683 +gdb_continue_to_breakpoint "re-reverse-elements"
1684 +gdb_test "print pvla" " = \\\(1, 2, 3, 4, 5, 6, 7, 8, 9, 10\\\)" \
1685 +  "print re-reverse-elements"
1686 +gdb_test "print pvla(1)" " = 1" "print first re-reverse-element"
1687 +gdb_test "print pvla(10)" " = 10" "print last re-reverse-element"
1688 +
1689 +gdb_breakpoint [gdb_get_line_number "odd-elements"]
1690 +gdb_continue_to_breakpoint "odd-elements"
1691 +gdb_test "print pvla" " = \\\(1, 3, 5, 7, 9\\\)" "print odd-elements"
1692 +gdb_test "print pvla(1)" " = 1" "print first odd-element"
1693 +gdb_test "print pvla(5)" " = 9" "print last odd-element"
1694 +
1695 +gdb_breakpoint [gdb_get_line_number "single-element"]
1696 +gdb_continue_to_breakpoint "single-element"
1697 +gdb_test "print pvla" " = \\\(5\\\)" "print single-element"
1698 +gdb_test "print pvla(1)" " = 5" "print one single-element"
1699 diff --git a/gdb/testsuite/gdb.fortran/vla-stride.f90 b/gdb/testsuite/gdb.fortran/vla-stride.f90
1700 new file mode 100644
1701 index 0000000000..8d2425222e
1702 --- /dev/null
1703 +++ b/gdb/testsuite/gdb.fortran/vla-stride.f90
1704 @@ -0,0 +1,29 @@
1705 +! Copyright 2016 Free Software Foundation, Inc.
1706 +!
1707 +! This program is free software; you can redistribute it and/or modify
1708 +! it under the terms of the GNU General Public License as published by
1709 +! the Free Software Foundation; either version 3 of the License, or
1710 +! (at your option) any later version.
1711 +!
1712 +! This program is distributed in the hope that it will be useful,
1713 +! but WITHOUT ANY WARRANTY; without even the implied warranty of
1714 +! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1715 +! GNU General Public License for more details.
1716 +!
1717 +! You should have received a copy of the GNU General Public License
1718 +! along with this program.  If not, see <http://www.gnu.org/licenses/>.
1719 +
1720 +program vla_stride
1721 +  integer, target, allocatable :: vla (:)
1722 +  integer, pointer :: pvla (:)
1723 +
1724 +  allocate(vla(10))
1725 +  vla = (/ (I, I = 1,10) /)
1726 +
1727 +  pvla => vla(10:1:-1)
1728 +  pvla => pvla(10:1:-1)
1729 +  pvla => vla(1:10:2)   ! re-reverse-elements
1730 +  pvla => vla(5:4:-2)   ! odd-elements
1731 +
1732 +  pvla => null()        ! single-element
1733 +end program vla_stride
1734 diff --git a/gdb/testsuite/gdb.fortran/vla.f90 b/gdb/testsuite/gdb.fortran/vla.f90
1735 index 508290a36e..d87f59b92b 100644
1736 --- a/gdb/testsuite/gdb.fortran/vla.f90
1737 +++ b/gdb/testsuite/gdb.fortran/vla.f90
1738 @@ -54,4 +54,14 @@ program vla
1739  
1740    allocate (vla3 (2,2))               ! vla2-deallocated
1741    vla3(:,:) = 13
1742 +
1743 +  allocate (vla1 (-2:1, -5:4, -3:-1))
1744 +  l = allocated(vla1)
1745 +
1746 +  vla1(:, :, :) = 1
1747 +  vla1(-2, -3, -1) = -231
1748 +
1749 +  deallocate (vla1)                   ! vla1-neg-bounds
1750 +  l = allocated(vla1)
1751 +
1752  end program vla
1753 diff --git a/gdb/valarith.c b/gdb/valarith.c
1754 index 58e3a09c37..035def5466 100644
1755 --- a/gdb/valarith.c
1756 +++ b/gdb/valarith.c
1757 @@ -189,10 +189,16 @@ value_subscripted_rvalue (struct value *array, LONGEST index, int lowerbound)
1758    struct type *array_type = check_typedef (value_type (array));
1759    struct type *elt_type = check_typedef (TYPE_TARGET_TYPE (array_type));
1760    ULONGEST elt_size = type_length_units (elt_type);
1761 -  ULONGEST elt_offs = elt_size * (index - lowerbound);
1762 +  LONGEST elt_offs = index - lowerbound;
1763 +  LONGEST elt_stride = TYPE_BYTE_STRIDE (TYPE_INDEX_TYPE (array_type));
1764 +
1765 +  if (elt_stride != 0)
1766 +    elt_offs *= elt_stride;
1767 +  else
1768 +    elt_offs *= elt_size;
1769  
1770    if (index < lowerbound || (!TYPE_ARRAY_UPPER_BOUND_IS_UNDEFINED (array_type)
1771 -                            && elt_offs >= type_length_units (array_type)))
1772 +                            && abs (elt_offs) >= type_length_units (array_type)))
1773      {
1774        if (type_not_associated (array_type))
1775          error (_("no such vector element (vector not associated)"));
1776 diff --git a/gdb/valops.c b/gdb/valops.c
1777 index 9525dc8499..4cd4fd96ae 100644
1778 --- a/gdb/valops.c
1779 +++ b/gdb/valops.c
1780 @@ -3776,56 +3776,195 @@ value_of_this_silent (const struct language_defn *lang)
1781  
1782  struct value *
1783  value_slice (struct value *array, int lowbound, int length)
1784 +{
1785 +  /* Pass unaltered arguments to VALUE_SLICE_1, plus a default stride
1786 +     value of '1', which returns every element between LOWBOUND and
1787 +     (LOWBOUND + LENGTH).  We also provide a default CALL_COUNT of '1'
1788 +     as we are only considering the highest dimension, or we are
1789 +     working on a one dimensional array.  So we call VALUE_SLICE_1
1790 +     exactly once.  */
1791 +  return value_slice_1 (array, lowbound, length, 1, 1);
1792 +}
1793 +
1794 +/* VALUE_SLICE_1 is called for each array dimension to calculate the number
1795 +   of elements as defined by the subscript expression.
1796 +   CALL_COUNT is used to determine if we are calling the function once, e.g.
1797 +   we are working on the current dimension of ARRAY, or if we are calling
1798 +   the function repeatedly.  In the later case we need to take elements
1799 +   from the TARGET_TYPE of ARRAY.
1800 +   With a CALL_COUNT greater than 1 we calculate the offsets for every element
1801 +   that should be in the result array.  Then we fetch the contents and then
1802 +   copy them into the result array.  The result array will have one dimension
1803 +   less than the input array, so later on we need to recreate the indices and
1804 +   ranges in the calling function.  */
1805 +
1806 +struct value *
1807 +value_slice_1 (struct value *array, int lowbound, int length,
1808 +              int stride_length, int call_count)
1809  {
1810    struct type *slice_range_type, *slice_type, *range_type;
1811 -  LONGEST lowerbound, upperbound;
1812 -  struct value *slice;
1813 -  struct type *array_type;
1814 +  struct type *array_type = check_typedef (value_type (array));
1815 +  struct type *elt_type = check_typedef (TYPE_TARGET_TYPE (array_type));
1816 +  unsigned int elt_size, elt_offs;
1817 +  LONGEST ary_high_bound, ary_low_bound;
1818 +  struct value *v;
1819 +  int slice_range_size, i = 0, row_count = 1, elem_count = 1;
1820  
1821 -  array_type = check_typedef (value_type (array));
1822 +  /* Check for legacy code if we are actually dealing with an array or
1823 +     string.  */
1824    if (TYPE_CODE (array_type) != TYPE_CODE_ARRAY
1825        && TYPE_CODE (array_type) != TYPE_CODE_STRING)
1826      error (_("cannot take slice of non-array"));
1827  
1828 -  range_type = TYPE_INDEX_TYPE (array_type);
1829 -  if (get_discrete_bounds (range_type, &lowerbound, &upperbound) < 0)
1830 -    error (_("slice from bad array or bitstring"));
1831 +  ary_low_bound = TYPE_LOW_BOUND (TYPE_INDEX_TYPE (array_type));
1832 +  ary_high_bound = TYPE_HIGH_BOUND (TYPE_INDEX_TYPE (array_type));
1833 +
1834 +  /* When we are working on a multi-dimensional array, we need to get the
1835 +     attributes of the underlying type.  */
1836 +  if (call_count > 1)
1837 +    {
1838 +      ary_low_bound = TYPE_LOW_BOUND (TYPE_INDEX_TYPE (elt_type));
1839 +      ary_high_bound = TYPE_HIGH_BOUND (TYPE_INDEX_TYPE (elt_type));
1840 +      elt_type = check_typedef (TYPE_TARGET_TYPE (elt_type));
1841 +      row_count = TYPE_LENGTH (array_type)
1842 +                   / TYPE_LENGTH (TYPE_TARGET_TYPE (array_type));
1843 +    }
1844 +
1845 +  /* With a stride of '1', the number of elements per result row is equal to
1846 +     the LENGTH of the subarray.  With non-default stride values, we skip
1847 +     elements, but have to add the start element to the total number of
1848 +     elements per row.  */
1849 +  if (stride_length == 1)
1850 +    elem_count = length;
1851 +  else
1852 +    elem_count = ((length - 1) / stride_length) + 1;
1853 +
1854 +  elt_size = TYPE_LENGTH (elt_type);
1855 +  elt_offs = lowbound - ary_low_bound;
1856  
1857 -  if (lowbound < lowerbound || length < 0
1858 -      || lowbound + length - 1 > upperbound)
1859 -    error (_("slice out of range"));
1860 +  elt_offs *= elt_size;
1861 +
1862 +  /* Check for valid user input.  In case of Fortran this was already done
1863 +     in the calling function.  */
1864 +  if (call_count == 1
1865 +       && (!TYPE_ARRAY_UPPER_BOUND_IS_UNDEFINED (array_type)
1866 +             && elt_offs >= TYPE_LENGTH (array_type)))
1867 +    error (_("no such vector element"));
1868 +
1869 +  /* CALL_COUNT is 1 when we are dealing either with the highest dimension
1870 +     of the array, or a one dimensional array.  Set RANGE_TYPE accordingly.
1871 +     In both cases we calculate how many rows/elements will be in the output
1872 +     array by setting slice_range_size.  */
1873 +  if (call_count == 1)
1874 +    {
1875 +      range_type = TYPE_INDEX_TYPE (array_type);
1876 +      slice_range_size = ary_low_bound + elem_count - 1;
1877 +
1878 +      /* Check if the array bounds are valid.  */
1879 +      if (get_discrete_bounds (range_type, &ary_low_bound, &ary_high_bound) < 0)
1880 +       error (_("slice from bad array or bitstring"));
1881 +    }
1882 +  /* When CALL_COUNT is greater than 1, we are dealing with an array of arrays.
1883 +     So we need to get the type below the current one and set the RANGE_TYPE
1884 +     accordingly.  */
1885 +  else
1886 +    {
1887 +      range_type = TYPE_INDEX_TYPE (TYPE_TARGET_TYPE (array_type));
1888 +      slice_range_size = ary_low_bound + (row_count * elem_count) - 1;
1889 +      ary_low_bound = TYPE_LOW_BOUND (range_type);
1890 +    }
1891  
1892    /* FIXME-type-allocation: need a way to free this type when we are
1893 -     done with it.  */
1894 -  slice_range_type = create_static_range_type ((struct type *) NULL,
1895 -                                              TYPE_TARGET_TYPE (range_type),
1896 -                                              lowbound,
1897 -                                              lowbound + length - 1);
1898 +      done with it.  */
1899  
1900 +  slice_range_type = create_static_range_type (NULL, TYPE_TARGET_TYPE (range_type),
1901 +                                              ary_low_bound, slice_range_size);
1902    {
1903 -    struct type *element_type = TYPE_TARGET_TYPE (array_type);
1904 -    LONGEST offset
1905 -      = (lowbound - lowerbound) * TYPE_LENGTH (check_typedef (element_type));
1906 +    struct type *element_type;
1907 +
1908 +    /* When both CALL_COUNT and STRIDE_LENGTH equal 1, we can use the legacy
1909 +       code for subarrays.  */
1910 +    if (call_count == 1 && stride_length == 1)
1911 +      {
1912 +       element_type = TYPE_TARGET_TYPE (array_type);
1913 +
1914 +       slice_type = create_array_type (NULL, element_type, slice_range_type);
1915  
1916 -    slice_type = create_array_type ((struct type *) NULL,
1917 -                                   element_type,
1918 -                                   slice_range_type);
1919 -    TYPE_CODE (slice_type) = TYPE_CODE (array_type);
1920 +       TYPE_CODE (slice_type) = TYPE_CODE (array_type);
1921  
1922 -    if (VALUE_LVAL (array) == lval_memory && value_lazy (array))
1923 -      slice = allocate_value_lazy (slice_type);
1924 +       if (VALUE_LVAL (array) == lval_memory && value_lazy (array))
1925 +         v = allocate_value_lazy (slice_type);
1926 +       else
1927 +         {
1928 +           v = allocate_value (slice_type);
1929 +           value_contents_copy (v,
1930 +                                value_embedded_offset (v),
1931 +                                array,
1932 +                                value_embedded_offset (array) + elt_offs,
1933 +                                elt_size * longest_to_int (length));
1934 +         }
1935 +
1936 +      }
1937 +    /* With a CALL_COUNT or STRIDE_LENGTH are greater than 1 we are working
1938 +       on a range of ranges.  So we copy the relevant elements into the
1939 +       new array we return.  */
1940      else
1941        {
1942 -       slice = allocate_value (slice_type);
1943 -       value_contents_copy (slice, 0, array, offset,
1944 -                            type_length_units (slice_type));
1945 +       int j, offs_store = elt_offs;
1946 +       LONGEST dst_offset = 0;
1947 +       LONGEST src_row_length = TYPE_LENGTH (TYPE_TARGET_TYPE (array_type));
1948 +
1949 +       if (call_count == 1)
1950 +         {
1951 +           /* When CALL_COUNT is equal to 1 we are working on the current range
1952 +              and use these elements directly.  */
1953 +           element_type = TYPE_TARGET_TYPE (array_type);
1954 +         }
1955 +       else
1956 +         {
1957 +           /* Working on an array of arrays, the type of the elements is the type
1958 +              of the subarrays' type.  */
1959 +           element_type = TYPE_TARGET_TYPE (TYPE_TARGET_TYPE (array_type));
1960 +         }
1961 +
1962 +       slice_type = create_array_type (NULL, element_type, slice_range_type);
1963 +
1964 +        /* If we have a one dimensional array, we copy its TYPE_CODE.  For a
1965 +           multi dimensional array we copy the embedded type's TYPE_CODE.  */
1966 +       if (call_count == 1)
1967 +         TYPE_CODE (slice_type) = TYPE_CODE (array_type);
1968 +       else
1969 +         TYPE_CODE (slice_type) = TYPE_CODE (TYPE_TARGET_TYPE (array_type));
1970 +
1971 +       v = allocate_value (slice_type);
1972 +
1973 +       /* Iterate through the rows of the outer array and set the new offset
1974 +          for each row.  */
1975 +       for (i = 0; i < row_count; i++)
1976 +         {
1977 +           elt_offs = offs_store + i * src_row_length;
1978 +
1979 +           /* Iterate through the elements in each row to copy only those.  */
1980 +           for (j = 1; j <= elem_count; j++)
1981 +             {
1982 +               /* Fetches the contents of ARRAY and copies them into V.  */
1983 +               value_contents_copy (v, dst_offset, array, elt_offs, elt_size);
1984 +               elt_offs += elt_size * stride_length;
1985 +               dst_offset += elt_size;
1986 +             }
1987 +         }
1988        }
1989  
1990 -    set_value_component_location (slice, array);
1991 -    set_value_offset (slice, value_offset (array) + offset);
1992 +    set_value_component_location (v, array);
1993 +    if (VALUE_LVAL (v) == lval_register)
1994 +      {
1995 +       VALUE_REGNUM (v) = VALUE_REGNUM (array);
1996 +       VALUE_NEXT_FRAME_ID (v) = VALUE_NEXT_FRAME_ID (array);
1997 +      }
1998 +    set_value_offset (v, value_offset (array) + elt_offs);
1999    }
2000  
2001 -  return slice;
2002 +  return v;
2003  }
2004  
2005  /* Create a value for a FORTRAN complex number.  Currently most of the
2006 diff --git a/gdb/value.h b/gdb/value.h
2007 index 7dc67dc721..03ca06448f 100644
2008 --- a/gdb/value.h
2009 +++ b/gdb/value.h
2010 @@ -1128,6 +1128,8 @@ extern struct value *varying_to_slice (struct value *);
2011  
2012  extern struct value *value_slice (struct value *, int, int);
2013  
2014 +extern struct value *value_slice_1 (struct value *, int, int, int, int);
2015 +
2016  extern struct value *value_literal_complex (struct value *, struct value *,
2017                                             struct type *);
2018  
2019 -- 
2020 2.14.3
2021
This page took 0.480145 seconds and 3 git commands to generate.