]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Fix finalize address for arrays of protected types
authorArtur Pietrek <pietrek@adacore.com>
Thu, 21 May 2026 13:29:10 +0000 (15:29 +0200)
committerMarc Poulhiès <dkm@gcc.gnu.org>
Thu, 4 Jun 2026 08:42:24 +0000 (10:42 +0200)
Make_Address_For_Finalize emits a -Descriptor_Size shift whenever
the array's first subtype is unconstrained, but does not check whether
the object has a controlled component. For arrays of protected types
Has_Controlled_Component is False so no dope vector is allocated, but
at scope exit the incorrect finalize address is dereferenced, which
may lead to EXCEPTION_ACCESS_VIOLATION, or silent error.

gcc/ada/ChangeLog:

* exp_ch7.adb (Make_Address_For_Finalize): check
Has_Controlled_Component predicate before emitting the shift to be
consistant with what Is_Constr_Array_Subt_With_Bounds says.

gcc/ada/exp_ch7.adb

index c303a6145df77425967ba295275b3f9cacfe6a98..11c86895aa16af76cc8e31c9594513a726aa0442 100644 (file)
@@ -5471,11 +5471,12 @@ package body Exp_Ch7 is
       --  subtype, its Finalize_Address primitive expects the address of
       --  an object with a dope vector (see Make_Finalize_Address_Stmts).
       --  This is achieved by setting Is_Constr_Array_Subt_With_Bounds,
-      --  but the address of the object is still that of its elements,
-      --  so we need to shift it back to skip the dope vector.
+      --  whose predicate also requires Has_Controlled_Component, so we
+      --  have to check for the controlled component here, too.
 
       if Is_Array_Type (Utyp)
         and then not Is_Constrained (First_Subtype (Utyp))
+        and then Has_Controlled_Component (Utyp)
       then
          Obj_Addr :=
            Shift_Address_For_Descriptor