]> git.ipfire.org Git - thirdparty/gcc.git/commit
ada: Excess elements created for indexed aggregates with iterator_specifications
authorGary Dismukes <dismukes@adacore.com>
Tue, 12 Dec 2023 22:10:37 +0000 (22:10 +0000)
committerMarc Poulhiès <poulhies@adacore.com>
Tue, 9 Jan 2024 13:13:32 +0000 (14:13 +0100)
commit8ca25eacaa326022bd2f3e2ffc8a690a9d7363d0
tree787ad93c3eb71f2d02988c0343aac512ceaa9a67
parentb4beadb39a6cc97a6a628a99752c48123b37db60
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.
gcc/ada/exp_aggr.adb