public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Pierre-Marie de Rodat <pmderodat@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r12-6309] [Ada] Fix regression in freezing code for instantiations
Date: Thu,  6 Jan 2022 17:14:28 +0000 (GMT)	[thread overview]
Message-ID: <20220106171428.99C37385801B@sourceware.org> (raw)

https://gcc.gnu.org/g:b542b2d97f2c574d58f6f071cdf1314ceb51587e

commit r12-6309-gb542b2d97f2c574d58f6f071cdf1314ceb51587e
Author: Eric Botcazou <ebotcazou@adacore.com>
Date:   Thu Dec 9 13:34:09 2021 +0100

    [Ada] Fix regression in freezing code for instantiations
    
    gcc/ada/
    
            * sem_ch12.adb (Insert_Freeze_Node_For_Instance): When going to
            the outer level, do not jump over following instantiations in
            the list.

Diff:
---
 gcc/ada/sem_ch12.adb | 30 +++++++++++++++++++-----------
 1 file changed, 19 insertions(+), 11 deletions(-)

diff --git a/gcc/ada/sem_ch12.adb b/gcc/ada/sem_ch12.adb
index 9010410a87f..fe55c5c20b1 100644
--- a/gcc/ada/sem_ch12.adb
+++ b/gcc/ada/sem_ch12.adb
@@ -9703,6 +9703,7 @@ package body Sem_Ch12 is
       Decl     : Node_Id;
       Decls    : List_Id;
       Inst     : Entity_Id;
+      Origin   : Entity_Id;
       Par_Inst : Node_Id;
       Par_N    : Node_Id;
 
@@ -9793,9 +9794,10 @@ package body Sem_Ch12 is
          end;
       end if;
 
-      Decl  := N;
-      Decls := List_Containing (N);
-      Par_N := Parent (Decls);
+      Decl   := N;
+      Decls  := List_Containing (N);
+      Par_N  := Parent (Decls);
+      Origin := Empty;
 
       --  Determine the proper freeze point of an instantiation
 
@@ -9824,10 +9826,13 @@ package body Sem_Ch12 is
                 not In_Same_Source_Unit (Generic_Parent (Par_Inst), Inst)
             then
                while Present (Decl) loop
-                  if (Nkind (Decl) in N_Unit_Body
+                  if ((Nkind (Decl) in N_Unit_Body
                         or else
-                      Nkind (Decl) in N_Body_Stub)
-                    and then Comes_From_Source (Decl)
+                       Nkind (Decl) in N_Body_Stub)
+                      and then Comes_From_Source (Decl))
+                    or else (Present (Origin)
+                              and then Nkind (Decl) in N_Generic_Instantiation
+                              and then Instance_Spec (Decl) /= Origin)
                   then
                      Set_Sloc (F_Node, Sloc (Decl));
                      Insert_Before (Decl, F_Node);
@@ -9851,16 +9856,19 @@ package body Sem_Ch12 is
                return;
 
             --  When the instantiation occurs in a package spec and there is
-            --  no source body which follows, not even of the package itself
-            --  then insert into the declaration list of the outer level.
+            --  no source body which follows, not even of the package itself,
+            --  then insert into the declaration list of the outer level, but
+            --  do not jump over following instantiations in this list because
+            --  they may have a body that has not materialized yet, see above.
 
             elsif Nkind (Par_N) = N_Package_Specification
               and then No (Corresponding_Body (Parent (Par_N)))
               and then Is_List_Member (Parent (Par_N))
             then
-               Decl  := Parent (Par_N);
-               Decls := List_Containing (Decl);
-               Par_N := Parent (Decls);
+               Decl   := Parent (Par_N);
+               Decls  := List_Containing (Decl);
+               Par_N  := Parent (Decls);
+               Origin := Decl;
 
             --  In a package declaration, or if no source body which follows
             --  and at library level, then insert at end of list.


                 reply	other threads:[~2022-01-06 17:14 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220106171428.99C37385801B@sourceware.org \
    --to=pmderodat@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).