[gcc r13-7866] ada: Fix spurious error on nested instantiations with generic renaming

Eric Botcazou ebotcazou@gcc.gnu.org
Wed Sep 27 08:25:06 GMT 2023


https://gcc.gnu.org/g:171a74d56d58cd6c8daf948b640ba85f5c153af9

commit r13-7866-g171a74d56d58cd6c8daf948b640ba85f5c153af9
Author: Eric Botcazou <ebotcazou@adacore.com>
Date:   Sat Apr 1 21:57:21 2023 +0200

    ada: Fix spurious error on nested instantiations with generic renaming
    
    The problem is that the renaming slightly changes the form of a global
    reference that was saved during the analysis of a generic package, and
    that is sufficient to fool the code adjusting global references during
    the instantiation.
    
    gcc/ada/
    
            * sem_ch12.adb (Copy_Generic_Node): Test the original node kind
            for the sake of consistency.  For identifiers and other entity
            names and operators, accept an expanded name as associated node.
            Replace "or" with "or else" in condtion and fix its formatting.

Diff:
---
 gcc/ada/sem_ch12.adb | 27 ++++++++++++++++++---------
 1 file changed, 18 insertions(+), 9 deletions(-)

diff --git a/gcc/ada/sem_ch12.adb b/gcc/ada/sem_ch12.adb
index c1d3d953111..16850d0e426 100644
--- a/gcc/ada/sem_ch12.adb
+++ b/gcc/ada/sem_ch12.adb
@@ -7966,11 +7966,11 @@ package body Sem_Ch12 is
 
       --  Special casing for identifiers and other entity names and operators
 
-      if Nkind (New_N) in N_Character_Literal
-                        | N_Expanded_Name
-                        | N_Identifier
-                        | N_Operator_Symbol
-                        | N_Op
+      if Nkind (N) in N_Character_Literal
+                    | N_Expanded_Name
+                    | N_Identifier
+                    | N_Operator_Symbol
+                    | N_Op
       then
          if not Instantiating then
 
@@ -8174,6 +8174,15 @@ package body Sem_Ch12 is
                   then
                      Set_Entity (New_N, Assoc);
 
+                  --  Cope with the rewriting into expanded name that may have
+                  --  occurred in between, e.g. in Check_Generic_Child_Unit for
+                  --  generic renaming declarations.
+
+                  elsif Nkind (Assoc) = N_Expanded_Name then
+                     Rewrite (N, New_Copy_Tree (Assoc));
+                     Set_Associated_Node (N, Assoc);
+                     return Copy_Generic_Node (N, Parent_Id, Instantiating);
+
                   --  The name in the call may be a selected component if the
                   --  call has not been analyzed yet, as may be the case for
                   --  pre/post conditions in a generic unit.
@@ -8184,10 +8193,10 @@ package body Sem_Ch12 is
                      Set_Entity (New_N, Entity (Name (Assoc)));
 
                   elsif Nkind (Assoc) in N_Entity
-                    and then (Expander_Active or
-                                (GNATprove_Mode
-                                  and then not In_Spec_Expression
-                                  and then not Inside_A_Generic))
+                    and then (Expander_Active
+                               or else (GNATprove_Mode
+                                         and then not In_Spec_Expression
+                                         and then not Inside_A_Generic))
                   then
                      --  Inlining case: we are copying a tree that contains
                      --  global entities, which are preserved in the copy to be


More information about the Gcc-cvs mailing list