]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Fix latent issue exposed by recent change in aggregate expansion
authorEric Botcazou <ebotcazou@adacore.com>
Mon, 11 Nov 2024 23:18:00 +0000 (00:18 +0100)
committerMarc Poulhiès <dkm@gcc.gnu.org>
Tue, 26 Nov 2024 09:49:34 +0000 (10:49 +0100)
The tag is not assigned when a compile-time known aggregate initializes an
object declared with an address clause/aspect.

gcc/ada/ChangeLog:

* freeze.adb: Remove clauses for Exp_Ch3.
(Check_Address_Clause): Always reassign the tag for an object of a
tagged type if there is an initialization expression.

gcc/ada/freeze.adb

index b52898f421210ebb6e0898af39c2ccb0d9ea0f0e..9486d02f6818e2f34f31e67668854b4a7b448e9f 100644 (file)
@@ -33,7 +33,6 @@ with Einfo.Entities; use Einfo.Entities;
 with Einfo.Utils;    use Einfo.Utils;
 with Elists;         use Elists;
 with Errout;         use Errout;
-with Exp_Ch3;        use Exp_Ch3;
 with Exp_Ch7;        use Exp_Ch7;
 with Exp_Disp;       use Exp_Disp;
 with Exp_Pakd;       use Exp_Pakd;
@@ -767,16 +766,23 @@ package body Freeze is
             Append_Freeze_Action (E,
               Make_Assignment_Statement (Sloc (Decl),
                 Name       => Lhs,
-                Expression => Expression (Decl)));
+                Expression => Init));
 
             Set_No_Initialization (Decl);
 
             --  If the object is tagged, check whether the tag must be
             --  reassigned explicitly.
 
-            Tag_Assign := Make_Tag_Assignment (Decl);
-            if Present (Tag_Assign) then
-               Append_Freeze_Action (E, Tag_Assign);
+            if Is_Tagged_Type (Typ) and then Tagged_Type_Expansion then
+               Tag_Assign :=
+                 Make_Tag_Assignment_From_Type
+                   (Sloc (Decl),
+                    New_Occurrence_Of (E, Sloc (Decl)),
+                    Underlying_Type (Typ));
+
+               if Present (Tag_Assign) then
+                  Append_Freeze_Action (E, Tag_Assign);
+               end if;
             end if;
          end if;
       end if;