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 r13-524] [Ada] Use Actions field of freeze nodes for subprograms
Date: Tue, 17 May 2022 08:27:42 +0000 (GMT)	[thread overview]
Message-ID: <20220517082742.ADF5F3857402@sourceware.org> (raw)

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

commit r13-524-gd4090614041c7803373a5064dfb82fdf6017971d
Author: Eric Botcazou <ebotcazou@adacore.com>
Date:   Sat Mar 19 00:23:39 2022 +0100

    [Ada] Use Actions field of freeze nodes for subprograms
    
    This has a couple of advantages: 1) the actions are analyzed with checks
    disabled and 2) they are considered elaboration code by Sem_Elab.
    
    gcc/ada/
    
            * exp_ch13.adb (Expand_N_Freeze_Entity): Delete freeze nodes for
            subprograms only if they have no actions.
            * exp_ch6.adb (Freeze_Subprogram): Put the actions into the Actions
            field of the freeze node instead of inserting them after it.
            * sem_elab.adb (Is_SPARK_Semantic_Target): Fix typo in comment.
            * gcc-interface/trans.cc (process_freeze_entity): Return early for
            freeze nodes of subprograms with Interface_Alias set.

Diff:
---
 gcc/ada/exp_ch13.adb           | 14 ++++++--------
 gcc/ada/exp_ch6.adb            | 15 +++++++++++++--
 gcc/ada/gcc-interface/trans.cc |  5 +++++
 gcc/ada/sem_elab.adb           |  2 +-
 4 files changed, 25 insertions(+), 11 deletions(-)

diff --git a/gcc/ada/exp_ch13.adb b/gcc/ada/exp_ch13.adb
index d3765e25543..6b6da818387 100644
--- a/gcc/ada/exp_ch13.adb
+++ b/gcc/ada/exp_ch13.adb
@@ -617,14 +617,12 @@ package body Exp_Ch13 is
       elsif Is_Subprogram (E) then
          Exp_Ch6.Freeze_Subprogram (N);
 
-         --  Ada 2005 (AI-251): Remove the freezing node associated with the
-         --  entities internally used by the frontend to register primitives
-         --  covering abstract interfaces. The call to Freeze_Subprogram has
-         --  already expanded the code that fills the corresponding entry in
-         --  its secondary dispatch table and therefore the code generator
-         --  has nothing else to do with this freezing node.
-
-         Delete := Present (Interface_Alias (E));
+         --  Ada 2005 (AI-251): Remove the freeze nodes associated with the
+         --  entities internally used by the front end to register primitives
+         --  covering abstract interfaces if they have no side effects. For the
+         --  others, gigi must discard them after evaluating the side effects.
+
+         Delete := Present (Interface_Alias (E)) and then No (Actions (N));
       end if;
 
       --  Analyze actions generated by freezing. The init_proc contains source
diff --git a/gcc/ada/exp_ch6.adb b/gcc/ada/exp_ch6.adb
index db5ec357bea..c3067f1a9c4 100644
--- a/gcc/ada/exp_ch6.adb
+++ b/gcc/ada/exp_ch6.adb
@@ -7856,6 +7856,8 @@ package body Exp_Ch6 is
          declare
             Typ : constant Entity_Id := Scope (DTC_Entity (Subp));
 
+            L : List_Id;
+
          begin
             --  Handle private overridden primitives
 
@@ -7895,8 +7897,17 @@ package body Exp_Ch6 is
                      Register_Predefined_DT_Entry (Subp);
                   end if;
 
-                  Insert_Actions_After (N,
-                    Register_Primitive (Loc, Prim => Subp));
+                  L := Register_Primitive (Loc, Prim => Subp);
+
+                  if Is_Empty_List (L) then
+                     null;
+
+                  elsif No (Actions (N)) then
+                     Set_Actions (N, L);
+
+                  else
+                     Append_List (L, Actions (N));
+                  end if;
                end if;
             end if;
          end;
diff --git a/gcc/ada/gcc-interface/trans.cc b/gcc/ada/gcc-interface/trans.cc
index 57419861838..e9701cdf72f 100644
--- a/gcc/ada/gcc-interface/trans.cc
+++ b/gcc/ada/gcc-interface/trans.cc
@@ -9045,6 +9045,11 @@ process_freeze_entity (Node_Id gnat_node)
   if (kind == E_Class_Wide_Type)
     return;
 
+  /* Likewise for the entities internally used by the front-end to register
+     primitives covering abstract interfaces, see Expand_N_Freeze_Entity.  */
+  if (Is_Subprogram (gnat_entity) && Present (Interface_Alias (gnat_entity)))
+    return;
+
   /* Check for an old definition if this isn't an object with address clause,
      since the saved GCC tree is the address expression in that case.  */
   gnu_old
diff --git a/gcc/ada/sem_elab.adb b/gcc/ada/sem_elab.adb
index 8e38f8c1285..caebb174577 100644
--- a/gcc/ada/sem_elab.adb
+++ b/gcc/ada/sem_elab.adb
@@ -1845,7 +1845,7 @@ package body Sem_Elab is
 
       function Is_SPARK_Semantic_Target (Id : Entity_Id) return Boolean;
       pragma Inline (Is_SPARK_Semantic_Target);
-      --  Determine whether arbitrary entity Id nodes a source or internally
+      --  Determine whether arbitrary entity Id denotes a source or internally
       --  generated subprogram which emulates SPARK semantics.
 
       function Is_Subprogram_Inst (Id : Entity_Id) return Boolean;


                 reply	other threads:[~2022-05-17  8:27 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=20220517082742.ADF5F3857402@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).