[Ada] 'first/'last/'length of array whose bound is a discriminant
authorJoel Brobecker <brobecker@adacore.com>
Thu, 15 Jan 2015 06:09:32 +0000 (10:09 +0400)
committerJoel Brobecker <brobecker@adacore.com>
Thu, 15 Jan 2015 08:53:33 +0000 (12:53 +0400)
commitbafffb51c4da50881dc5d72ec9bf9b78377ac692
tree0ebb3809995e2b934463341e002e7aad458d88fe
parenta300380e12ca04a6cb900e9bfd26161b3fe56ed8
[Ada] 'first/'last/'length of array whose bound is a discriminant

Consider the following code:

   type Table is array (Positive range <>) of Integer;
   type Object (N : Integer) is record
       Data : Table (1 .. N);
   end record;
   My_Object : Object := (N => 3, Data => (3, 5, 8));

Trying to print the range and length of the My_Object.Data array yields:

    (gdb) print my_object.data'first
    $1 = 1
    (gdb) print my_object.data'last
    $2 = 0
    (gdb) print my_object.data'length
    $3 = 0

The first one is correct, and that is thanks to the fact that
the lower bound is statically known.  However, for the upper
bound, and consequently the array's length, the values are incorrect.
It should be:

    (gdb) print my_object.data'last
    $2 = 3
    (gdb) print my_object.data'length
    $3 = 3

What happens here is that ada_array_bound_from_type sees that
our array has a parallel "___XA" type, and therefore tries to
use it.  In particular, it described our array's index type as:
[...]___XDLU_1__n, which means lower bound = 1, and upper bound
is value of "n". Unfortunately, ada_array_bound_from_type does
not have access to the discriminant, and is therefore unable to
compute the bound correctly.

Fortunately, at this stage, the bound has already been computed
a while ago, and therefore doesn't need to be re-computed here.
This patch fixes the issue by ignoring that ___XA type if the array
is marked as already fixed.

This also fixes the same issue with packed arrays.

gdb/ChangeLog:

        * ada-lang.c (ada_array_bound_from_type): Ignore array's parallel
        ___XA type if the array has already been fixed.

gdb/testsuite/ChangeLog:

        * gdb.ada/var_arr_attrs: New testcase.
gdb/ChangeLog
gdb/ada-lang.c
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.ada/var_arr_attrs.exp [new file with mode: 0644]
gdb/testsuite/gdb.ada/var_arr_attrs/foo_o115_002.adb [new file with mode: 0644]
gdb/testsuite/gdb.ada/var_arr_attrs/pck.adb [new file with mode: 0644]
gdb/testsuite/gdb.ada/var_arr_attrs/pck.ads [new file with mode: 0644]
This page took 0.037465 seconds and 4 git commands to generate.