From: Eric Botcazou Date: Tue, 16 Jun 2026 16:28:01 +0000 (+0200) Subject: ada: Fix pragma Import ignored in conjunction with address aspect X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=b75cf42fb1e2d49fe8e856496a8df35d2029c9dc;p=thirdparty%2Fgcc.git 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 --git a/gcc/ada/einfo.ads b/gcc/ada/einfo.ads index 960f39004ab..ea563109418 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 ed3061cc71a..3b823b6fa41 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;