aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Botcazou <ebotcazou@adacore.com>2022-03-19 00:23:39 +0100
committerPierre-Marie de Rodat <derodat@adacore.com>2022-05-17 08:25:41 +0000
commitd4090614041c7803373a5064dfb82fdf6017971d (patch)
treee31236cc5772f6f5521aa8c2635a1a3f220d8450
parenta08f366ae875ae70fba5014c94956cdbf7bf91db (diff)
[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.
-rw-r--r--gcc/ada/exp_ch13.adb14
-rw-r--r--gcc/ada/exp_ch6.adb15
-rw-r--r--gcc/ada/gcc-interface/trans.cc5
-rw-r--r--gcc/ada/sem_elab.adb2
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;