ada: Fix double free on finalization of Vector in array aggregate
commit9f6cee820f9c8d263dfcd1772127268508360838
authorEric Botcazou <ebotcazou@adacore.com>
Sun, 26 Mar 2023 22:55:08 +0000 (27 00:55 +0200)
committerMarc Poulhiès <poulhies@adacore.com>
Fri, 26 May 2023 07:29:18 +0000 (26 09:29 +0200)
treeb902f79dc3e7d9174d53de713afa1ed24de5e6db
parent6b19eb2490675cacf72b8225d953d73029bc53fb
ada: Fix double free on finalization of Vector in array aggregate

The handling of finalization is delicate during the expansion of aggregates
since the generated assignments must not cause the finalization of the RHS.
That's why the No_Ctrl_Actions flag is set on them and the adjustments are
generated manually.

This was not done in the case of an array of array with controlled component
when its subaggregates are not expanded in place but instead are replaced by
temporaries, leading to double free or memory corruption.

gcc/ada/

* exp_aggr.adb (Initialize_Array_Component): Remove obsolete code.
(Expand_Array_Aggregate): In the case where a temporary is created
and the parent is an assignment statement with No_Ctrl_Actions set,
set Is_Ignored_Transient on the temporary.
gcc/ada/exp_aggr.adb