]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Improve fix for object with address clause and C++ constructor
authorJavier Miranda <miranda@adacore.com>
Tue, 23 Dec 2025 19:05:33 +0000 (19:05 +0000)
committerMarc Poulhiès <dkm@gcc.gnu.org>
Fri, 9 Jan 2026 10:57:22 +0000 (11:57 +0100)
Improves previous fix to handle an object that has an address clause
and it is initialized by C++ imported constructor call.

gcc/ada/ChangeLog:

* exp_ch3.adb (Expand_N_Object_Declaration): Remove previous patch
and place the call to the constructor into a compound statement
attached to the object; the compound statement will be moved to
the freezing actions of the object if the object has an address
clause.

gcc/ada/exp_ch3.adb

index d233be85507a649fc11c9aebfdb0365c5f8f3d5b..cbacd42fb0c9c202daa54082e88d5ac17e5deca6 100644 (file)
@@ -8021,10 +8021,6 @@ package body Exp_Ch3 is
       --  Explicit initialization present
 
       else
-         --  Obtain actual expression from qualified expression
-
-         Expr_Q := Unqualify (Expr);
-
          --  When we have the appropriate kind of aggregate in the expression
          --  (this has been determined during analysis of the aggregate by
          --  setting the Expansion_Delayed flag), let's perform in place
@@ -8494,6 +8490,7 @@ package body Exp_Ch3 is
             elsif Is_CPP_Constructor_Call (Expr) then
                declare
                   Id_Ref : constant Node_Id := New_Occurrence_Of (Def_Id, Loc);
+                  Marker : constant Node_Id := Next (N);
 
                begin
                   --  The call to the initialization procedure does NOT freeze
@@ -8502,16 +8499,6 @@ package body Exp_Ch3 is
                   Set_Must_Not_Freeze (Id_Ref);
                   Set_Assignment_OK (Id_Ref);
 
-                  --  Avoid separating an object declaration from
-                  --  its representation clauses.
-
-                  while Present (Next (Init_After))
-                    and then Nkind (Next (Init_After)) in
-                               N_Attribute_Definition_Clause
-                  loop
-                     Init_After := Next (Init_After);
-                  end loop;
-
                   Insert_Actions_After (Init_After,
                     Build_Initialization_Call (N, Id_Ref, Typ,
                       Constructor_Ref => Expr));
@@ -8520,6 +8507,22 @@ package body Exp_Ch3 is
                   --  to avoid its management in the backend
 
                   Set_Expression (N, Empty);
+
+                  --  Place the call to the constructor into a compound
+                  --  statement attached to the object through attribute
+                  --  Initialization_Statements; the compound statement will
+                  --  be moved to the freezing actions of the object if the
+                  --  object has an address clause (see Analyze_Attribute_
+                  --  Definition_Clause, Attribute_Address).
+
+                  if Needs_Initialization_Statements (N)
+                    and then not (Scope_Is_Transient
+                                    and then N = Node_To_Be_Wrapped)
+                  then
+                     Set_No_Initialization (N);
+                     Move_To_Initialization_Statements (N, Marker);
+                  end if;
+
                   return;
                end;