From 136236bd31f5244bba8fa063c7d159c07422c018 Mon Sep 17 00:00:00 2001 From: Javier Miranda Date: Wed, 6 Jul 2016 13:14:25 +0000 Subject: [PATCH] sem_ch7.adb (Analyze_Package_Specification): Insert its freezing nodes after the last declaration. 2016-07-06 Javier Miranda * sem_ch7.adb (Analyze_Package_Specification): Insert its freezing nodes after the last declaration. Needed to ensure that global entities referenced in aspects of frozen types are properly handled. * freeze.adb (Freeze_Entity): Minor code reorganization to ensure that freezing nodes of generic packages are handled. * sem_ch13.adb (Freeze_Entity_Checks): Handle N_Freeze_Generic nodes. * sem_ch12.adb (Save_References_In_Identifier): Handle selected components which denote a named number that is constant folded in the analyzed copy of the tree. From-SVN: r238047 --- gcc/ada/ChangeLog | 13 +++++++++++++ gcc/ada/freeze.adb | 12 ++++++------ gcc/ada/sem_ch12.adb | 39 +++++++++++++++++++++++++++++++++------ gcc/ada/sem_ch13.adb | 16 +++++++++++++--- gcc/ada/sem_ch7.adb | 25 +++++++++++++++++++++++++ 5 files changed, 90 insertions(+), 15 deletions(-) diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog index 764ba8d63e7..8e8a370d0a1 100644 --- a/gcc/ada/ChangeLog +++ b/gcc/ada/ChangeLog @@ -1,3 +1,16 @@ +2016-07-06 Javier Miranda + + * sem_ch7.adb (Analyze_Package_Specification): Insert its + freezing nodes after the last declaration. Needed to ensure + that global entities referenced in aspects of frozen types are + properly handled. + * freeze.adb (Freeze_Entity): Minor code reorganization to ensure + that freezing nodes of generic packages are handled. + * sem_ch13.adb (Freeze_Entity_Checks): Handle N_Freeze_Generic nodes. + * sem_ch12.adb (Save_References_In_Identifier): Handle selected + components which denote a named number that is constant folded + in the analyzed copy of the tree. + 2016-07-06 Hristian Kirtchev * exp_aggr.adb Remove with and use clauses for Exp_Ch11 and Inline. diff --git a/gcc/ada/freeze.adb b/gcc/ada/freeze.adb index 3d6dd18e2ab..12f60a0c900 100644 --- a/gcc/ada/freeze.adb +++ b/gcc/ada/freeze.adb @@ -4945,6 +4945,12 @@ package body Freeze is Ghost_Mode := Save_Ghost_Mode; return No_List; + elsif Ekind (E) = E_Generic_Package then + Result := Freeze_Generic_Entities (E); + + Ghost_Mode := Save_Ghost_Mode; + return Result; + -- It is improper to freeze an external entity within a generic because -- its freeze node will appear in a non-valid context. The entity will -- be frozen in the proper scope after the current generic is analyzed. @@ -5054,12 +5060,6 @@ package body Freeze is return No_List; end if; end; - - elsif Ekind (E) = E_Generic_Package then - Result := Freeze_Generic_Entities (E); - - Ghost_Mode := Save_Ghost_Mode; - return Result; end if; -- Add checks to detect proper initialization of scalars that may appear diff --git a/gcc/ada/sem_ch12.adb b/gcc/ada/sem_ch12.adb index d600d277e21..d79a8453ada 100644 --- a/gcc/ada/sem_ch12.adb +++ b/gcc/ada/sem_ch12.adb @@ -14860,14 +14860,41 @@ package body Sem_Ch12 is -- The node did not undergo a transformation if Nkind (N) = Nkind (Get_Associated_Node (N)) then + declare + Aux_N2 : constant Node_Id := Get_Associated_Node (N); + Orig_N2_Parent : constant Node_Id := + Original_Node (Parent (Aux_N2)); + begin + -- The parent of this identifier is a selected component + -- which denotes a named number that was constant folded. + -- Preserve the original name for ASIS and link the parent + -- with its expanded name. The constant folding will be + -- repeated in the instance. + + if Nkind (Parent (N)) = N_Selected_Component + and then Nkind_In (Parent (Aux_N2), N_Integer_Literal, + N_Real_Literal) + and then Is_Entity_Name (Orig_N2_Parent) + and then Ekind (Entity (Orig_N2_Parent)) in Named_Kind + and then Is_Global (Entity (Orig_N2_Parent)) + then + N2 := Aux_N2; + Set_Associated_Node (Parent (N), + Original_Node (Parent (N2))); - -- If this is a discriminant reference, always save it. It is - -- used in the instance to find the corresponding discriminant - -- positionally rather than by name. + -- Common case - Set_Original_Discriminant - (N, Original_Discriminant (Get_Associated_Node (N))); - Reset_Entity (N); + else + -- If this is a discriminant reference, always save it. + -- It is used in the instance to find the corresponding + -- discriminant positionally rather than by name. + + Set_Original_Discriminant + (N, Original_Discriminant (Get_Associated_Node (N))); + end if; + + Reset_Entity (N); + end; -- The analysis of the generic copy transformed the identifier -- into another construct. Propagate the changes to the template. diff --git a/gcc/ada/sem_ch13.adb b/gcc/ada/sem_ch13.adb index ccb323325f3..aad9f68fe96 100644 --- a/gcc/ada/sem_ch13.adb +++ b/gcc/ada/sem_ch13.adb @@ -10789,10 +10789,20 @@ package body Sem_Ch13 is -- the subtype name in the saved expression so that they will not cause -- trouble in the preanalysis. - -- This is also not needed in the generic case + -- Case 1: Generic case. For freezing nodes of types defined in generics + -- we must perform the analysis of its aspects; needed to ensure that + -- they have the minimum decoration needed by ASIS. + + if not Non_Generic_Case then + if Has_Delayed_Aspects (E) then + Push_Scope (Scope (E)); + Analyze_Aspects_At_Freeze_Point (E); + Pop_Scope; + end if; + + -- Case 2: Non-generic case - if Non_Generic_Case - and then Has_Delayed_Aspects (E) + elsif Has_Delayed_Aspects (E) and then Scope (E) = Current_Scope then -- Retrieve the visibility to the discriminants in order to properly diff --git a/gcc/ada/sem_ch7.adb b/gcc/ada/sem_ch7.adb index eeb7a75612f..4a3b2de0429 100644 --- a/gcc/ada/sem_ch7.adb +++ b/gcc/ada/sem_ch7.adb @@ -39,6 +39,7 @@ with Exp_Ch7; use Exp_Ch7; with Exp_Disp; use Exp_Disp; with Exp_Dist; use Exp_Dist; with Exp_Dbug; use Exp_Dbug; +with Freeze; use Freeze; with Ghost; use Ghost; with Lib; use Lib; with Lib.Xref; use Lib.Xref; @@ -1502,7 +1503,20 @@ package body Sem_Ch7 is declare Orig_Spec : constant Node_Id := Specification (Orig_Decl); Save_Priv : constant List_Id := Private_Declarations (Orig_Spec); + begin + -- Insert the freezing nodes after the visible declarations to + -- ensure that we analyze its aspects; needed to ensure that + -- global entities referenced in the aspects are properly handled. + + if Ada_Version >= Ada_2012 + and then Is_Non_Empty_List (Vis_Decls) + and then Is_Empty_List (Priv_Decls) + then + Insert_List_After_And_Analyze + (Last (Vis_Decls), Freeze_Entity (Id, Last (Vis_Decls))); + end if; + Set_Private_Declarations (Orig_Spec, Empty_List); Save_Global_References (Orig_Decl); Set_Private_Declarations (Orig_Spec, Save_Priv); @@ -1690,6 +1704,17 @@ package body Sem_Ch7 is Generic_Formal_Declarations (Orig_Decl); begin + -- Insert the freezing nodes after the private declarations to + -- ensure that we analyze its aspects; needed to ensure that + -- global entities referenced in the aspects are properly handled. + + if Ada_Version >= Ada_2012 + and then Is_Non_Empty_List (Priv_Decls) + then + Insert_List_After_And_Analyze + (Last (Priv_Decls), Freeze_Entity (Id, Last (Priv_Decls))); + end if; + Set_Visible_Declarations (Orig_Spec, Empty_List); Set_Generic_Formal_Declarations (Orig_Decl, Empty_List); Save_Global_References (Orig_Decl); -- 2.30.2