===================================================================
@@ -2143,6 +2143,37 @@
return False;
end Has_Controlled_Coextensions;
+ ------------------------
+ -- Has_Address_Clause --
+ ------------------------
+
+ -- Should this function check the private part in a package ???
+
+ function Has_Following_Address_Clause (D : Node_Id) return Boolean is
+ Id : constant Entity_Id := Defining_Identifier (D);
+ Decl : Node_Id;
+
+ begin
+ Decl := Next (D);
+ while Present (Decl) loop
+ if Nkind (Decl) = N_At_Clause
+ and then Chars (Identifier (Decl)) = Chars (Id)
+ then
+ return True;
+
+ elsif Nkind (Decl) = N_Attribute_Definition_Clause
+ and then Chars (Decl) = Name_Address
+ and then Chars (Name (Decl)) = Chars (Id)
+ then
+ return True;
+ end if;
+
+ Next (Decl);
+ end loop;
+
+ return False;
+ end Has_Following_Address_Clause;
+
--------------------
-- Homonym_Number --
--------------------
===================================================================
@@ -444,6 +444,11 @@
-- Determine whether a record type has anonymous access discriminants with
-- a controlled designated type.
+ function Has_Following_Address_Clause (D : Node_Id) return Boolean;
+ -- D is the node for an object declaration. This function searches the
+ -- current declarative part to look for an address clause for the object
+ -- being declared, and returns True if one is found.
+
function Homonym_Number (Subp : Entity_Id) return Nat;
-- Here subp is the entity for a subprogram. This routine returns the
-- homonym number used to disambiguate overloaded subprograms in the same
===================================================================
@@ -5659,16 +5659,18 @@
-- We only give the warning for non-imported entities of a type for
-- which a non-null base init proc is defined, or for objects of access
- -- types with implicit null initialization, or when Initialize_Scalars
+ -- types with implicit null initialization, or when Normalize_Scalars
-- applies and the type is scalar or a string type (the latter being
-- tested for because predefined String types are initialized by inline
- -- code rather than by an init_proc).
+ -- code rather than by an init_proc). Note that we do not give the
+ -- warning for Initialize_Scalars, since we suppressed initialization
+ -- in this case.
if Present (Expr)
and then not Is_Imported (Ent)
and then (Has_Non_Null_Base_Init_Proc (Typ)
or else Is_Access_Type (Typ)
- or else (Init_Or_Norm_Scalars
+ or else (Normalize_Scalars
and then (Is_Scalar_Type (Typ)
or else Is_String_Type (Typ))))
then
===================================================================
@@ -4122,12 +4122,6 @@
-- array sub-aggregate we start the computation from. Dim is the
-- dimension corresponding to the sub-aggregate.
- function Has_Address_Clause (D : Node_Id) return Boolean;
- -- If the aggregate is the expression in an object declaration, it
- -- cannot be expanded in place. This function does a lookahead in the
- -- current declarative part to find an address clause for the object
- -- being declared.
-
function In_Place_Assign_OK return Boolean;
-- Simple predicate to determine whether an aggregate assignment can
-- be done in place, because none of the new values can depend on the
@@ -4435,35 +4429,6 @@
end Compute_Others_Present;
------------------------
- -- Has_Address_Clause --
- ------------------------
-
- function Has_Address_Clause (D : Node_Id) return Boolean is
- Id : constant Entity_Id := Defining_Identifier (D);
- Decl : Node_Id;
-
- begin
- Decl := Next (D);
- while Present (Decl) loop
- if Nkind (Decl) = N_At_Clause
- and then Chars (Identifier (Decl)) = Chars (Id)
- then
- return True;
-
- elsif Nkind (Decl) = N_Attribute_Definition_Clause
- and then Chars (Decl) = Name_Address
- and then Chars (Name (Decl)) = Chars (Id)
- then
- return True;
- end if;
-
- Next (Decl);
- end loop;
-
- return False;
- end Has_Address_Clause;
-
- ------------------------
-- In_Place_Assign_OK --
------------------------
@@ -5162,6 +5127,8 @@
Build_Activation_Chain_Entity (N);
end if;
+ -- Should document these individual tests ???
+
if not Has_Default_Init_Comps (N)
and then Comes_From_Source (Parent (N))
and then Nkind (Parent (N)) = N_Object_Declaration
@@ -5170,7 +5137,13 @@
and then N = Expression (Parent (N))
and then not Is_Bit_Packed_Array (Typ)
and then not Has_Controlled_Component (Typ)
- and then not Has_Address_Clause (Parent (N))
+
+ -- If the aggregate is the expression in an object declaration, it
+ -- cannot be expanded in place. Lookahead in the current declarative
+ -- part to find an address clause for the object being declared. If
+ -- one is present, we cannot build in place. Unclear comment???
+
+ and then not Has_Following_Address_Clause (Parent (N))
then
Tmp := Defining_Identifier (Parent (N));
Set_No_Initialization (Parent (N));
===================================================================
@@ -4466,7 +4466,10 @@
-- it will be assigned subsequently. In particular, there is no point
-- in applying Initialize_Scalars to such a temporary.
- elsif Needs_Simple_Initialization (Typ)
+ elsif Needs_Simple_Initialization
+ (Typ,
+ Initialize_Scalars
+ and then not Has_Following_Address_Clause (N))
and then not Is_Internal (Def_Id)
and then not Has_Init_Expression (N)
then
@@ -8145,7 +8148,14 @@
-- Needs_Simple_Initialization --
---------------------------------
- function Needs_Simple_Initialization (T : Entity_Id) return Boolean is
+ function Needs_Simple_Initialization
+ (T : Entity_Id;
+ Consider_IS : Boolean := True) return Boolean
+ is
+ Consider_IS_NS : constant Boolean :=
+ Normalize_Scalars
+ or (Initialize_Scalars and Consider_IS);
+
begin
-- Check for private type, in which case test applies to the underlying
-- type of the private type.
@@ -8167,7 +8177,7 @@
-- types.
elsif Is_Access_Type (T)
- or else (Init_Or_Norm_Scalars and then (Is_Scalar_Type (T)))
+ or else (Consider_IS_NS and then (Is_Scalar_Type (T)))
then
return True;
@@ -8176,7 +8186,7 @@
-- expanding an aggregate (since in the latter case they will be
-- filled with appropriate initializing values before they are used).
- elsif Init_Or_Norm_Scalars
+ elsif Consider_IS_NS
and then
(Root_Type (T) = Standard_String
or else Root_Type (T) = Standard_Wide_String
===================================================================
@@ -126,14 +126,18 @@
-- then tags components located at variable positions of Target are
-- initialized.
- function Needs_Simple_Initialization (T : Entity_Id) return Boolean;
+ function Needs_Simple_Initialization
+ (T : Entity_Id;
+ Consider_IS : Boolean := True) return Boolean;
-- Certain types need initialization even though there is no specific
-- initialization routine. In this category are access types (which need
-- initializing to null), packed array types whose implementation is a
-- modular type, and all scalar types if Normalize_Scalars is set, as well
-- as private types whose underlying type is present and meets any of these
-- criteria. Finally, descendants of String and Wide_String also need
- -- initialization in Initialize/Normalize_Scalars mode.
+ -- initialization in Initialize/Normalize_Scalars mode. Consider_IS is
+ -- normally True. If it is False, the Initialize_Scalars is not considered
+ -- in determining whether simple initialization is needed.
function Get_Simple_Init_Val
(T : Entity_Id;