aboutsummaryrefslogtreecommitdiff
path: root/gcc/ada/exp_ch4.adb
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/ada/exp_ch4.adb')
-rw-r--r--gcc/ada/exp_ch4.adb59
1 files changed, 34 insertions, 25 deletions
diff --git a/gcc/ada/exp_ch4.adb b/gcc/ada/exp_ch4.adb
index 01be3df..0cf5643 100644
--- a/gcc/ada/exp_ch4.adb
+++ b/gcc/ada/exp_ch4.adb
@@ -193,12 +193,12 @@ package body Exp_Ch4 is
procedure Insert_Conditional_Object_Declaration
(Obj_Id : Entity_Id;
+ Typ : Entity_Id;
Expr : Node_Id;
- Decl : Node_Id);
- -- Expr is the dependent expression of a conditional expression and Decl
- -- is the declaration of an object whose initialization expression is the
- -- conditional expression. Insert in the actions of Expr the declaration
- -- of Obj_Id modeled on Decl and with Expr as initialization expression.
+ Const : Boolean);
+ -- Expr is the dependent expression of a conditional expression. Insert in
+ -- the actions of Expr the declaration of Obj_Id with type Typ and Expr as
+ -- initialization expression. Const is True when Obj_Id is a constant.
procedure Insert_Dereference_Action (N : Node_Id);
-- N is an expression whose type is an access. When the type of the
@@ -5313,7 +5313,7 @@ package body Exp_Ch4 is
-- 'Unrestricted_Access.
-- Generate:
- -- type Ptr_Typ is not null access all [constant] Typ;
+ -- type Target_Typ is not null access all [constant] Typ;
else
Target_Typ := Make_Temporary (Loc, 'P');
@@ -5411,20 +5411,16 @@ package body Exp_Ch4 is
elsif Optimize_Object_Decl then
Obj := Make_Temporary (Loc, 'C', Alt_Expr);
- Insert_Conditional_Object_Declaration (Obj, Alt_Expr, Par);
-
- Alt_Expr :=
- Make_Attribute_Reference (Alt_Loc,
- Prefix => New_Occurrence_Of (Obj, Alt_Loc),
- Attribute_Name => Name_Unrestricted_Access);
-
- LHS := New_Occurrence_Of (Target, Loc);
- Set_Assignment_OK (LHS);
+ Insert_Conditional_Object_Declaration
+ (Obj, Typ, Alt_Expr, Const => Constant_Present (Par));
Stmts := New_List (
Make_Assignment_Statement (Alt_Loc,
- Name => LHS,
- Expression => Alt_Expr));
+ Name => New_Occurrence_Of (Target, Loc),
+ Expression =>
+ Make_Attribute_Reference (Alt_Loc,
+ Prefix => New_Occurrence_Of (Obj, Alt_Loc),
+ Attribute_Name => Name_Unrestricted_Access)));
-- Take the unrestricted access of the expression value for non-
-- scalar types. This approach avoids big copies and covers the
@@ -6022,8 +6018,10 @@ package body Exp_Ch4 is
Target : constant Entity_Id := Make_Temporary (Loc, 'C', N);
begin
- Insert_Conditional_Object_Declaration (Then_Obj, Thenx, Par);
- Insert_Conditional_Object_Declaration (Else_Obj, Elsex, Par);
+ Insert_Conditional_Object_Declaration
+ (Then_Obj, Typ, Thenx, Const => Constant_Present (Par));
+ Insert_Conditional_Object_Declaration
+ (Else_Obj, Typ, Elsex, Const => Constant_Present (Par));
-- Generate:
-- type Ptr_Typ is not null access all [constant] Typ;
@@ -13294,16 +13292,17 @@ package body Exp_Ch4 is
procedure Insert_Conditional_Object_Declaration
(Obj_Id : Entity_Id;
+ Typ : Entity_Id;
Expr : Node_Id;
- Decl : Node_Id)
+ Const : Boolean)
is
Loc : constant Source_Ptr := Sloc (Expr);
Obj_Decl : constant Node_Id :=
Make_Object_Declaration (Loc,
Defining_Identifier => Obj_Id,
Aliased_Present => True,
- Constant_Present => Constant_Present (Decl),
- Object_Definition => New_Copy_Tree (Object_Definition (Decl)),
+ Constant_Present => Const,
+ Object_Definition => New_Occurrence_Of (Typ, Loc),
Expression => Relocate_Node (Expr));
-- We make the object unconditionally aliased to avoid dangling bound
-- issues when its nominal subtype is an unconstrained array type.
@@ -13322,9 +13321,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