]> git.ipfire.org Git - thirdparty/gcc.git/commit
ada: Fix wrong finalization of constrained subtype of unconstrained array type
authorEric Botcazou <ebotcazou@adacore.com>
Tue, 6 May 2025 17:03:19 +0000 (19:03 +0200)
committerEric Botcazou <ebotcazou@adacore.com>
Tue, 1 Jul 2025 14:33:58 +0000 (16:33 +0200)
commit5bd03021271731b4260d06571e868f91740188d1
tree4f2ff76d91dd84182c71176bf31db272a8dfdfe7
parent74cc201d4d555acb55edf22945022f70cd9e331a
ada: Fix wrong finalization of constrained subtype of unconstrained array type

Dynamically allocated objects of a constrained subtype of an unconstrained
array type with a controlled component type have not been properly finalized
since the first rewrite of the finalization machinery more than a decade
ago.  The reason is that the Finalize_Address routine is that of the base
type, which is unconstrained, and thus requires the bounds, which are not
present for the subtype in the allocation.

This is fixed by setting Is_Constr_Array_Subt_With_Bounds for allocators the
same way it is set for object declarations.  The rest is just refactoring.

gcc/ada/ChangeLog:

* exp_ch7.adb (Shift_Address_For_Descriptor): New function.
(Make_Address_For_Finalize): Call above function.
(Make_Finalize_Address_Stmts): Likewise.
* exp_util.ads (Is_Constr_Array_Subt_Of_Unc_With_Controlled): New
predicate.
* exp_util.adb (Is_Constr_Array_Subt_Of_Unc_With_Controlled): Ditto.
(Remove_Side_Effects): Call above predicate.
* sem_ch3.adb (Analyze_Object_Declaration): Likewise.
* sem_ch4.adb (Analyze_Allocator): Allocate the bounds by setting
Is_Constr_Array_Subt_With_Bounds when appropriate.
gcc/ada/exp_ch7.adb
gcc/ada/exp_util.adb
gcc/ada/exp_util.ads
gcc/ada/sem_ch3.adb
gcc/ada/sem_ch4.adb