Commit 9e25affd by Ed Schonberg Committed by Pierre-Marie de Rodat

[Ada] Unnesting: fix handling of uplevel refs to unconstrained formals

2018-10-09  Ed Schonberg  <schonberg@adacore.com>

gcc/ada/

	* 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.

From-SVN: r264972
parent 8dcefdc0
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
......
......@@ -1966,7 +1966,9 @@ package body Exp_Unst is
Asn : Node_Id;
Attr : Name_Id;
Comp : Entity_Id;
Ins : Node_Id;
Rhs : Node_Id;
begin
-- For parameters, we insert the assignment
......@@ -2001,6 +2003,32 @@ package body Exp_Unst is
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 =>
......@@ -2012,12 +2040,7 @@ package body Exp_Unst is
(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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment