+2018-10-09 Ed Schonberg <schonberg@adacore.com>
+
+ * exp_unst.adb (Unnest_Subprogram): When an uplevel reference
+ is to an unconstrained formal, the 'Access reference that is
+ created to initialize the corresponding component of the
+ activation record must be wrapped in an unchecked conversion to
+ the generated type of the component. Otherwise, spurious suvtype
+ conformance errors will be generated when the code is within an
+ instantiation and the type of the formal is a formal type of the
+ enclosing generic. Note that during unnesting there is no simple
+ way to determine that the code appears within an instance
+ because ther is no scope stack.
+
2018-10-09 Eric Botcazou <ebotcazou@adacore.com>
* gcc-interface/decl.c (type_requires_init_of_formal): New
Asn : Node_Id;
Attr : Name_Id;
+ Comp : Entity_Id;
Ins : Node_Id;
+ Rhs : Node_Id;
begin
-- For parameters, we insert the assignment
Attr := Name_Address;
end if;
+ Rhs := Make_Attribute_Reference (Loc,
+ Prefix =>
+ New_Occurrence_Of (Ent, Loc),
+ Attribute_Name => Attr);
+
+ -- If the entity is an unconstrained formal
+ -- we wrap the attribute reference in an
+ -- unchecked conversion to the type of the
+ -- activation record component, to prevent
+ -- spurious subtype conformance errors within
+ -- instances.
+
+ if Is_Formal (Ent)
+ and then not Is_Constrained (Etype (Ent))
+ then
+ -- Find target component and its type.
+
+ Comp := First_Component (STJ.ARECnT);
+ while Chars (Comp) /= Chars (Ent) loop
+ Comp := Next_Component (Comp);
+ end loop;
+
+ Rhs := Unchecked_Convert_To (
+ Etype (Comp), Rhs);
+ end if;
+
Asn :=
Make_Assignment_Statement (Loc,
Name =>
(Activation_Record_Component
(Ent),
Loc)),
-
- Expression =>
- Make_Attribute_Reference (Loc,
- Prefix =>
- New_Occurrence_Of (Ent, Loc),
- Attribute_Name => Attr));
+ Expression => Rhs);
-- If we have a loop parameter, we have
-- to insert before the first statement