[Ada] Fix wrong value of 'Size for slices of bit-packed arrays
commit37915d022449d21fe7bfa7db640a15e77cd3352e
authorEric Botcazou <ebotcazou@adacore.com>
Tue, 17 Sep 2019 07:59:16 +0000 (17 07:59 +0000)
committerPierre-Marie de Rodat <pmderodat@gcc.gnu.org>
Tue, 17 Sep 2019 07:59:16 +0000 (17 07:59 +0000)
tree63d68b13e71558c24f9d2b3a8d47774eb456eb8f
parent38b06e7a19d4002697117965d0bfce7ee77e1d40
[Ada] Fix wrong value of 'Size for slices of bit-packed arrays

This fixes a long-standing issue in the compiler which would return
a wrong value for the Size attribute applied to slices of bit-packed
arrays whose size is not a multiple of the storage unit.

The problem is that the computation was done in the code generator
after the bit-packed array had been internally rewritten into an
array of bytes, so the Size was always rounded up to the next byte.

The computation is now rewritten into the product of the Length and
Compnent_Size attribute of the slices before being sent to the code
generator.

2019-09-17  Eric Botcazou  <ebotcazou@adacore.com>

gcc/ada/

* exp_attr.adb (Expand_Size_Attribute): Chain the special cases
on the back-end path and rewrite the attribute appled to slices
of bit-packed arrays into the product of the Length and the
Compoent_Size attributes of the slices.
* exp_ch5.adb (Expand_Assign_Array_Bitfield): Use Size attribute
directly to compute the bitfield's size.

gcc/testsuite/

* gnat.dg/pack25.adb: New testcase.

From-SVN: r275769
gcc/ada/ChangeLog
gcc/ada/exp_attr.adb
gcc/ada/exp_ch5.adb
gcc/testsuite/ChangeLog
gcc/testsuite/gnat.dg/pack25.adb [new file with mode: 0644]