aboutsummaryrefslogtreecommitdiff
path: root/gcc/ada/exp_ch3.adb
diff options
context:
space:
mode:
authorEric Botcazou <ebotcazou@adacore.com>2024-12-02 21:58:29 +0100
committerMarc Poulhiès <dkm@gcc.gnu.org>2025-01-03 16:39:11 +0100
commit1e3619a37aebd8005c8505aebded7957b661577c (patch)
tree89587954aa9afe8e573c1b84a420c75a3ff73662 /gcc/ada/exp_ch3.adb
parentd9ba2b857eb39ab52b1e2f93246af444e837dce4 (diff)
downloadgcc-1e3619a37aebd8005c8505aebded7957b661577c.zip
gcc-1e3619a37aebd8005c8505aebded7957b661577c.tar.gz
gcc-1e3619a37aebd8005c8505aebded7957b661577c.tar.bz2
ada: Improve expansion of conditional expressions in object declarations
This arranges for conditional expressions in objects declarations to have their expansion delayed when they have a type that cannot be easily copied or copied at all, including limited and controlled types. The ultimate goal is to replace the declaration with a renaming declaration of the dereference of an access value designating an object initialized with the dependent expression chosen by the condition. gcc/ada/ChangeLog: * einfo.ads (Is_Independent): Document usage on Master_Node objects. * exp_aggr.adb (In_Place_Assign_OK): Remove Parent_Kind variable. (Convert_To_Assignments): Call Unconditional_Parent and remove the restriction on the known size for the in-place expansion of the aggregate in the context of an object declaration. (Expand_Array_Aggregate): Remove Parent_Kind variable and call Unconditional_Parent and Delay_Conditional_Expressions_Between * exp_ch3.adb: Remove clauses for Exp_Dbug. (Expand_N_Object_Declaration): Factor out the code rewriting the declaration as a renaming in Rewrite_Object_Declaration_As_Renaming and call the procedure. * exp_ch4.adb (Insert_Conditional_Object_Declaration): Declare. (Expand_N_Case_Expression): Delay expanding the expression if it is in the context of an optimizable object declaration. If the parent node is this object declaration, then replace it with a renaming of the dereference of an access value designating an object initialized with the dependent expression chosen by the condition. (Expand_N_If_Expression): Likewise. (Insert_Conditional_Object_Declaration): New procedure. * exp_ch6.adb (Expand_Ctrl_Function_Call): Test the unconditional parent in the case of an object declaration too. * exp_ch7.adb (Build_Finalizer.Process_Declarations): Pass Strict to Processing_Actions from the Is_Independent flag on a Master_Node. * exp_util.ads (Rewrite_Object_Declaration_As_Renaming): Declare. * exp_util.adb: Add clauses for Exp_Dbug. (Rewrite_Object_Declaration_As_Renaming): New procedure extracted from Expand_N_Object_Declaration. * sem_ch3.adb (Analyze_Object_Declaration): Also leave the analysis if the declaration has been replaced with a renaming in the case of an initialization expression that is a conditional expression.
Diffstat (limited to 'gcc/ada/exp_ch3.adb')
-rw-r--r--gcc/ada/exp_ch3.adb31
1 files changed, 1 insertions, 30 deletions
diff --git a/gcc/ada/exp_ch3.adb b/gcc/ada/exp_ch3.adb
index 2a0b0e6..afcb0a9 100644
--- a/gcc/ada/exp_ch3.adb
+++ b/gcc/ada/exp_ch3.adb
@@ -38,7 +38,6 @@ with Exp_Ch4; use Exp_Ch4;
with Exp_Ch6; use Exp_Ch6;
with Exp_Ch7; use Exp_Ch7;
with Exp_Ch9; use Exp_Ch9;
-with Exp_Dbug; use Exp_Dbug;
with Exp_Disp; use Exp_Disp;
with Exp_Dist; use Exp_Dist;
with Exp_Put_Image;
@@ -9134,35 +9133,7 @@ package body Exp_Ch3 is
-- illegal code if written by hand, but that's OK.
if Rewrite_As_Renaming then
- Rewrite (N,
- Make_Object_Renaming_Declaration (Loc,
- Defining_Identifier => Def_Id,
- Subtype_Mark => New_Occurrence_Of (Etype (Def_Id), Loc),
- Name => Expr_Q));
-
- -- Keep original aspects
-
- Move_Aspects (Original_Node (N), N);
-
- -- We do not analyze this renaming declaration, because all its
- -- components have already been analyzed, and if we were to go
- -- ahead and analyze it, we would in effect be trying to generate
- -- another declaration of X, which won't do.
-
- Set_Renamed_Object (Def_Id, Expr_Q);
- Set_Analyzed (N);
-
- -- We do need to deal with debug issues for this renaming
-
- -- First, if entity comes from source, then mark it as needing
- -- debug information, even though it is defined by a generated
- -- renaming that does not come from source.
-
- Set_Debug_Info_Defining_Id (N);
-
- -- Now call the routine to generate debug info for the renaming
-
- Insert_Action (N, Debug_Renaming_Declaration (N));
+ Rewrite_Object_Declaration_As_Renaming (N, Expr_Q);
end if;
-- Exception on library entity not available