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.