end if;
end Clean_Task_Names;
+ ----------------------------------------
+ -- Ensure_Activation_Chain_And_Master --
+ ----------------------------------------
+
+ procedure Ensure_Activation_Chain_And_Master (Obj_Decl : Node_Id) is
+ Def_Id : constant Entity_Id := Defining_Identifier (Obj_Decl);
+ Expr : constant Node_Id := Expression (Obj_Decl);
+ Expr_Q : Node_Id;
+ Typ : constant Entity_Id := Etype (Def_Id);
+
+ begin
+ pragma Assert (Nkind (Obj_Decl) = N_Object_Declaration);
+
+ if Has_Task (Typ) or else Might_Have_Tasks (Typ) then
+ Build_Activation_Chain_Entity (Obj_Decl);
+
+ if Has_Task (Typ) then
+ Build_Master_Entity (Def_Id);
+
+ -- Handle objects initialized with BIP function calls
+
+ elsif Present (Expr) then
+ if Nkind (Expr) = N_Qualified_Expression then
+ Expr_Q := Expression (Expr);
+ else
+ Expr_Q := Expr;
+ end if;
+
+ if Is_Build_In_Place_Function_Call (Expr_Q)
+ or else Present (Unqual_BIP_Iface_Function_Call (Expr_Q))
+ or else
+ (Nkind (Expr_Q) = N_Reference
+ and then
+ Is_Build_In_Place_Function_Call (Prefix (Expr_Q)))
+ then
+ Build_Master_Entity (Def_Id);
+ end if;
+ end if;
+ end if;
+ end Ensure_Activation_Chain_And_Master;
+
------------------------------
-- Expand_Freeze_Array_Type --
------------------------------
-- also that a Master variable is established (and that the appropriate
-- enclosing construct is established as a task master).
- if Has_Task (Typ) or else Might_Have_Tasks (Typ) then
- Build_Activation_Chain_Entity (N);
-
- if Has_Task (Typ) then
- Build_Master_Entity (Def_Id);
-
- -- Handle objects initialized with BIP function calls
-
- elsif Present (Expr) then
- declare
- Expr_Q : Node_Id := Expr;
-
- begin
- if Nkind (Expr) = N_Qualified_Expression then
- Expr_Q := Expression (Expr);
- end if;
-
- if Is_Build_In_Place_Function_Call (Expr_Q)
- or else Present (Unqual_BIP_Iface_Function_Call (Expr_Q))
- or else
- (Nkind (Expr_Q) = N_Reference
- and then
- Is_Build_In_Place_Function_Call (Prefix (Expr_Q)))
- then
- Build_Master_Entity (Def_Id);
- end if;
- end;
- end if;
- end if;
+ Ensure_Activation_Chain_And_Master (N);
-- If No_Implicit_Heap_Allocations or No_Implicit_Task_Allocations
-- restrictions are active then default-sized secondary stacks are
-- Build the body of the equality function Body_Id for the untagged variant
-- record Typ with the given parameters specification list.
+ procedure Ensure_Activation_Chain_And_Master (Obj_Decl : Node_Id);
+ -- If tasks are being declared (or might be declared) by the given object
+ -- declaration then ensure to have an activation chain defined for the
+ -- tasks (has no effect if we already have one), and also that a Master
+ -- variable is established (and that the appropriate enclosing construct
+ -- is established as a task master).
+
function Freeze_Type (N : Node_Id) return Boolean;
-- This function executes the freezing actions associated with the given
-- freeze type node N and returns True if the node is to be deleted. We
with Elists; use Elists;
with Errout; use Errout;
with Expander; use Expander;
+with Exp_Ch3; use Exp_Ch3;
with Exp_Ch6; use Exp_Ch6;
with Exp_Ch7; use Exp_Ch7;
with Exp_Ch9; use Exp_Ch9;
-- object declaration.
Set_Is_Return_Object (Defining_Identifier (Obj_Decl));
- Analyze (Obj_Decl);
+
+ -- Returning a build-in-place unconstrained array type we defer
+ -- the full analysis of the returned object to avoid generating
+ -- the corresponding constrained subtype; otherwise the bounds
+ -- would be created in the stack and a dangling reference would
+ -- be returned pointing to the bounds. We perform its preanalysis
+ -- to report errors on the initializing aggregate now (if any);
+ -- we also ensure its activation chain and Master variable are
+ -- defined (if tasks are being declared) since they are generated
+ -- as part of the analysis and expansion of the object declaration
+ -- at this stage.
+
+ if Is_Array_Type (R_Type)
+ and then not Is_Constrained (R_Type)
+ and then Is_Build_In_Place_Function (Scope_Id)
+ and then Needs_BIP_Alloc_Form (Scope_Id)
+ and then Nkind_In (Expr, N_Aggregate, N_Extension_Aggregate)
+ then
+ Preanalyze (Obj_Decl);
+
+ if Expander_Active then
+ Ensure_Activation_Chain_And_Master (Obj_Decl);
+ end if;
+
+ else
+ Analyze (Obj_Decl);
+ end if;
Check_Return_Subtype_Indication (Obj_Decl);