Skip to content
Snippets Groups Projects
Commit 59c4d2e5 authored by Eric Botcazou's avatar Eric Botcazou Committed by Marc Poulhiès
Browse files

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.
parent d9f3a1d6
No related branches found
No related tags found
No related merge requests found
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment