]> git.ipfire.org Git - thirdparty/gcc.git/commit
ada: Fix latent alignment issue for dynamically-allocated controlled objects
authorEric Botcazou <ebotcazou@adacore.com>
Wed, 21 Feb 2024 20:48:13 +0000 (21:48 +0100)
committerMarc Poulhiès <poulhies@adacore.com>
Thu, 16 May 2024 08:49:29 +0000 (10:49 +0200)
commit48068753771507b4e95f746eaf8b0d0135e6c8ef
treecc0e44eba638bdae6ae3f8073d095009a42fdcbf
parentb98e256652c336160afa47bf8735eb4aa3529135
ada: Fix latent alignment issue for dynamically-allocated controlled objects

Dynamically-allocated controlled objects are attached to a finalization
collection by means of a hidden header placed right before the object,
which means that the size effectively allocated must naturally account
for the size of this header.  But the allocation must also account for
the alignment of this header in order to have it properly aligned.

gcc/ada/

* libgnat/s-finpri.ads (Header_Alignment): New function.
(Header_Size): Adjust description.
(Master_Node): Put Finalize_Address as first component.
(Collection_Node): Likewise.
* libgnat/s-finpri.adb (Header_Alignment): New function.
(Header_Size): Return the object size in storage units.
* libgnat/s-stposu.ads (Adjust_Controlled_Dereference): Replace
collection node with header in description.
* libgnat/s-stposu.adb (Adjust_Controlled_Dereference): Likewise.
(Allocate_Any_Controlled): Likewise.  Pass the maximum of the
specified alignment and that of the header to the allocator.
(Deallocate_Any_Controlled): Likewise to the deallocator.
gcc/ada/libgnat/s-finpri.adb
gcc/ada/libgnat/s-finpri.ads
gcc/ada/libgnat/s-stposu.adb
gcc/ada/libgnat/s-stposu.ads