https://gcc.gnu.org/g:b75cf42fb1e2d49fe8e856496a8df35d2029c9dc
commit r17-1969-gb75cf42fb1e2d49fe8e856496a8df35d2029c9dc Author: Eric Botcazou <[email protected]> Date: Tue Jun 16 18:28:01 2026 +0200 ada: Fix pragma Import ignored in conjunction with address aspect 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. Diff: --- gcc/ada/einfo.ads | 4 ++-- gcc/ada/exp_ch3.adb | 20 ++++++++++++-------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/gcc/ada/einfo.ads b/gcc/ada/einfo.ads index 960f39004ab9..ea5631094186 100644 --- a/gcc/ada/einfo.ads +++ b/gcc/ada/einfo.ads @@ -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 diff --git a/gcc/ada/exp_ch3.adb b/gcc/ada/exp_ch3.adb index ed3061cc71af..3b823b6fa411 100644 --- a/gcc/ada/exp_ch3.adb +++ b/gcc/ada/exp_ch3.adb @@ -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;
