preserve type length in ada-lang.c::to_fixed_range_type
This patch fixes a potential issue which was noticed by code inspection:
ada-lang.c::to_fixed_range_type uses gdbtypes.c::create_static_range_type
to create most of the range type, which relies on create_range_type to
do most of the work. The latter has the following piece of code which
sets the length of the range type to match the length of the index_type:
if (TYPE_STUB (index_type))
TYPE_TARGET_STUB (result_type) = 1;
else
TYPE_LENGTH (result_type) = TYPE_LENGTH (check_typedef (index_type));
In Ada, it is actually possible to have a range type whose size
is smaller than its base type. For instance, with:
type Unsigned2_T is range 0 .. 2 ** 16 - 1;
for Unsigned2_T'SIZE use 16;
The compiler generates the following DWARF:
.uleb128 0x3 # (DIE (0x4e) DW_TAG_subrange_type)
.byte 0x2 # DW_AT_byte_size
.byte 0 # DW_AT_lower_bound
.value 0xffff # DW_AT_upper_bound
.long .LASF64 # DW_AT_name: "try__unsigned2_t___XDLU_0__65535"
.long 0x616 # DW_AT_type
... which points to the following base type...
.uleb128 0x1d # (DIE (0x616) DW_TAG_base_type)
.byte 0x4 # DW_AT_byte_size
.byte 0x5 # DW_AT_encoding
.long .LASF57 # DW_AT_name: "try__Tunsigned2_tB"
# DW_AT_artificial
... which has a size of 4 bytes.
With a type like this one, create_range_type returns a type whose
size is 4 bytes, instead of 2, which is not what we we would normally
expect.
Currently, this function is only used to handle array index types,
so the length of the type actually does not matter and there should
not be any user-visible consequences of the current behavior. But
it seems best to plug this latent bug now, rather than wait for it
to surface....
gdb/ChangeLog:
* ada-lang.c (to_fixed_range_type): Make sure that the size
of the range type being returned is the same as the size
of the range type being fixed.
Tested on x86_64-linux, no regression.