https://gcc.gnu.org/g:484fb60fdcb33703e32f1770cf2b406a4428a680

commit r15-9888-g484fb60fdcb33703e32f1770cf2b406a4428a680
Author: Eric Botcazou <ebotca...@adacore.com>
Date:   Mon May 5 16:59:13 2025 +0200

    ada: Fix wrong finalization of constrained array derived from unconstrained
    
    The bug had been present for dynamically allocated objects since the first
    rewrite of the finalization machinery more than a decade ago, and was then
    propagated to statically declared objects by the recent rewrite.
    
    gcc/ada/ChangeLog:
    
            * exp_util.adb (Finalize_Address): Do not go to the root type for
            array types.

Diff:
---
 gcc/ada/exp_util.adb | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/gcc/ada/exp_util.adb b/gcc/ada/exp_util.adb
index 1874420fd273..2510b3f1f9b0 100644
--- a/gcc/ada/exp_util.adb
+++ b/gcc/ada/exp_util.adb
@@ -6072,9 +6072,10 @@ package body Exp_Util is
       --  now known to be protected, the finalization routine is the one
       --  defined on the corresponding record of the ancestor (corresponding
       --  records do not automatically inherit operations, but maybe they
-      --  should???)
+      --  should???). This does not apply to array types, where every base
+      --  type has a finalization routine that depends on the first subtype.
 
-      if Is_Untagged_Derivation (Btyp) then
+      if Is_Untagged_Derivation (Btyp) and then not Is_Array_Type (Btyp) then
          if Is_Protected_Type (Btyp) then
             Utyp := Corresponding_Record_Type (Root_Type (Btyp));

Reply via email to