aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPiotr Trojanek <trojanek@adacore.com>2023-01-27 12:37:25 +0100
committerMarc Poulhiès <poulhies@adacore.com>2023-05-22 10:44:07 +0200
commit01b0a60038a91d5607e8f64d18bfa43984255632 (patch)
tree426253e24706059c404949aeb3c8fba28f6ef409
parente7f7018c2a5f07e6e8a045b6ba18c023daed7010 (diff)
downloadgcc-01b0a60038a91d5607e8f64d18bfa43984255632.zip
gcc-01b0a60038a91d5607e8f64d18bfa43984255632.tar.gz
gcc-01b0a60038a91d5607e8f64d18bfa43984255632.tar.bz2
ada: Update Controlling_Argument when copying trees
When copying the AST we need to update fields that carry semantic meaning and not just copy them. We already updated some of them, e.g. the First/Next_Named_Association chain, but failed to update the Controlling_Argument. This fix doesn't appear to change anything for the compiler, but it is needed for GNATprove, where we no longer want to expand expression functions and instead we want to copy their preanalyzed expressions. gcc/ada/ * sem_util.ads (New_Copy_Tree): Update comment. * sem_util.adb (New_Copy_Tree): Update Controlling_Argument, very much like we update the First/Next_Named_Association.
-rw-r--r--gcc/ada/sem_util.adb73
-rw-r--r--gcc/ada/sem_util.ads1
2 files changed, 70 insertions, 4 deletions
diff --git a/gcc/ada/sem_util.adb b/gcc/ada/sem_util.adb
index 9cf2195..cb0cbf2 100644
--- a/gcc/ada/sem_util.adb
+++ b/gcc/ada/sem_util.adb
@@ -23136,6 +23136,13 @@ package body Sem_Util is
pragma Inline (Update_CFS_Sloc);
-- Update the Comes_From_Source and Sloc attributes of node or entity N
+ procedure Update_Controlling_Argument
+ (Old_Call : Node_Id;
+ New_Call : Node_Id);
+ pragma Inline (Update_Controlling_Argument);
+ -- Update Controlling_Argument of New_Call base on Old_Call to make it
+ -- points to the corresponding newly copied actual parameter.
+
procedure Update_Named_Associations
(Old_Call : Node_Id;
New_Call : Node_Id);
@@ -23574,17 +23581,22 @@ package body Sem_Util is
(Old_Assoc => N,
New_Assoc => Result);
- -- Update the First/Next_Named_Association chain for a replicated
- -- call.
+ -- Update the First/Next_Named_Association chain and the
+ -- Controlling_Argument for a replicated call.
if Nkind (N) in N_Entry_Call_Statement
- | N_Function_Call
- | N_Procedure_Call_Statement
+ | N_Subprogram_Call
then
Update_Named_Associations
(Old_Call => N,
New_Call => Result);
+ if Nkind (N) in N_Subprogram_Call then
+ Update_Controlling_Argument
+ (Old_Call => N,
+ New_Call => Result);
+ end if;
+
-- Update the Renamed_Object attribute of a replicated object
-- declaration.
@@ -23694,6 +23706,59 @@ package body Sem_Util is
end if;
end Update_CFS_Sloc;
+ ---------------------------------
+ -- Update_Controlling_Argument --
+ ---------------------------------
+
+ procedure Update_Controlling_Argument
+ (Old_Call : Node_Id;
+ New_Call : Node_Id)
+ is
+ New_Act : Node_Id;
+ Old_Act : Node_Id;
+
+ Old_Ctrl_Arg : constant Node_Id := Controlling_Argument (Old_Call);
+ -- Controlling argument of the old call node
+
+ Replaced : Boolean := False;
+ -- Flag to make sure that replacement works as expected
+
+ begin
+ if No (Old_Ctrl_Arg) then
+ return;
+ end if;
+
+ -- Recreate the Controlling_Argument of a call by traversing both the
+ -- old and new actual parameters in parallel.
+
+ New_Act := First (Parameter_Associations (New_Call));
+ Old_Act := First (Parameter_Associations (Old_Call));
+ while Present (Old_Act) loop
+
+ -- Actual parameter appears either in a named parameter
+ -- association or directly.
+
+ if Nkind (Old_Act) = N_Parameter_Association then
+ if Explicit_Actual_Parameter (Old_Act) = Old_Ctrl_Arg then
+ Set_Controlling_Argument
+ (New_Call, Explicit_Actual_Parameter (New_Act));
+ Replaced := True;
+ exit;
+ end if;
+
+ elsif Old_Act = Old_Ctrl_Arg then
+ Set_Controlling_Argument (New_Call, New_Act);
+ Replaced := True;
+ exit;
+ end if;
+
+ Next (New_Act);
+ Next (Old_Act);
+ end loop;
+
+ pragma Assert (Replaced);
+ end Update_Controlling_Argument;
+
-------------------------------
-- Update_Named_Associations --
-------------------------------
diff --git a/gcc/ada/sem_util.ads b/gcc/ada/sem_util.ads
index 42c6d24..060d042 100644
--- a/gcc/ada/sem_util.ads
+++ b/gcc/ada/sem_util.ads
@@ -2646,6 +2646,7 @@ package Sem_Util is
--
-- First_Named_Actual
-- Next_Named_Actual
+ -- Controlling_Argument
--
-- If applicable, the Etype field (if any) is updated to refer to a
-- local itype or type (see below).