diff options
author | Eric Botcazou <ebotcazou@adacore.com> | 2025-02-21 10:03:22 +0100 |
---|---|---|
committer | Eric Botcazou <ebotcazou@adacore.com> | 2025-06-06 16:44:45 +0200 |
commit | cb3e76508b1af7ff5ba6e43592d7d67bbb96fac6 (patch) | |
tree | 5bb4cd8f8706e2e4e9267e6f9200604de99fbf8a /gcc | |
parent | 1189522245be51d435fcc6d205e690f086f12e46 (diff) | |
download | gcc-cb3e76508b1af7ff5ba6e43592d7d67bbb96fac6.zip gcc-cb3e76508b1af7ff5ba6e43592d7d67bbb96fac6.tar.gz gcc-cb3e76508b1af7ff5ba6e43592d7d67bbb96fac6.tar.bz2 |
ada: Fix wrong initialization of library-level object by conditional expression
At library level the object must be allocated statically and with its bounds
when its nominal subtype is an unconstrained array type.
gcc/ada/ChangeLog:
* exp_ch4.adb (Insert_Conditional_Object_Declaration): Make sure the
object is allocated properly by the code generator at library level.
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/ada/exp_ch4.adb | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/gcc/ada/exp_ch4.adb b/gcc/ada/exp_ch4.adb index eb9fb6b..793e468 100644 --- a/gcc/ada/exp_ch4.adb +++ b/gcc/ada/exp_ch4.adb @@ -13292,10 +13292,12 @@ package body Exp_Ch4 is Obj_Decl : constant Node_Id := Make_Object_Declaration (Loc, Defining_Identifier => Obj_Id, - Aliased_Present => Aliased_Present (Decl), + Aliased_Present => True, Constant_Present => Constant_Present (Decl), Object_Definition => New_Copy_Tree (Object_Definition (Decl)), Expression => Relocate_Node (Expr)); + -- We make the object unconditionally aliased to avoid dangling bound + -- issues when its nominal subtype is an unconstrained array type. Master_Node_Decl : Node_Id; Master_Node_Id : Entity_Id; @@ -13310,6 +13312,11 @@ 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)); + -- 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 -- it will be declared in the arm of a conditional statement and 2) we |