]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Fix pragma Import ignored in conjunction with address aspect
authorEric Botcazou <ebotcazou@adacore.com>
Tue, 16 Jun 2026 16:28:01 +0000 (18:28 +0200)
committerMarc Poulhiès <dkm@gcc.gnu.org>
Mon, 29 Jun 2026 11:17:12 +0000 (13:17 +0200)
The special mechanism used to "deinitialize" an object in the presence of
a pragma Import works in conjunction with an address clause, but not with
an address aspect.  This tweaks the expansion so as to plug this loophole.

gcc/ada/ChangeLog:

* einfo.ads (Initialization_Statements): Adjust description.
* exp_ch3.adb (Default_Initialize_Object): Use the special mechanism
of Initialization_Statements, if need be, instead of inserting the
initialization statements directly into the freeze actions.

gcc/ada/einfo.ads
gcc/ada/exp_ch3.adb

index 960f39004ab97a471396463c9aa09e1851951d42..ea563109418657351e0c9b150410f2c27553e9a5 100644 (file)
@@ -2344,8 +2344,8 @@ package Einfo is
 --       call wrapper if available.
 
 --    Initialization_Statements
---       Defined in constants and variables. For a composite object coming from
---       source and initialized with an aggregate or a call expanded in place,
+--       Defined in constants and variables. For composite objects coming from
+--       source and (default-)initialized with an aggregate or a function call,
 --       points to a compound statement containing the assignment(s). This is
 --       used for a couple of purposes: 1) to defer the initialization to the
 --       freeze point if an address clause or a delayed aspect is present for
index ed3061cc71afad5d5e6f7008cabceb1a05d8d13c..3b823b6fa411c82aa1179d01f8ee0743147e10e2 100644 (file)
@@ -7504,6 +7504,8 @@ package body Exp_Ch3 is
       -------------------------------
 
       procedure Default_Initialize_Object (After : Node_Id) is
+         Marker : constant Node_Id := Next (After);
+
          Init_Expr  : Node_Id;
          Init_Stmts : List_Id;
 
@@ -7557,16 +7559,18 @@ package body Exp_Ch3 is
             Init_Stmts := Build_Default_Initialization (N, Typ, Def_Id);
          end if;
 
-         --  Insert the whole initialization sequence into the tree. If the
-         --  object has a delayed freeze, as will be the case when it has
-         --  aspect specifications, the initialization sequence is part of
-         --  the freeze actions.
+         --  Insert the whole initialization sequence into the tree. Park the
+         --  generated statements if the declaration requires it and is not the
+         --  node that is wrapped in a transient scope.
 
          if Present (Init_Stmts) then
-            if Has_Delayed_Freeze (Def_Id) then
-               Append_Freeze_Actions (Def_Id, Init_Stmts);
-            else
-               Insert_Actions_After (After, Init_Stmts);
+            Insert_Actions_After (After, Init_Stmts);
+
+            if not Special_Ret_Obj
+              and then Needs_Initialization_Statements (N)
+              and then not (Scope_Is_Transient and then N = Node_To_Be_Wrapped)
+            then
+               Move_To_Initialization_Statements (N, Marker);
             end if;
          end if;
       end Default_Initialize_Object;