Commit ef8f9700 by Ed Schonberg Committed by Pierre-Marie de Rodat

[Ada] Unnesting: fix handling of up level refs for entries

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

gcc/ada/

	* exp_unst.adb: Fix handling of up level references for entries.

From-SVN: r264603
parent 33d25517
2018-09-26 Ed Schonberg <schonberg@adacore.com> 2018-09-26 Ed Schonberg <schonberg@adacore.com>
* exp_unst.adb: Fix handling of up level references for entries.
2018-09-26 Ed Schonberg <schonberg@adacore.com>
* contracts.adb (Expand_Subprogram_Contract, * contracts.adb (Expand_Subprogram_Contract,
Process_Preconditions_For): Apply Freeze_Expr_Types to the Process_Preconditions_For): Apply Freeze_Expr_Types to the
expression for a precondition of an expression function that is expression for a precondition of an expression function that is
......
...@@ -260,8 +260,8 @@ package body Exp_Unst is ...@@ -260,8 +260,8 @@ package body Exp_Unst is
E := Ultimate_Alias (E); E := Ultimate_Alias (E);
-- The body of a protected operation has a different name and -- The body of a protected operation has a different name and
-- has been scanned at this point, and thus has an entry in the -- has been scanned at this point, and thus has an entry in
-- subprogram table. -- the subprogram table.
if E = Sub and then Convention (E) = Convention_Protected then if E = Sub and then Convention (E) = Convention_Protected then
E := Protected_Body_Subprogram (E); E := Protected_Body_Subprogram (E);
...@@ -535,6 +535,29 @@ package body Exp_Unst is ...@@ -535,6 +535,29 @@ package body Exp_Unst is
end loop; end loop;
end; end;
-- The type of the prefix may be have an uplevel
-- reference if this needs bounds.
if Nkind (N) = N_Attribute_Reference then
declare
Attr : constant Attribute_Id :=
Get_Attribute_Id (Attribute_Name (N));
begin
if (Attr = Attribute_First
or else Attr = Attribute_Last
or else Attr = Attribute_Length)
and then Is_Constrained (Etype (Prefix (N)))
then
declare
DT : Boolean := False;
begin
Check_Static_Type
(Etype (Prefix (N)), Empty, DT);
end;
end if;
end;
end if;
-- Binary operator cases. These can apply to arrays for -- Binary operator cases. These can apply to arrays for
-- which we may need bounds. -- which we may need bounds.
...@@ -699,6 +722,9 @@ package body Exp_Unst is ...@@ -699,6 +722,9 @@ package body Exp_Unst is
and then Corresponding_Procedure (Callee) = Caller and then Corresponding_Procedure (Callee) = Caller
then then
return; return;
elsif Ekind_In (Callee, E_Entry, E_Entry_Family) then
return;
end if; end if;
-- We have a new uplevel referenced entity -- We have a new uplevel referenced entity
...@@ -748,6 +774,22 @@ package body Exp_Unst is ...@@ -748,6 +774,22 @@ package body Exp_Unst is
ARECnU => Empty)); ARECnU => Empty));
Set_Subps_Index (E, UI_From_Int (Subps.Last)); Set_Subps_Index (E, UI_From_Int (Subps.Last));
-- If we marked this reachable because it's in a synchronized
-- unit, we have to mark all enclosing subprograms as reachable
-- as well.
if In_Synchronized_Unit (E) then
declare
S : Entity_Id := E;
begin
for J in reverse 1 .. L - 1 loop
S := Enclosing_Subprogram (S);
Subps.Table (Subp_Index (S)).Reachable := True;
end loop;
end;
end if;
end Register_Subprogram; end Register_Subprogram;
-- Start of processing for Visit_Node -- Start of processing for Visit_Node
...@@ -1109,12 +1151,24 @@ package body Exp_Unst is ...@@ -1109,12 +1151,24 @@ package body Exp_Unst is
end if; end if;
-- Pragmas and component declarations can be ignored -- Pragmas and component declarations can be ignored
-- Quantified expressions are expanded into explicit loops
-- and the original epression must be ignored.
when N_Component_Declaration when N_Component_Declaration
| N_Pragma | N_Pragma
| N_Quantified_Expression
=> =>
return Skip; return Skip;
-- We want to skip the function spec for a generic function
-- to avoid looking at any generic types that might be in
-- its formals.
when N_Function_Specification =>
if Is_Generic_Subprogram (Unique_Defining_Entity (N)) then
return Skip;
end if;
-- Otherwise record an uplevel reference in a local identifier -- Otherwise record an uplevel reference in a local identifier
when others => when others =>
...@@ -1965,13 +2019,26 @@ package body Exp_Unst is ...@@ -1965,13 +2019,26 @@ package body Exp_Unst is
-- If we have a loop parameter, we have -- If we have a loop parameter, we have
-- to insert before the first statement -- to insert before the first statement
-- of the loop. Ins points to the -- of the loop. Ins points to the
-- N_Loop_Parameter_Specification. -- N_Loop_Parameter_Specification or to
-- an N_Iterator_Specification.
if Ekind (Ent) = E_Loop_Parameter then
Ins := if Nkind_In (Ins, N_Iterator_Specification,
First N_Loop_Parameter_Specification)
(Statements (Parent (Parent (Ins)))); then
Insert_Before (Ins, Asn); -- Quantified expression are rewrittne
-- as loops during expansion.
if Nkind (Parent (Ins)) =
N_Quantified_Expression
then
null;
else
Ins :=
First
(Statements (Parent (Parent (Ins))));
Insert_Before (Ins, Asn);
end if;
else else
Insert_After (Ins, Asn); Insert_After (Ins, Asn);
...@@ -2369,6 +2436,13 @@ package body Exp_Unst is ...@@ -2369,6 +2436,13 @@ package body Exp_Unst is
elsif Nkind (N) in N_Body_Stub then elsif Nkind (N) in N_Body_Stub then
Do_Search (Library_Unit (N)); Do_Search (Library_Unit (N));
-- Skip generic packages
elsif Nkind (N) = N_Package_Body
and then Ekind (Corresponding_Spec (N)) = E_Generic_Package
then
return Skip;
end if; end if;
return OK; return OK;
......
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