-- case X is
-- when A =>
-- then-obj : typ := then_expr;
- -- target := then-obj'Unrestricted_Access;
+ -- target := then-obj'Unrestricted_Access;
-- when B =>
-- else-obj : typ := else-expr;
- -- target := else-obj'Unrestricted_Access;
+ -- target := else-obj'Unrestricted_Access;
-- ...
-- end case
--
-- Target := Obj'Unrestricted_Access;
elsif Optimize_Object_Decl then
+ Par_Obj := Defining_Identifier (Par);
Obj := Make_Temporary (Loc, 'C', Alt_Expr);
+ Set_Is_Return_Object (Obj, Is_Return_Object (Par_Obj));
Insert_Conditional_Object_Declaration
(Obj, Typ, Alt_Expr, Const => Constant_Present (Par));
-- if cond then
-- then-obj : typ := then_expr;
- -- target := then-obj'Unrestricted_Access;
+ -- target := then-obj'Unrestricted_Access;
-- else
-- else-obj : typ := else-expr;
- -- target := else-obj'Unrestricted_Access;
+ -- target := else-obj'Unrestricted_Access;
-- end if;
--
-- obj : typ renames target.all;
Target : constant Entity_Id := Make_Temporary (Loc, 'C', N);
begin
+ Set_Is_Return_Object (Then_Obj, Is_Return_Object (Par_Obj));
Insert_Conditional_Object_Declaration
(Then_Obj, Typ, Thenx, Const => Constant_Present (Par));
+
+ Set_Is_Return_Object (Else_Obj, Is_Return_Object (Par_Obj));
Insert_Conditional_Object_Declaration
(Else_Obj, Typ, Elsex, Const => Constant_Present (Par));
-- cannot invoke Process_Transients_In_Expression on it since it is not
-- a transient object (it has the lifetime of the original object).
- if Needs_Finalization (Base_Type (Etype (Obj_Id))) then
+ if Needs_Finalization (Base_Type (Etype (Obj_Id)))
+ and then not Is_Return_Object (Obj_Id)
+ then
Master_Node_Id := Make_Temporary (Loc, 'N');
Master_Node_Decl :=
Make_Master_Node_Declaration (Loc, Master_Node_Id, Obj_Id);
Obj_Def : Node_Id;
begin
- -- First limitation: distribution is not implemented for return objects
-
- if Nkind (N) /= N_Object_Declaration
- or else Is_Return_Object (Defining_Identifier (N))
- then
+ if Nkind (N) /= N_Object_Declaration then
return False;
end if;
Obj_Def := Object_Definition (N);
- -- Second limitation: distribution is not implemented for CW types
+ -- Current limitation: distribution is not implemented for CW types,
+ -- except for return objects which always live on the secondary stack.
if Is_Entity_Name (Obj_Def)
- and then Is_Class_Wide_Type (Entity (Obj_Def))
+ and then (Is_Class_Wide_Type (Entity (Obj_Def))
+ and then not Is_Return_Object (Defining_Identifier (N)))
then
return False;
end if;
Generate_Definition (Id);
Enter_Name (Id);
+ -- For artificial return objects created from within a transient
+ -- scope, propagate Return_Applies_To from the enclosing return.
+
+ if Is_Return_Object (Id) and then Scope_Is_Transient then
+ Set_Return_Applies_To
+ (Scope (Id), Return_Applies_To (Scope (Scope (Id))));
+ end if;
+
Mark_Coextensions (N, Object_Definition (N));
T := Find_Type_Of_Object (Object_Definition (N), N);
-- has been replaced by a renaming declaration during its expansion
-- (see Expand_N_Case_Expression and Expand_N_If_Expression).
- if Expander_Active
- and then Nkind (E) in N_Case_Expression | N_If_Expression
+ if Nkind (E) in N_Case_Expression | N_If_Expression
and then Nkind (N) = N_Object_Renaming_Declaration
then
goto Leave;