]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Fix location of pragmas coming from aspects in top-level instances
authorPiotr Trojanek <trojanek@adacore.com>
Wed, 14 Sep 2022 19:59:05 +0000 (21:59 +0200)
committerMarc Poulhiès <poulhies@adacore.com>
Mon, 26 Sep 2022 09:02:31 +0000 (11:02 +0200)
This patch fixes an AST anomaly where pragmas that correspond to aspects
of a generic package declaration appeared as the auxiliary declarations
of the compilation unit for the instantiated package body.

In particular, this anomaly happened for aspect Annotate and affected
GNATprove, which didn't pick pragma corresponding to this aspect.

gcc/ada/

* sem_ch12.adb (Build_Instance_Compilation_Unit_Nodes): Relocate
auxiliary declarations from the original compilation unit to the
newly created compilation unit for the spec.

gcc/ada/sem_ch12.adb

index 9525140b45b3552eea2663f726135bd8c221ac9e..ab2e182567986130c46e5d88360ade78bc7fbf9f 100644 (file)
@@ -6296,13 +6296,16 @@ package body Sem_Ch12 is
       Old_Main   : constant Entity_Id := Cunit_Entity (Main_Unit);
 
    begin
-      --  A new compilation unit node is built for the instance declaration
+      --  A new compilation unit node is built for the instance declaration.
+      --  It relocates the auxiliary declaration node from the compilation unit
+      --  where the instance appeared, so that declarations that originally
+      --  followed the instance will be attached to the spec compilation unit.
 
       Decl_Cunit :=
         Make_Compilation_Unit (Sloc (N),
           Context_Items  => Empty_List,
           Unit           => Act_Decl,
-          Aux_Decls_Node => Make_Compilation_Unit_Aux (Sloc (N)));
+          Aux_Decls_Node => Relocate_Node (Aux_Decls_Node (Parent (N))));
 
       Set_Parent_Spec (Act_Decl, Parent_Spec (N));