aboutsummaryrefslogtreecommitdiff
path: root/gcc/ada/exp_attr.adb
diff options
context:
space:
mode:
authorEric Botcazou <ebotcazou@adacore.com>2023-09-21 23:27:44 +0200
committerMarc Poulhiès <poulhies@adacore.com>2024-05-06 11:11:24 +0200
commit48d7a599ecd141f7936deff6170dd5199edb2d98 (patch)
tree67a547747a46db24e6bd4b4345975a4b93835d33 /gcc/ada/exp_attr.adb
parent53c32e9d7f01ee350803c9371b8630bf3e4844b7 (diff)
downloadgcc-48d7a599ecd141f7936deff6170dd5199edb2d98.zip
gcc-48d7a599ecd141f7936deff6170dd5199edb2d98.tar.gz
gcc-48d7a599ecd141f7936deff6170dd5199edb2d98.tar.bz2
ada: Partial implementation of redesign of support for object finalization
This set of changes is a partial reimplemention of the support for Ada finalization in the GNAT compiler and run-time library, based on the redesign done by Hristian Kirtchev in February 2022. It only affects the scope-based finalization of objects and does not touch the support for finalization of dynamically allocated objects. It also does not modify the internal architecture of this support in the front-end but only changes its output, i.e. the expanded code. In other words, the code-based dispatching scheme in finalizers and the hook-based approach for transient objects are replaced by finalization scope masters and master nodes, which maintain a list of objects needing finalization, but the expansion of the code that builds these masters is still performed mainly during a dedicated post-processing phase. gcc/ada/ * Makefile.rtl (GNATRTL_NONTASKING_OBJS): Add s-finpri$(objext). * contracts.adb (Add_Call_Helper): Append freeze actions to the class-wide type rather than the specific tagged type. * einfo.ads (Finalization_Master_Node_Or_Node): Document. (Status_Flag_Or_Transient_Decl): Remove. * exp_attr.adb (Expand_N_Attribute_Reference) <Address>: Do not adjust a return object of a class-wide interface type. * exp_ch3.adb (Expand_Freeze_Class_Wide_Type): Add test that Finalize_Address is not already present as a condition for calling Make_Finalize_Address_Body. (Expand_Freeze_Record_Type): Call Make_Finalize_Address_Body for class-wide types of both regular tagged types and interface types. * exp_ch4.adb (Process_Transients_In_Expression): Replace the use of hooks with the use of master nodes. * exp_ch6.adb (Build_Flag_For_Function): Delete. (Expand_N_Extended_Return_Statement): Create a master node for the return object if it does not exist. At the end of the statement, generate a call to Suppress_Object_Finalize. (Expand_Non_Function_Return): Likewise just before the return. * exp_ch7.ads (Make_Master_Node_Declaration): Declare. (Make_Suppress_Object_Finalize_Call): Likewise. * exp_ch7.adb (Build_Finalization_Master): Defer generating the call to Set_Finalize_Address until freezing if the Finalize_Address procedure has not been analyzed yet. (Build_Finalizer): Reimplement the expansion using a finalization scope master per finalizer. (Insert_Actions_In_Scope_Around): Replace finalization hooks by master nodes and calls to the Finalize_Object. (Make_Master_Node_Declaration): New procedure. (Make_Suppress_Object_Finalize_Call): Likewise. * exp_util.ads (Build_Transient_Object_Statements): Delete. * exp_util.adb (Build_Transient_Object_Statements): Likewise. (Requires_Cleanup_Actions): Remove obsolete code and return true for master nodes. * gen_il-fields.ads (Opt_Field_Enum): Add Finalization_Master_Node_Or_Object and remove Status_Flag_Or_Transient_Decl. * gen_il-gen-gen_entities.adb (Allocatable_Kind): Likewise. * rtsfind.ads (RTU_Id): Add System_Finalization_Primitives. (RE_Id): Add entities of System_Finalization_Primitives. (RE_Unit_Table): Add entries for them. * sem_ch3.adb (Analyze_Object_Declaration): For an array whose type has an unconstrained first subtype and a controlled component, set the Is_Constr_Array_Subt_With_Bounds flag. * libgnat/s-finpri.ads: New file. * libgnat/s-finpri.adb: Likewise.
Diffstat (limited to 'gcc/ada/exp_attr.adb')
-rw-r--r--gcc/ada/exp_attr.adb7
1 files changed, 4 insertions, 3 deletions
diff --git a/gcc/ada/exp_attr.adb b/gcc/ada/exp_attr.adb
index 8f32dc2..614f1fb 100644
--- a/gcc/ada/exp_attr.adb
+++ b/gcc/ada/exp_attr.adb
@@ -2701,13 +2701,14 @@ package body Exp_Attr is
-- activation record object where the component corresponds to
-- prefix of the attribute (for back ends that require "unnesting"
-- of nested subprograms), since the address needs to be assigned
- -- as-is to such components.
+ -- as-is to such components. Likewise for a return object.
elsif Tagged_Type_Expansion
and then Is_Class_Wide_Type (Ptyp)
and then Is_Interface (Underlying_Type (Ptyp))
- and then not (Nkind (Pref) in N_Has_Entity
- and then Is_Subprogram (Entity (Pref)))
+ and then not (Is_Entity_Name (Pref)
+ and then (Is_Subprogram (Entity (Pref))
+ or else Is_Return_Object (Entity (Pref))))
and then not Is_Unnested_Component_Init (N)
then
Rewrite (N,