diff options
author | Gary Dismukes <dismukes@adacore.com> | 2023-12-12 22:10:37 +0000 |
---|---|---|
committer | Marc Poulhiès <poulhies@adacore.com> | 2024-01-09 14:13:32 +0100 |
commit | 8ca25eacaa326022bd2f3e2ffc8a690a9d7363d0 (patch) | |
tree | 787ad93c3eb71f2d02988c0343aac512ceaa9a67 /gcc/ada/gcc-interface/utils.cc | |
parent | b4beadb39a6cc97a6a628a99752c48123b37db60 (diff) | |
download | gcc-8ca25eacaa326022bd2f3e2ffc8a690a9d7363d0.zip gcc-8ca25eacaa326022bd2f3e2ffc8a690a9d7363d0.tar.gz gcc-8ca25eacaa326022bd2f3e2ffc8a690a9d7363d0.tar.bz2 |
ada: Excess elements created for indexed aggregates with iterator_specifications
In the case of an indexed aggregate of a container type with both Add_Unnamed
and New_Indexed specified in the Aggregate aspect of the type (such as for
the Vector type in Ada.Containers.Vectors), in cases where a component
association is given by an iterator_specification, the compiler could end
up generating a call to the New_Indexed operation rather than the Empty
operation. For example, in the case of a Vector type, this could result
in allocating a container of the size of the defaulted Capacity formal of
the New_Vector function (with uninitialized components), and elements added
in the aggregate would append to that preallocated Vector. The compiler is
corrected so that the Empty function is called to initialize the implicit
aggregate object, rather than the New_Indexed function.
gcc/ada/
* exp_aggr.adb (Expand_Container_Aggregate): Add code to determine
whether the aggregate is an indexed aggregate, setting a flag
(Is_Indexed_Aggregate), which is tested to have proper separation
of treatment for the Add_Unnamed
(for positional aggregates) and New_Indexed (for indexed
aggregates) cases. In the code generating associations for indexed
aggregates, remove the code for Expressions cases entirely, since
the code for indexed aggregates is governed by the presence of
Component_Associations, and add an assertion that Expressions must
be Empty. Also, exclude empty aggregates from entering that code.
Diffstat (limited to 'gcc/ada/gcc-interface/utils.cc')
0 files changed, 0 insertions, 0 deletions