aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorEric Botcazou <ebotcazou@adacore.com>2025-03-25 18:23:50 +0100
committerEric Botcazou <ebotcazou@adacore.com>2025-06-10 10:59:29 +0200
commitd02a2fe99f895f7c8cf969b618a51700e61c69ac (patch)
treefbadf9dfff8a92345d4d80f67a50c8fbc1b5aabb /gcc
parent4aca5bc773ced42d006e07197e24462d0fa38a8f (diff)
downloadgcc-d02a2fe99f895f7c8cf969b618a51700e61c69ac.zip
gcc-d02a2fe99f895f7c8cf969b618a51700e61c69ac.tar.gz
gcc-d02a2fe99f895f7c8cf969b618a51700e61c69ac.tar.bz2
ada: Fix wrong initialization of library-level object by conditional expression
The previous fix was not robust enough in the presence of transient scopes. gcc/ada/ChangeLog: * exp_ch4.adb (Insert_Conditional_Object_Declaration): Deal with a transient scope being created around the declaration. * freeze.adb (Freeze_Entity): Do not call Freeze_Static_Object for a renaming declaration.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ada/exp_ch4.adb16
-rw-r--r--gcc/ada/freeze.adb3
2 files changed, 15 insertions, 4 deletions
diff --git a/gcc/ada/exp_ch4.adb b/gcc/ada/exp_ch4.adb
index 161bcee..0cf605c 100644
--- a/gcc/ada/exp_ch4.adb
+++ b/gcc/ada/exp_ch4.adb
@@ -13312,9 +13312,19 @@ package body Exp_Ch4 is
Insert_Action (Expr, Obj_Decl);
-- The object can never be local to an elaboration routine at library
- -- level since we will take 'Unrestricted_Access of it.
-
- Set_Is_Statically_Allocated (Obj_Id, Is_Library_Level_Entity (Obj_Id));
+ -- level since we will take 'Unrestricted_Access of it. Beware that
+ -- Is_Library_Level_Entity always returns False when called from within
+ -- a transient scope, but the associated block will not be materialized
+ -- when the transient scope is finally closed in the case of an object
+ -- declaration (see Exp.Ch7.Wrap_Transient_Declaration).
+
+ if Scope (Obj_Id) = Current_Scope and then Scope_Is_Transient then
+ Set_Is_Statically_Allocated
+ (Obj_Id, Is_Library_Level_Entity (Scope (Obj_Id)));
+ else
+ Set_Is_Statically_Allocated
+ (Obj_Id, Is_Library_Level_Entity (Obj_Id));
+ end if;
-- If the object needs finalization, we need to insert its Master_Node
-- manually because 1) the machinery in Exp_Ch7 will not pick it since
diff --git a/gcc/ada/freeze.adb b/gcc/ada/freeze.adb
index 54b6202..93ba3d0 100644
--- a/gcc/ada/freeze.adb
+++ b/gcc/ada/freeze.adb
@@ -6869,9 +6869,10 @@ package body Freeze is
end if;
end if;
- -- Static objects require special handling
+ -- Statically allocated objects require special handling
if (Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
+ and then No (Renamed_Object (E))
and then Is_Statically_Allocated (E)
then
Freeze_Static_Object (E);