]> gcc.gnu.org Git - gcc.git/commit
ada: Fix double finalization for dependent expression of case expression
authorEric Botcazou <ebotcazou@adacore.com>
Fri, 9 Feb 2024 23:03:42 +0000 (00:03 +0100)
committerMarc Poulhiès <poulhies@adacore.com>
Tue, 14 May 2024 08:19:52 +0000 (10:19 +0200)
commit59c4d2e5a7169d5afa49facd0329bc2f9fe91b1a
tree2d2307c6a179aa2b3444f7c62229d28592290d92
parentd9f3a1d612eacc35027bc5ca42b0ee29b554306a
ada: Fix double finalization for dependent expression of case expression

The recent fix to Default_Initialize_Object, which has ensured that the
No_Initialization flag set on an object declaration, for example for the
temporary created by Expand_N_Case_Expression, is honored in all cases,
has also uncovered a latent issue in the machinery responsible for the
finalization of transient objects.

More specifically, the answer returned by the Is_Finalizable_Transient
predicate for an object of an access type is different when it is left
uninitialized (true) than when it is initialized to null (false), which
is incorrect; it must return false in both cases, because the only case
where an object can be finalized by the machinery through an access value
is when this value is a reference (N_Reference node) to the object.

This was already more or less the current state of the evolution of the
predicate, but this now explicitly states it in the code.

The change also sets the No_Initialization flag for the temporary created
by Expand_N_If_Expression for the sake of consistency.

gcc/ada/

* exp_ch4.adb (Expand_N_If_Expression): Set No_Initialization on the
declaration of the temporary in the by-reference case.
* exp_util.adb (Initialized_By_Access): Delete.
(Is_Allocated): Likewise.
(Initialized_By_Reference): New predicate.
(Is_Finalizable_Transient): If the transient object is of an access
type, do not return true unless it is initialized by a reference.
gcc/ada/exp_ch4.adb
gcc/ada/exp_util.adb
This page took 0.049004 seconds and 5 git commands to generate.