aboutsummaryrefslogtreecommitdiff
path: root/gcc/ada/sinfo.ads
diff options
context:
space:
mode:
authorEric Botcazou <ebotcazou@adacore.com>2023-04-24 20:50:39 +0200
committerMarc Poulhiès <poulhies@adacore.com>2023-06-13 09:31:44 +0200
commitc0ceba6c86ae4fcefa720b0976c58481c903eb63 (patch)
tree7df9602c5b5fc8db67f4ccd448d2fae4b66f443e /gcc/ada/sinfo.ads
parent44eb2bbdcef264661ded3710cc58269f6f33fa93 (diff)
downloadgcc-c0ceba6c86ae4fcefa720b0976c58481c903eb63.zip
gcc-c0ceba6c86ae4fcefa720b0976c58481c903eb63.tar.gz
gcc-c0ceba6c86ae4fcefa720b0976c58481c903eb63.tar.bz2
ada: Streamline expansion of controlled actions for aggregates
This changes the strategy used to expand controlled actions for array and record aggregates so as to make it simpler and more robust. The current strategy is to set the No_Ctrl_Actions flag on the assignments generated during the expansion of aggregate, as done during the expansion of initialization procedures, and to generate the adjustments of the LHS manually in the same list of actions, before sending the entire list for analysis and expansion. The problem is that, when the RHS also requires controlled actions, the No_Ctrl_Actions flag prevents transient scopes from being created around the assignments, with the end result that the actions are "naturally" generated between the assignments and adjustments of the LHS, causing premature finalization of the RHS. In order to counter that, the controlled actions of the RHS must also be generated manually during the expansion of the aggregates, after blocking normal processing e.g. by means of the No_Side_Effect_Removal flag. This means that, for a more complex RHS, this strategy generates a wrong order of controlled actions by default, until specifically adjusted. The new strategy is to reuse the standard machinery as much as possible, disabling only the part that is not needed for the assignments generated during the expansion of aggregates, namely the finalization of the LHS; in other words, the adjustment of the LHS is left entirely to the standard machinery and the creation of transient scopes is no longer blocked, which gives a correct order of controlled actions by default. It is implemented by means of a No_Finalize_Actions flag present on the assignments generated during the expansion. It is mostly straightforward, modulo the following hitch: the assignments are now analyzed and expanded by the common expander, which in the case of controlled assignments analyzes the final rewriting with all checks off, which in particular disables elaboration checks for the calls to the Adjust primitives; now these checks are necessary in the case where an aggregate is the initialization expression of an object declared before the body of the Adjust primitive is seen. Hence the use of an existing trick, namely Suppress/Unsuppress blocks, around the assignments. gcc/ada/ * gen_il-fields.ads (Opt_Field_Enum): Add No_Finalize_Actions and remove No_Side_Effect_Removal. * gen_il-gen-gen_nodes.adb (N_Function_Call): Remove semantic flag No_Side_Effect_Removal (N_Assignment_Statement): Add semantic flag No_Finalize_Actions. * sinfo.ads (No_Ctrl_Actions): Adjust comment. (No_Finalize_Actions): New flag on assignment statements. (No_Side_Effect_Removal): Delete. * exp_aggr.adb (Build_Record_Aggr_Code): Remove obsolete comment and Ancestor_Is_Expression variable. In the case of an extension, do not generate a call to Adjust manually, call Set_No_Finalize_Actions instead. Do not set the tags, replace call to Make_Unsuppress_Block by Make_Suppress_Block and remove useless assertions. In the general case, call Initialize_Component. (Initialize_Controlled_Component): Delete. (Initialize_Simple_Component): Delete. (Initialize_Component): Do the low-level processing, but do not generate a call to Adjust manually, call Set_No_Finalize_Actions. (Process_Transient_Component): Delete. (Process_Transient_Component_Completion): Likewise. * exp_ch5.adb (Expand_Assign_Array): Deal with No_Finalize_Actions. (Expand_Assign_Array_Loop): Likewise. (Expand_N_Assignment_Statement): Likewise. (Make_Tag_Ctrl_Assignment): Likewise. * exp_util.adb (Remove_Side_Effects): Do not test the No_Side_Effect_Removal flag. * sem_prag.adb (Process_Suppress_Unsuppress): Give the warning in SPARK mode only for pragma Suppress. * tbuild.ads (Make_Suppress_Block): New declaration. (Make_Unsuppress_Block): Adjust comment. * tbuild.adb (Make_Suppress_Block): New procedure. (Make_Unsuppress_Block): Unsuppress instead of suppressing.
Diffstat (limited to 'gcc/ada/sinfo.ads')
-rw-r--r--gcc/ada/sinfo.ads31
1 files changed, 18 insertions, 13 deletions
diff --git a/gcc/ada/sinfo.ads b/gcc/ada/sinfo.ads
index 0f698cd..b565221 100644
--- a/gcc/ada/sinfo.ads
+++ b/gcc/ada/sinfo.ads
@@ -2067,12 +2067,14 @@ package Sinfo is
-- is undefined and should not be read).
-- No_Ctrl_Actions
- -- Present in N_Assignment_Statement to indicate that no Finalize nor
- -- Adjust should take place on this assignment even though the RHS is
- -- controlled. Also indicates that the primitive _assign should not be
- -- used for a tagged assignment. This is used in init procs and aggregate
- -- expansions where the generated assignments are initializations, not
- -- real assignments.
+ -- Present in N_Assignment_Statement to indicate that neither Finalize
+ -- nor Adjust should take place on this assignment even though the LHS
+ -- and RHS are controlled. Also to indicate that the primitive _assign
+ -- should not be used for a tagged assignment. This flag is used in init
+ -- proc and aggregate expansion where the generated assignments are
+ -- initializations, not real assignments. Note that it also suppresses
+ -- the creation of transient scopes around the N_Assignment_Statement,
+ -- in other words it disables all controlled actions for the assignment.
-- No_Elaboration_Check
-- NOTE: this flag is relevant only for the legacy ABE mechanism and
@@ -2092,6 +2094,15 @@ package Sinfo is
-- to generate the proper message (see Sem_Util.Check_Unused_Withs for
-- full details).
+ -- No_Finalize_Actions
+ -- Present in N_Assignment_Statement to indicate that no Finalize should
+ -- take place on this assignment even though the LHS is controlled. Also
+ -- to indicate that the primitive _assign should not be used for a tagged
+ -- assignment. This flag is only used in aggregates expansion where the
+ -- generated assignments are initializations, not real assignments. Note
+ -- that, unlike the No_Ctrl_Actions flag, it does *not* suppress the
+ -- creation of transient scopes around the N_Assignment_Statement.
+
-- No_Initialization
-- Present in N_Object_Declaration and N_Allocator to indicate that the
-- object must not be initialized (by Initialize or call to an init
@@ -2106,12 +2117,6 @@ package Sinfo is
-- It is used to indicate that processing for extended overflow checking
-- modes is not required (this is used to prevent infinite recursion).
- -- No_Side_Effect_Removal
- -- Present in N_Function_Call nodes. Set when a function call does not
- -- require side effect removal. This attribute suppresses the generation
- -- of a temporary to capture the result of the function which eventually
- -- replaces the function call.
-
-- No_Truncation
-- Present in N_Unchecked_Type_Conversion node. This flag has an effect
-- only if the RM_Size of the source is greater than the RM_Size of the
@@ -4934,6 +4939,7 @@ package Sinfo is
-- Forwards_OK
-- Backwards_OK
-- No_Ctrl_Actions
+ -- No_Finalize_Actions
-- Has_Target_Names
-- Is_Elaboration_Code
-- Componentwise_Assignment
@@ -5560,7 +5566,6 @@ package Sinfo is
-- Is_Elaboration_Warnings_OK_Node
-- No_Elaboration_Check
-- Is_Expanded_Build_In_Place_Call
- -- No_Side_Effect_Removal
-- Is_Known_Guaranteed_ABE
-- plus fields for expression