[Ada] Use Actions field of freeze nodes for subprograms
authorEric Botcazou <ebotcazou@adacore.com>
Fri, 18 Mar 2022 23:23:39 +0000 (00:23 +0100)
committerPierre-Marie de Rodat <derodat@adacore.com>
Tue, 17 May 2022 08:25:41 +0000 (08:25 +0000)
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.

gcc/ada/exp_ch13.adb
gcc/ada/exp_ch6.adb
gcc/ada/gcc-interface/trans.cc
gcc/ada/sem_elab.adb

index d3765e2..6b6da81 100644 (file)
@@ -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
index db5ec35..c3067f1 100644 (file)
@@ -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;
index 5741986..e9701cd 100644 (file)
@@ -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
index 8e38f8c..caebb17 100644 (file)
@@ -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;