]> git.ipfire.org Git - thirdparty/gcc.git/commit
ada: Fix segmentation fault on slice of array with Unbounded_String component
authorEric Botcazou <ebotcazou@adacore.com>
Fri, 3 May 2024 23:30:40 +0000 (01:30 +0200)
committerMarc Poulhiès <poulhies@adacore.com>
Thu, 13 Jun 2024 13:30:35 +0000 (15:30 +0200)
commitea3172a4247c11dbb90ed6484bbba97a2bbcc1f9
treefb7931cc526ee98ed3e4b5acd99e1f2da78d1c4b
parentd7de75a0c28d505e60ceefccb508807a06a985e3
ada: Fix segmentation fault on slice of array with Unbounded_String component

This fixes a regression introduced by the overhaul of the implementation
of finalization.  When the first subtype of an array type is declared as
constrained, the Finalize_Address primitive of the base type synthesized
by the compiler is tailored to this first subtype, which means that this
primitive cannot be used for other subtypes of the array type, which may
for example be generated when an aggregate is assigned to a slice of an
object of the first subtype.

The straightforward solution would be to synthesize the Finalize_Address
primitive for the base type instead, but its clean implementation would
require changing the way allocators are implemented to always allocate
the bounds alongside the data, which may turn out to be delicate.

This instead changes the compiler to synthesize a local Finalize_Address
primitive in the problematic cases, which should be rare in practice, and
also contains a fixlet for Find_Last_Init, which fails to get to the base
type again in the indirect case and, therefore, mishandles array subtypes.

gcc/ada/

* exp_ch7.adb (Attach_Object_To_Master_Node): Fix formatting.
(Build_Finalizer.Process_Object_Declaration): Synthesize a local
Finalize_Address primitive if the object's subtype is an array
that has a constrained first subtype and is not this first subtype.
* exp_util.adb (Find_Last_Init): Get again to the base type in the
indirect case.
gcc/ada/exp_ch7.adb
gcc/ada/exp_util.adb