aboutsummaryrefslogtreecommitdiff
path: root/gcc/ada/exp_ch4.adb
AgeCommit message (Collapse)AuthorFilesLines
2024-08-23ada: Fix style in lines starting with assignment operatorPiotr Trojanek1-8/+8
Style cleanup; semantics is unaffected. Offending occurrences found with grep "^ *:=" and fixed manually. gcc/ada/ * checks.ads, cstand.adb, exp_aggr.adb, exp_ch4.adb, exp_ch5.adb, exp_dbug.adb, exp_util.adb, gnatlink.adb, lib-util.adb, libgnat/a-except.adb, libgnat/a-exexpr.adb, libgnat/a-ngcoar.adb, libgnat/s-rannum.adb, libgnat/s-trasym__dwarf.adb, osint.adb, rtsfind.adb, sem_case.adb, sem_ch12.adb, sem_ch13.adb, sem_ch3.adb, sem_ch6.adb, sem_eval.adb, sem_prag.adb, sem_util.adb: Fix style.
2024-08-08ada: Etype missing for raise expressionSteve Baird1-2/+5
If the primitive equality operator of the component type of an array type is abstract, then a call to that abstract function raises Program_Error (when such a call is legal). The FE generates a raise expression to implement this. That raise expression is an expression so it should have a valid Etype. gcc/ada/ * exp_ch4.adb (Build_Eq_Call): In the abstract callee case, copy the Etype of the callee onto the Make_Raise_Program_Error result.
2024-08-02ada: Remove unreferenced procedureRichard Kenner1-43/+0
gcc/ada/ * exp_ch4.adb (Generate_Temporary): Remove unused procedure.
2024-08-01ada: Implement full relaxed finalization semantics for controlled objectsEric Botcazou1-5/+1
These semantics state that the compiler is permitted to enforce none of the guarantees specified by the RM 7.6.1(14/1) and following subclauses, and to instead just let the exception be propagated upward. The guarantees impose a significant overhead in terms of complexity and run-time performance compared to similar constructs in other languages, and the goal is to reduce it significantly, if not eliminate it totally: for example, untagged record types declared with the Finalizable aspect, the relaxed finalization semantics and inline Initialize/Adjust/Finalize primitives, and used with abort disabled: pragma Restrictions (No_Abort_Statements); pragma Restrictions (Max_Asynchronous_Select_Nesting => 0); pragma Restrictions (No_Asynchronous_Control); should behave like simple C++ classes. The implementation morally boils down to undoing the changes made a few months ago to the support of finalization for controlled objects, i.e. to getting rid of the added linked list and the associated indirection for controlled objects with relaxed finalization semantics. But, in order to keep a unified processing for both kinds of controlled objects and not to bring back the issues addressed by the aforementioned changes, the work is split between the front-end and the code generator: the front-end drops the linked list and the code generator is in charge of eliminating the indirection with the help of the optimizer. gcc/ada/ * doc/gnat_rm/gnat_language_extensions.rst (Generalized Finalization): Update status. * einfo.ads (Has_Relaxed_Finalization): Add more details. * exp_ch4.adb (Process_Transients_In_Expression): Invoke Make_Finalize_Call_For_Node instead of building the call. * exp_ch5.adb (Expand_N_Assignment_Statement): Do not set up an exception handler around the assignment for a controlled type with relaxed finalization semantics. Streamline the code implementing the protection against aborts and do not use an At_End handler for a controlled type with relaxed finalization semantics. * exp_ch7.ads (Make_Finalize_Call_For_Node): New function. * exp_ch7.adb (Finalize_Address_For_Node): New function renaming. (Set_Finalize_Address_For_Node): New procedure renaming. (Attach_Object_To_Master_Node): Also attach the Finalize_Address primitive to the Master_Node statically. (Build_Finalizer): Add Has_Strict_Ctrl_Objs local variable. Insert back the body of the finalizer at the end of the statement list in the non-package case and restore the associated support code to that effect. When all the controlled objects have the relaxed finalization semantics, do not create a Finalization_Master and finalize the objects directly instead. (Processing_Actions): Add Strict parameter and use it to set the Has_Strict_Ctrl_Objs variable. (Process_Declarations): Make main loop more robust and adjust calls to Processing_Actions. (Make_Finalize_Address_Body): Mark the primitive as inlined if the type has relaxed finalization semantics. (Make_Finalize_Call_For_Node): New function. * sem_ch6.adb (Check_Statement_Sequence): Skip subprogram bodies. * libgnat/s-finpri.ads (Finalize_Object): Add Finalize_Address parameter. (Master_Node): Remove superfluous qualification. * libgnat/s-finpri.adb (Attach_Object_To_Node): Likewise. (Finalize_Master): Adjust calls to Finalize_Object. (Finalize_Object): Add Finalize_Address parameter and assert that it is equal to the component of the node. Use the Object_Address component as guard. (Suppress_Object_Finalize_At_End): Clear Object_Address component. * gnat_rm.texi: Regenerate. * gnat_ugn.texi: Regenerate.
2024-08-01ada: Fix internal error on limited aggregate in nested conditional expressionEric Botcazou1-20/+53
This is a fallout of an earlier fix to Is_Build_In_Place_Aggregate_Return that made it take into account intermediate conditional expressions, but turned out to work only for a single nesting level of them. The fix reuses the delayed expansion mechanism recently extended to deal with conditional expressions in a straightforward way. gcc/ada/ * exp_aggr.adb (Convert_To_Assignments): Set Expansion_Delayed on intermediate conditional expressions for BIP aggregate returns too. * exp_ch4.adb (Expand_N_Case_Expression): Also deal with delayed expansion in the return case. (Expand_N_If_Expression): Likewise.
2024-08-01ada: Remove support for bodies in -gnatcegArnaud Charlet1-811/+123
The support for generating C for Ada code is moved to GNAT LLVM. Keep support for generating header files from Ada spec files which is the remaining usage of -gnatceg. gcc/ada/ * bindgen.adb, bindusg.adb, debug.adb, einfo.ads, exp_aggr.adb, exp_attr.adb, exp_ch11.adb, exp_ch3.adb, exp_ch4.adb, exp_ch6.adb, exp_ch7.adb, exp_ch8.adb, exp_dbug.adb, exp_dbug.ads, exp_intr.adb, exp_unst.adb, exp_util.adb, exp_util.ads, freeze.adb, gen_il-fields.ads, gen_il-gen-gen_entities.adb, gnat1drv.adb, inline.adb, opt.ads, osint-c.adb, osint-c.ads, sem_attr.adb, sem_ch12.adb, sem_ch3.adb, sem_ch4.adb, sem_ch6.adb, sem_elab.adb, sem_res.adb, sinfo.ads, snames.ads-tmpl, switch-b.adb, switch-c.adb: Major clean up to remove C code generation for bodies.
2024-07-02ada: Use static allocation for small dynamic string concatenations in more casesEric Botcazou1-24/+67
This lifts the limitation of the original implementation whereby the first operand of the concatenation needs to have a length known at compiled time in order for the static allocation to be used. gcc/ada/ * exp_ch4.adb (Expand_Concatenate): In the case where an operand does not have both bounds known at compile time, use nevertheless the low bound directly if it is known at compile time. Fold the conditional expression giving the low bound of the result in the general case if the low bound of all the operands are equal.
2024-07-02ada: Call memcmp instead of Compare_Array_Unsigned_8 and...Eric Botcazou1-18/+23
... implement support for ordering comparisons of discrete array types. This extends the Support_Composite_Compare_On_Target feature to ordering comparisons of discrete array types as specified by RM 4.5.2(26/3), when the component type is a byte (unsigned). Implement support for ordering comparisons of discrete array types with a two-pronged approach: for types with a size known at compile time, this lets the gimplifier generate the call to memcmp (or else an optimize version of it); otherwise, this directly generates the call to memcmp. gcc/ada/ * exp_ch4.adb (Expand_Array_Comparison): Remove the obsolete byte addressibility test. If Support_Composite_Compare_On_Target is true, immediately return for a component size of 8, an unsigned component type and aligned operands. Disable when Unnest_Subprogram_Mode is true (for LLVM). (Expand_N_Op_Eq): Adjust comment. * targparm.ads (Support_Composite_Compare_On_Target): Replace bit by byte in description and document support for ordering comparisons. * gcc-interface/utils2.cc (compare_arrays): Rename into... (compare_arrays_for_equality): ...this. Remove redundant lines. (compare_arrays_for_ordering): New function. (build_binary_op) <comparisons>: Call compare_arrays_for_ordering to implement ordering comparisons for arrays.
2024-06-27ada: Implement first half of Generalized FinalizationEric Botcazou1-3/+5
This implements the first half of the Generalized Finalization proposal, namely the Finalizable aspect as well as its optional relaxed semantics for the finalization operations, but the latter part is only implemented for dynamically allocated objects. In accordance with the spirit, if not the letter, of the proposal, this implements the finalizable types declared with strict semantics for the finalization operations as a direct generalization of controlled types, which in turn makes it possible to reimplement the latter types in terms of the former types and ensures full interoperability between them. The relaxed semantics for the finalization operations is also a direct generalization of the GNAT pragma No_Heap_Finalization for dynamically allocated objects, in that it extends the effects of the pragma to all access types designating the finalizable type, instead of just applying them to library-level named access types. gcc/ada/ * aspects.ads (Aspect_Id): Add Aspect_Finalizable. (Implementation_Defined_Aspect): Add True for Aspect_Finalizable. (Operational_Aspect): Add True for Aspect_Finalizable. (Aspect_Argument): Add Expression for Aspect_Finalizable. (Is_Representation_Aspect): Add False for Aspect_Finalizable. (Aspect_Names): Add Name_Finalizable for Aspect_Finalizable. (Aspect_Delay): Add Always_Delay for Aspect_Finalizable. * checks.adb: Add with and use clauses for Sem_Elab. (Install_Primitive_Elaboration_Check): Call Is_Controlled_Procedure. * einfo.ads (Has_Relaxed_Finalization): Document new flag. (Is_Controlled_Active): Update documentation. * exp_aggr.adb (Generate_Finalization_Actions): Replace Find_Prim_Op with Find_Controlled_Prim_Op for Name_Finalize. * exp_attr.adb (Expand_N_Attribute_Reference) <Finalization_Size>: Return 0 if the prefix type has relaxed finalization. * exp_ch3.adb (Build_Equivalent_Record_Aggregate): Return Empty if the type needs finalization. (Expand_Freeze_Record_Type): Call Find_Controlled_Prim_Op instead of Find_Prim_Op for Name_{Adjust,Initialize,Finalize}. Call Make_Finalize_Address_Body for all controlled types. * exp_ch4.adb (Insert_Dereference_Action): Do not generate a call to Adjust_Controlled_Dereference if the designated type has relaxed finalization. * exp_ch6.adb (Needs_BIP_Collection): Return false for an untagged type that has relaxed finalization. * exp_ch7.adb (Allows_Finalization_Collection): Return false if the designated type has relaxed finalization. (Check_Visibly_Controlled): Call Find_Controlled_Prim_Op instead of Find_Prim_Op. (Make_Adjust_Call): Likewise. (Make_Deep_Record_Body): Likewise. (Make_Final_Call): Likewise. (Make_Init_Call): Likewise. * exp_disp.adb (Set_All_DT_Position): Remove obsolete warning. * exp_util.ads: Add with and use clauses for Snames. (Find_Prim_Op): Add precondition. (Find_Controlled_Prim_Op): New function declaration. (Name_Of_Controlled_Prim_Op): Likewise. * exp_util.adb: Remove with and use clauses for Snames. (Build_Allocate_Deallocate_Proc): Do not build finalization actions if the designated type has relaxed finalization. (Find_Controlled_Prim_Op): New function. (Find_Last_Init): Call Find_Controlled_Prim_Op instead of Find_Prim_Op. (Name_Of_Controlled_Prim_Op): New function. * freeze.adb (Freeze_Entity.Freeze_Record_Type): Propagate the Has_Relaxed_Finalization flag from components. * gen_il-fields.ads (Opt_Field_Enum): Add Has_Relaxed_Finalization. * gen_il-gen-gen_entities.adb (Entity_Kind): Likewise. * sem_aux.adb (Is_By_Reference_Type): Return true for all controlled types. * sem_ch3.adb (Build_Derived_Record_Type): Do not special case types declared in Ada.Finalization. (Record_Type_Definition): Propagate the Has_Relaxed_Finalization flag from components. * sem_ch13.adb (Analyze_Aspects_At_Freeze_Point): Also process the Finalizable aspect. (Analyze_Aspect_Specifications): Likewise. Call Flag_Non_Static_Expr in more cases. (Check_Aspect_At_Freeze_Point): Likewise. (Inherit_Aspects_At_Freeze_Point): Likewise. (Resolve_Aspect_Expressions): Likewise. (Resolve_Finalizable_Argument): New procedure. (Validate_Finalizable_Aspect): Likewise. * sem_elab.ads: Add with and use clauses for Snames. (Is_Controlled_Procedure): New function declaration. * sem_elab.adb: Remove with and use clauses for Snames. (Is_Controlled_Proc): Move to... (Is_Controlled_Procedure): ...here and rename. (Check_A_Call): Call Find_Controlled_Prim_Op instead of Find_Prim_Op. (Is_Finalization_Procedure): Likewise. * sem_util.ads (Propagate_Controlled_Flags): Update documentation. * sem_util.adb (Is_Fully_Initialized_Type): Replace call to Find_Optional_Prim_Op with Find_Controlled_Prim_Op. Call Has_Null_Extension only for derived tagged types. (Propagate_Controlled_Flags): Propagate Has_Relaxed_Finalization. * snames.ads-tmpl (Name_Finalizable): New name. (Name_Relaxed_Finalization): Likewise. * libgnat/s-finroo.ads (Root_Controlled): Add Finalizable aspect. * doc/gnat_rm/gnat_language_extensions.rst: Document implementation of Generalized Finalization. * gnat_rm.texi: Regenerate. * gnat_ugn.texi: Regenerate.
2024-06-20ada: Fix composition of primitive equality for untagged records with variant ↵Eric Botcazou1-28/+22
part In Ada 2012, primitive equality operators of untagged record types compose like those of tagged record types, but this has never been implemented for untagged record types with a variant part. gcc/ada/ * exp_ch4.adb (Expand_Composite_Equality): In the untagged record case, always look for a user-defined equality operator in Ada 2012.
2024-06-20ada: Fix bogus error with "=" operator on array of private unchecked unionEric Botcazou1-18/+9
The code is legal and, therefore, must be accepted by the compiler, but it must raise Program_Error at run time due to operands not having inferable discriminants and a warning be given at compile time (RM B.3.3(22-23)). gcc/ada/ * exp_ch4.adb (Expand_Array_Equality.Component_Equality): Copy the Comes_From_Source flag from the original test to the new one, and remove obsolete code dealing with unchecked unions. * sem_util.adb (Has_Inferable_Discriminants): Return False for an incomplete or private nominal subtype.
2024-06-14ada: Add prototype for mutably tagged typesJustin Squirek1-13/+38
This patch implements mutably tagged types via the new Size'Class aspect. gcc/ada/ * doc/gnat_rm/gnat_language_extensions.rst: Add documentation for mutably tagged type feature. * aspects.ads: Add registration for 'Size'Class. * einfo.ads: Add documentation for new components Class_Wide_Equivalent_Type and Is_Mutably_Tagged_Type. * exp_aggr.adb (Gen_Assign): Assume associated mutably tagged type when class-wide equivalent type is encountered. (Contains_Mutably_Tagged_Type): New subprogram. (Convert_To_Positional): Assume associated mutably tagged type when class-wide equivalent type is encountered. (Is_Static_Element): Assume associated mutably tagged type when class-wide equivalent type is encountered. (Expand_Array_Aggregate): Assume associated mutably tagged type when class-wide equivalent type is encountered. (Expand_Record_Aggregate): Force mutably tagged records to be expanded into assignments. * exp_ch3.adb (Build_Array_Init_Proc): Assume associated mutably tagged type when class-wide equivalent type is encountered. (Simple_Initialization_OK): Disallow simple initialization for class-wide equivalent types. (Build_Init_Statements): Assume associated mutably tagged type when class-wide equivalent type is encountered. (Expand_Freeze_Array_Type): Ignore building of record init procs for mutably tagged types. (Expand_N_Full_Type_Declaration): Replace mutably tagged type declarations with their associated class-wide equivalent types. (Default_Initialize_Object): Add special handling for mutably tagged types. * exp_ch4.adb (Expand_N_Allocator): Add initialization for mutably tagged types. (Expand_Record_Equality): Generate mutably tagged unchecked conversions. * exp_ch5.adb (Expand_N_Assignment_Statement): Generate a special assignment case for class-wide equivalent types which does tag assignments and ignores certain checks. * exp_ch6.adb (Expand_Call_Helper): Propagate constrained extra formal actuals for mutably tagged types. * exp_ch7.adb (Make_Init_Call): Handle mutably tagged type initialization. * exp_util.adb (Make_CW_Equivalent_Type): Modify to handle mutably tagged objects which contain no initialization expression. (Make_Subtype_From_Expr): Modify call to Make_CW_Equivalent_Type. * exp_util.ads (Make_CW_Equivalent_Type): Move declaration from body to spec. * freeze.adb (Size_Known): No longer return false automatically when a class-wide type is encountered. (Freeze_Entity): Ignore error messages about size not being known for mutably tagged types. * gen_il-fields.ads: Register new fields Class_Wide_Equivalent_Type and Is_Mutably_Tagged_Type. * gen_il-gen-gen_entities.adb: Register new fields Class_Wide_Equivalent_Type and Is_Mutably_Tagged_Type for type entities. * mutably_tagged.adb, mutably_tagged.ads (Corresponding_Mutably_Tagged_Type): New subprogram. (Depends_On_Mutably_Tagged_Ext_Comp): New subprogram. (Get_Corresponding_Mutably_Tagged_Type_If_Present): New subprogram. (Get_Corresponding_Tagged_Type_If_Present): New subprogram. (Is_Mutably_Tagged_Conversion): New subprogram. (Is_Mutably_Tagged_CW_Equivalent_Type): New subprogram. (Make_Mutably_Tagged_Conversion): New subprogram. (Make_CW_Size_Compile_Check): New subprogram. (Make_Mutably_Tagged_CW_Check): New subprogram. * sem_aggr.adb (Resolve_Array_Aggregate): Skip tag checks for class-wide equivalent types. (Resolve_Aggr_Expr): Assume associated mutably tagged type when class-wide equivalent type is encountered. * sem_attr.adb (Analyze_Attribute): Allow 'Tag on mutably tagged types. (Resolve_Attribute): Detect errors for dependence of mutably tagged extension type component. * sem_ch12.adb (Instantiate_Object): Detect errors for dependence of mutably tagged extension type component. * sem_ch13.adb (Analyze_One_Aspect): Propagate 'Size'Class to class-wide type. (Analyze_Attribute_Definition_Clause): Add handling of 'Size'Class by generating class-wide equivalent types and checking for illegal uses. * sem_ch2.adb (Analyze_Identifier): Generate unchecked conversion for class-wide equivalent types. * sem_ch3.adb (Analyze_Component_Declaration): Avoid unconstrained errors on mutably tagged types. (Analyze_Object_Declaration): Rewrite declarations of mutably tagged types to use class-wide equivalent types. (Array_Type_Declaration): Modify arrays of mutably tagged types to use their corresponding class-wide equivalent types. (Derived_Type_Declaration): Add various checks for mutably tagged derived types. * sem_ch4.adb (Analyze_Allocator): Replace reference to mutably tagged type with cooresponding tagged type. (Process_Indexed_Component): Generate unchecked conversion for class-wide equivalent type. (Analyze_One_Call): Generate unchecked conversion for class-wide equivalent types. (Analyze_Selected_Component): Assume reference to class-wide equivalent type is associated mutably tagged type. (Analyze_Type_Conversion): Generate unchecked conversion for class-wide equivalent type. * sem_ch5.adb (Analyze_Assignment): Assume associated mutably tagged type when class-wide equivalent type is encountered. (Analyze_Iterator_Specification): Detect errors for dependence of mutably tagged extension type component. * sem_ch6.adb (Create_Extra_Formals): Add code to generate extra formal for mutably tagged types to signal if they are constrained. * sem_ch8.adb (Analyze_Object_Renaming): Detect error on renaming of mutably tagged extension type component. (Analyze_Renaming_Primitive_Operation): Detect error on renaming of mutably tagged extension type component. * sem_res.adb (Resolve_Actuals): Allow class-wide arguments on class-wide equivalent types. (Valid_Conversion): Assume associated mutably tagged type when class-wide equivalent type is encountered. * sem_util.adb (Is_Fully_Initialized_Type): Flag mutably tagged types as fully initialized. (Needs_Simple_Initalization): Flag class-wide equivalent types as needing initialization. * gnat_rm.texi: Regenerate. * gcc-interface/Make-lang.in: Add entry for mutably_tagged.o.
2024-06-10ada: Add support for No_Implicit_Conditionals to nonbinary modular typesEric Botcazou1-55/+77
The expansion of additive operations for nonbinary modular types implemented in the front-end and its counterpart in code generators may create branches, which is not allowed when restriction No_Implicit_Conditionals is in effect. This changes it to use an explicit Mod operation when the restriction is in effect, which is assumed not to create such branches. gcc/ada/ * exp_ch4.adb (Expand_Nonbinary_Modular_Op): Create an explicit Mod for additive operations if No_Implicit_Conditionals is in effect. (Expand_Modular_Addition): Likewise. (Expand_Modular_Subtraction): Likewise. (Expand_Modular_Op): Always use an unsigned type obtained by calling Small_Integer_Type_For on the required size.
2024-06-10ada: Fix references to Ada RM in commentsPiotr Trojanek1-1/+1
We seem to have a convention of using "RM" in the GNAT comments, not "Ada RM". Also, the paragraph references by convention should appear in parentheses, e.g. "8.3(12.3/2)", not "8.3 12.3/2". gcc/ada/ * einfo.ads, exp_attr.adb, exp_ch4.adb, exp_ch7.adb, lib-writ.adb, libgnat/a-stbuut.ads, sem_ch13.adb, sem_ch3.adb, sem_ch7.adb: Use "RM" in comments.
2024-05-20ada: Extend expansion delaying mechanism to conditional expressionsEric Botcazou1-81/+282
When an aggregate that needs to be converted into a series of assignments is present in an expression of a parent aggregate, or in the expression of an allocator, an object declaration, or an assignment in very specific cases, its expansion is delayed until its parent itself is expanded. This makes it possible to avoid creating a superfluous temporary for the aggregate. This change extends the delaying mechanism in the case of record aggregates to intermediate conditional expressions, that is to say, to the conditional expressions that are present between the parent and the aggregate, provided that the aggregate be a dependent expression, directly or recursively. This again makes it possible to avoid creating a temporary for the aggregate. gcc/ada/ * exp_aggr.ads (Is_Delayed_Conditional_Expression): New predicate. * exp_aggr.adb (Convert_To_Assignments.Known_Size): Likewise. (Convert_To_Assignments): Climb the parent chain, looking through qualified expressions and dependent expressions of conditional expressions, to find out whether the expansion may be delayed. Call Known_Size for this in the case of an object declaration. If so, set Expansion_Delayed on the aggregate as well as all the intermediate conditional expressions. (Initialize_Component): Reset the Analyzed flag on an initialization expression that is a conditional expression whose expansion has been delayed. (Is_Delayed_Conditional_Expression): New predicate. * exp_ch3.adb (Expand_N_Object_Declaration): Handle initialization expressions that are conditional expressions whose expansion has been delayed. * exp_ch4.adb (Build_Explicit_Assignment): New procedure. (Expand_Allocator_Expression): Handle initialization expressions that are conditional expressions whose expansion has been delayed. (Expand_N_Case_Expression): Deal with expressions whose expansion has been delayed by waiting for the rewriting of their parent as an assignment statement and then optimizing the assignment. (Expand_N_If_Expression): Likewise. (Expand_N_Qualified_Expression): Do not apply a predicate check to an operand that is a delayed aggregate or conditional expression. * gen_il-gen-gen_nodes.adb (N_If_Expression): Add Expansion_Delayed semantic flag. (N_Case_Expression): Likewise. * sinfo.ads (Expansion_Delayed): Document extended usage.
2024-05-20ada: Another small cleanup about allocators and aggregatesEric Botcazou1-2/+2
This eliminates a few more oddities present in the expander for allocators and aggregates nested in allocators and other constructs: - Convert_Aggr_In_Allocator takes both the N_Allocator and the aggregate as parameters, while the sibling procedures Convert_Aggr_In_Assignment and Convert_Aggr_In_Object_Decl only take the former. This changes the first to be consistent with the two others and propagates the change to Convert_Array_Aggr_In_Allocator. - Convert_Aggr_In_Object_Decl contains an awkward code structure with a useless inner block statement. - In_Place_Assign_OK and Convert_To_Assignments have some declarations of local variables not in the right place. No functional changes (presumably). gcc/ada/ * exp_aggr.ads (Convert_Aggr_In_Allocator): Remove Aggr parameter and adjust description. (Convert_Aggr_In_Object_Decl): Adjust description. * exp_aggr.adb (Convert_Aggr_In_Allocator): Remove Aggr parameter and add local variable of the same name instead. Adjust call to Convert_Array_Aggr_In_Allocator. (Convert_Aggr_In_Object_Decl): Add comment for early return and remove useless inner block statement. (Convert_Array_Aggr_In_Allocator): Remove Aggr parameter and add local variable of the same name instead. (In_Place_Assign_OK): Move down declarations of local variables. (Convert_To_Assignments): Put all declarations of local variables in the same place. Fix typo in comment. Replace T with Full_Typ. * exp_ch4.adb (Expand_Allocator_Expression): Call Unqualify instead of Expression on the qualified expression of the allocator for the sake of consistency. Adjust call to Convert_Aggr_In_Allocator.
2024-05-17ada: Replace spinlocks with fully-fledged locks in finalization collectionsEric Botcazou1-0/+2
This replaces spinlocks with fully-fledged locks in finalization collections because the former are deemed problematic with tasks that can be preempted. Because of the requirement to avoid dragging the tasking runtime when it is not necessary, the implementation goes through the usual soft links, with an additional hurdle that space must be reserved for the lock in any case since it is part of the ABI. This entails the introduction of the System.OS_Locks unit in the non-tasking runtime and the modification of the tasking runtime to also use this unit. This in turn requires a small adjustment: because of the presence of pre- and post-conditions in Interfaces.C and of the limitations of the RTSfind mechanism, the System.Finalization_Primitives unit must be preloaded, as what is done for the Ada.Strings.Text_Buffers unit. This effectively reverts the implementation to using the global task lock on bare board platforms. gcc/ada/ * Makefile.rtl (GNATRTL_NONTASKING_OBJS): Add s-oslock$(objext). (LIBGNAT_TARGET_PAIRS): Use s-oslock__dummy.ads by default. Set specific s-oslock.ads source file for all the platforms. * exp_ch7.ads (Preload_Finalization_Collection): New procedure. * exp_ch7.adb (Allows_Finalization_Collection): Return False if System.Finalization_Primitives has not been preloaded. (Preload_Finalization_Collection): New procedure. * opt.ads (Interface_Seen): New boolean variable. * s-oscons-tmplt.c: Use "N" string for pragma Style_Checks. * scng.adb (Scan): Set Interface_Seen upon seeing "interface". * sem_ch10.adb: Add clause for Exp_Ch7. (Analyze_Compilation_Unit): Call Preload_Finalization_Collection after the context of the unit is analyzed. * libgnarl/a-rttiev.adb: Add with clause for System.OS_Locks and alphabetize others. (Event_Queue_Lock): Adjust qualified name of subtype. * libgnarl/s-osinte__aix.ads: Add with clause for System.OS_Locks and change pthread_mutex_t into a local subtype. * libgnarl/s-osinte__android.ads: Likewise. * libgnarl/s-osinte__darwin.ads: Likewise. * libgnarl/s-osinte__dragonfly.ads: Likewise. * libgnarl/s-osinte__freebsd.ads: Likewise. * libgnarl/s-osinte__gnu.ads: Likewise. * libgnarl/s-osinte__hpux-dce.ads: Likewise. * libgnarl/s-osinte__hpux.ads: Add Likewise. * libgnarl/s-osinte__kfreebsd-gnu.ads: Likewise. * libgnarl/s-osinte__linux.ads: Likewise. * libgnarl/s-osinte__lynxos178e.ads: Likewise. * libgnarl/s-osinte__qnx.ads: Likewise. * libgnarl/s-osinte__rtems.ads: Likewise. * libgnarl/s-osinte__mingw.ads: Add with clause for System.OS_Locks and change CRITICAL_SECTION into a local subtype. Add declarations for imported procedures dealing with CRITICAL_SECTION. * libgnarl/s-osinte__solaris.ads: Add with clause for System.OS_Locks and change mutex_t into a local subtype. * libgnarl/s-osinte__vxworks.ads: Add missing blank line. * libgnarl/s-taprop.ads: Alphabetize clauses and package renamings. Use qualified name for RTS_Lock throughout. * libgnarl/s-taprop__dummy.adb: Add use clause for System.OS_Locks and alphabetize others. * libgnarl/s-taprop__hpux-dce.adb: Likewise. * libgnarl/s-taprop__linux.adb: Likewise. * libgnarl/s-taprop__posix.adb: Likewise. * libgnarl/s-taprop__qnx.adb: Likewise. * libgnarl/s-taprop__rtems.adb: Likewise. * libgnarl/s-taprop__solaris.adb: Likewise. * libgnarl/s-taprop__vxworks.adb: Likewise. * libgnarl/s-taprop__mingw.adb: Likewise. Remove declarations for imported procedures dealing with CRITICAL_SECTION. * libgnarl/s-tarest.adb: Add with clause for System.OS_Locks and alphabetize others. (Global_Task_Lock): Adjust qualified name of subtype. * libgnarl/s-tasini.adb: Add clause for System.OS_Locks. (Initialize_RTS_Lock): New procedure. (Finalize_RTS_Lock): Likewise. (Acquire_RTS_Lock): Likewise. (Release_RTS_Lock): Likewise. (Init_RTS): Add compile-time assertions for RTS_Lock types. Set the soft links for the RTS lock manipulation routines. * libgnarl/s-taspri__dummy.ads: Add with clause for System.OS_Locks. (RTS_Lock): Delete and adjust throughout accordingly. * libgnarl/s-taspri__hpux-dce.ads: Likewise. * libgnarl/s-taspri__lynxos.ads: Likewise. * libgnarl/s-taspri__mingw.ads: Likewise. * libgnarl/s-taspri__posix-noaltstack.ads: Likewise. * libgnarl/s-taspri__posix.ads: Likewise. * libgnarl/s-taspri__solaris.ads: Likewise. * libgnarl/s-taspri__vxworks.ads: Likewise. * libgnat/s-finpri.ads: Add clause for System.OS_Locks. (Finalization_Collection): Change type of Lock. * libgnat/s-finpri.adb (Initialize): Call Initialize_RTS_Lock. (Lock_Collection): Call Acquire_RTS_Lock. (Unlock_Collection): Call Release_RTS_Lock. * libgnat/s-oslock__dummy.ads: New file. * libgnat/s-oslock__hpux-dce.ads: Likewise. * libgnat/s-oslock__mingw.ads: Likewise. * libgnat/s-oslock__posix.ads: Likewise. * libgnat/s-oslock__solaris.ads: Likewise. * libgnat/s-oslock__vxworks.ads: Likewise. * libgnat/s-soflin.ads (Null_Set_Address): New null procedure. (Initialize_RTS_Lock): New soft link. (Finalize_RTS_Lock): Likewise. (Acquire_RTS_Lock): Likewise. (Release_RTS_Lock): Likewise. * exp_ch4.adb (Expand_N_Allocator): In the subtype indication case, call Apply_Predicate_Check on the resulting access value if need be.
2024-05-17ada: Remove superfluous Relocate_Node callsRonan Desplanques1-1/+1
This patch removes two calls to Relocate_Node that were not needed. This does not affect the behavior of the compiler. gcc/ada/ * exp_ch4.adb (Expand_N_Case_Expression): Remove call to Relocate_Node. * sem_attr.adb (Analyze_Attribute): Likewise.
2024-05-16ada: Fix missing length checks with case expressionsRonan Desplanques1-4/+14
This fixes an issue where length checks were not generated when the right-hand side of an assigment involved a case expression. gcc/ada/ * sem_res.adb (Resolve_Case_Expression): Add length check insertion. * exp_ch4.adb (Expand_N_Case_Expression): Add handling of nodes known to raise Constraint_Error.
2024-05-16ada: Fix crash with -gnatdJ and -gnatw_qRonan Desplanques1-4/+4
This commit makes the emission of -gnatw_q warnings pass node information so as to handle the enclosing subprogram display of -gnatdJ instead of crashing. gcc/ada/ * exp_ch4.adb (Expand_Composite_Equality): Call Error_Msg_N instead of Error_Msg.
2024-05-14ada: Fix small inaccuracy in previous changeEric Botcazou1-1/+7
The call to Build_Allocate_Deallocate_Proc must occur before the special accessibility check for class-wide allocation is generated, because this check comes with cleanup code. gcc/ada/ * exp_ch4.adb (Expand_Allocator_Expression): Move the first call to Build_Allocate_Deallocate_Proc up to before the accessibility check.
2024-05-14ada: Decouple attachment from dynamic allocation for controlled objectsEric Botcazou1-8/+12
This decouples the attachment to the appropriate finalization collection of dynamically allocated objects that need finalization from their allocation. The current implementation immediately attaches them after allocating them, which means that they will be finalized even if their initialization does not complete successfully. The new implementation instead generates the same sequence as the one generated for (statically) declared objects, that is to say, allocation, initialization and attachment in this order. gcc/ada/ * exp_ch3.adb (Build_Default_Initialization): Do not generate the protection for finalization collections. (Build_Heap_Or_Pool_Allocator): Set the No_Initialization flag on the declaration of the temporary. * exp_ch4.adb (Build_Aggregate_In_Place): Do not build an allocation procedure here. (Expand_Allocator_Expression): Build an allocation procedure, if it is required, only just before rewriting the allocator. (Expand_N_Allocator): Do not build an allocation procedure if the No_Initialization flag is set on the allocator, except for those generated for special return objects. In other cases, build an allocation procedure, if it is required, only before rewriting the allocator. * exp_ch7.ads (Make_Address_For_Finalize): New function declaration. * exp_ch7.adb (Finalization Management): Update description for dynamically allocated objects. (Make_Address_For_Finalize): Remove declaration. (Find_Last_Init): Change to function and move to... (Process_Object_Declaration): Adjust to above change. * exp_util.ads (Build_Allocate_Deallocate_Proc): Add Mark parameter with Empty default and document it. (Find_Last_Init): New function declaration. * exp_util.adb (Build_Allocate_Deallocate_Proc): Add Mark parameter with Empty default and pass it in recursive call. Deal with type conversions created for interface types. Adjust call sequence to Allocate_Any_Controlled by changing Collection to In/Out parameter and removing Finalize_Address parameter. For a controlled object, generate a conditional call to Attach_Object_To_Collection for an allocation and to Detach_Object_From_Collection for a deallocation. (Find_Last_Init): ...here. Compute the initialization type for an allocator whose designating type is class wide specifically and also handle concurrent types. * rtsfind.ads (RE_Id): Add RE_Attach_Object_To_Collection and RE_Detach_Object_From_Collection. (RE_Unit_Table): Add entries for RE_Attach_Object_To_Collection and RE_Detach_Object_From_Collection. * libgnat/s-finpri.ads (Finalization_Started): Delete. (Attach_Node_To_Collection): Likewise. (Detach_Node_From_Collection): Move to... (Attach_Object_To_Collection): New procedure declaration. (Detach_Object_From_Collection): Likewise. (Finalization_Collection): Remove Atomic for Finalization_Started. Add pragma Inline for Initialize. * libgnat/s-finpri.adb: Add clause for Ada.Unchecked_Conversion. (To_Collection_Node_Ptr): New instance of Ada.Unchecked_Conversion. (Detach_Node_From_Collection): ...here. (Attach_Object_To_Collection): New procedure. (Detach_Object_From_Collection): Likewise. (Finalization_Started): Delete. (Finalize): Replace allocation with attachment in comments. * libgnat/s-stposu.ads (Allocate_Any_Controlled): Rename parameter Context_Subpool into Named_Subpool, parameter Context_Collection into Collection and change it to In/Out, and remove Fin_Address. * libgnat/s-stposu.adb: Remove clause for Ada.Unchecked_Conversion and Finalization_Primitives. (To_Collection_Node_Ptr): Delete. (Allocate_Any_Controlled): Rename parameter Context_Subpool into Named_Subpool, parameter Context_Collection into Collection and change it to In/Out, and remove Fin_Address. Do not lock/unlock and do not attach the object, instead only displace its address. (Deallocate_Any_Controlled): Do not lock/unlock and do not detach the object. (Header_Size_With_Padding): Use qualified name for Header_Size.
2024-05-14ada: Small cleanup about allocators and aggregatesEric Botcazou1-73/+50
This eliminates a few oddities present in the expander for allocators and aggregates present in allocators: - Convert_Array_Aggr_In_Allocator takes both a Decl and Alloc parameters, and inserts new code before Alloc for records and after Decl for arrays through Convert_Array_Aggr_In_Allocator. Now, for the 3 (duplicated) calls to the procedure, that's the same place. It also creates a new list that it does not use in most cases. - Expand_Allocator_Expression uses the same code sequence in 3 places when the expression is an aggregate to build in place. - Build_Allocate_Deallocate_Proc takes an Is_Allocate parameter that is entirely determined by the N parameter: if N is an allocator, it must be true; if N is a free statement, it must be false. Barring that, the procedure either raises an assertion or Program_Error. It also contains useless pattern matching code in the second part. No functional changes. gcc/ada/ * exp_aggr.ads (Convert_Aggr_In_Allocator): Rename Alloc into N, replace Decl with Temp and adjust description. (Convert_Aggr_In_Object_Decl): Alphabetize. (Is_Delayed_Aggregate): Likewise. * exp_aggr.adb (Convert_Aggr_In_Allocator): Rename Alloc into N and replace Decl with Temp. Allocate a list only when neeeded. (Convert_Array_Aggr_In_Allocator): Replace N with Decl and insert new code before it. * exp_ch4.adb (Build_Aggregate_In_Place): New procedure nested in Expand_Allocator_Expression. (Expand_Allocator_Expression): Call it to build aggregates in place. Remove second parameter in calls to Build_Allocate_Deallocate_Proc. (Expand_N_Allocator): Likewise. * exp_ch13.adb (Expand_N_Free_Statement): Likewise. * exp_util.ads (Build_Allocate_Deallocate_Proc): Remove Is_Allocate parameter. * exp_util.adb (Build_Allocate_Deallocate_Proc): Remove Is_Allocate parameter and replace it with local variable of same name. Delete useless pattern matching.
2024-05-14ada: Fix double finalization for dependent expression of case expressionEric Botcazou1-0/+1
The recent fix to Default_Initialize_Object, which has ensured that the No_Initialization flag set on an object declaration, for example for the temporary created by Expand_N_Case_Expression, is honored in all cases, has also uncovered a latent issue in the machinery responsible for the finalization of transient objects. More specifically, the answer returned by the Is_Finalizable_Transient predicate for an object of an access type is different when it is left uninitialized (true) than when it is initialized to null (false), which is incorrect; it must return false in both cases, because the only case where an object can be finalized by the machinery through an access value is when this value is a reference (N_Reference node) to the object. This was already more or less the current state of the evolution of the predicate, but this now explicitly states it in the code. The change also sets the No_Initialization flag for the temporary created by Expand_N_If_Expression for the sake of consistency. gcc/ada/ * exp_ch4.adb (Expand_N_If_Expression): Set No_Initialization on the declaration of the temporary in the by-reference case. * exp_util.adb (Initialized_By_Access): Delete. (Is_Allocated): Likewise. (Initialized_By_Reference): New predicate. (Is_Finalizable_Transient): If the transient object is of an access type, do not return true unless it is initialized by a reference.
2024-05-14ada: Factor out implementation of default initialization for objectsEric Botcazou1-438/+167
As written down in a comment, "There is a *huge* amount of code duplication" in the implementation of default initializaion for objects in the front-end, between the (static) declaration case and the dynamic allocation case. This change factors out the implementation of the (static) declaration case and uses it for the dynamic allocation case, with the following benefits: 1. getting rid of the duplication and reducing total line count, 2. bringing optimizations implemented for the (static) declaration case to the dynamic allocation case, 3. performing the missing abort deferral prescribed by RM 9.8(9) in the dynamic allocation case. gcc/ada/ * exp_aggr.adb (Build_Record_Aggr_Code): Replace reference to Build_Task_Allocate_Block_With_Init_Stmts in comment with reference to Build_Task_Allocate_Block. (Convert_Aggr_In_Allocator): Likewise for the call in the code. * exp_ch6.adb (Make_Build_In_Place_Call_In_Allocator): Likewise. * exp_ch3.ads: Alphabetize clauses. (Build_Default_Initialization): New function declaration. (Build_Default_Simple_Initialization): Likewise. (Build_Initialization_Call): Add Target_Ref parameter with default. * exp_ch3.adb (Build_Default_Initialization): New function extracted from... (Build_Default_Simple_Initialization): Likewise. (Build_Initialization_Call): Add Target_Ref parameter with default. (Expand_N_Object_Declaration): ...here. (Default_Initialize_Object): Call Build_Default_Initialization and Build_Default_Simple_Initialization. * exp_ch4.adb (Expand_Allocator_Expression): Minor comment tweaks. (Expand_N_Allocator): Call Build_Default_Initialization and Build_Default_Simple_Initialization to implement the default initialization of the allocated object. * exp_ch9.ads (Build_Task_Allocate_Block): Delete. (Build_Task_Allocate_Block_With_Init_Stmts): Rename into... (Build_Task_Allocate_Block): ...this. * exp_ch9.adb: Remove clauses for Exp_Tss. (Build_Task_Allocate_Block): Delete. (Build_Task_Allocate_Block_With_Init_Stmts): Rename into... (Build_Task_Allocate_Block): ...this. * exp_util.adb (Build_Allocate_Deallocate_Proc): Remove unnecessary initialization expression, adjust commentary and replace early exit with assertion. * sem_ch4.adb (Analyze_Allocator): In the null-exclusion case, call Apply_Compile_Time_Constraint_Error to insert the raise.
2024-05-13ada: Replace finalization masters with finalization collectionsEric Botcazou1-12/+13
This change replaces finalization masters with finalization collections in most cases, that is to say, when they implement a list of objects created by allocators of a given access type; indeed the moniker is overloaded in the front-end, e.g. Sem_Util.Is_Master determines if a node "constitutes a finalization master" but is not affected by the change. This is mostly a renaming at this stage, toward something more in keeping with the terminology used in the RM 7.6.1 clause and no functional changes: although it gets rid of the rest of the System.Finalization_Masters unit, the functionalities are reimplemented in the System.Finalization_Primitives unit in terms of collections with only minor adjustments. gcc/ada/ * Makefile.rtl (GNATRTL_NONTASKING_OBJS): Remove s-finmas$(objext). * einfo.ads (Anonymous_Masters): Rename into Anonymous_Collections. (Finalization_Master): Rename into Finalization_Collection. * gen_il-fields.ads (Opt_Field_Enum): Replace Anonymous_Masters with Anonymous_Collections; and Finalization_Master with Finalization_Collection. * gen_il-gen-gen_entities.adb (Access_Kind): Likewise. (E_Function): Likewise. (E_Procedure): Likewise. (E_Package): Likewise. (E_Subprogram_Body): Likewise. * exp_ch3.adb (Build_Heap_Or_Pool_Allocator): Adjust to renamings. (Freeze_Type): Likewise. (Stream_Operation_OK): Remove obsolete test. * exp_ch4.adb (Expand_Allocator_Expression): Adjust to renamings. (Expand_N_Allocator): Likewise. * exp_ch6.ads (BIP_Formal_Kind): Replace BIP_Finalization_Master with BIP_Collection. (Needs_BIP_Finalization_Master): Rename into... (Needs_BIP_Collection): ...this. * exp_ch6.adb (BIP_Finalization_Master_Suffix): Delete. (BIP_Collection_Suffix): New constant string. (Add_Finalization_Master_Actual_To_Build_In_Place_Call): Rename to (Add_Collection_Actual_To_Build_In_Place_Call): ...this and adjust. (BIP_Formal_Suffix): Replace BIP_Finalization_Master alternative with BIP_Collection alternative. (BIP_Suffix_Kind): Replace test on BIP_Finalization_Master_Suffix with test on BIP_Collection_Suffix. (Is_Build_In_Place_Entity): Likewise. (Make_Build_In_Place_Call_In_Allocator): Call Needs_BIP_Collection and Add_Collection_Actual_To_Build_In_Place_Call. (Make_Build_In_Place_Call_In_Anonymous_Context): Likewise. (Make_Build_In_Place_Call_In_Assignment): Likewise. (Make_Build_In_Place_Call_In_Object_Declaration): Likewise. (Needs_BIP_Finalization_Master): Rename into... (Needs_BIP_Collection): ...this. (Needs_BIP_Alloc_Form): Call Needs_BIP_Collection. * exp_ch7.ads (Build_Anonymous_Master): Rename into... (Build_Anonymous_Collection): ...this. (Build_Finalization_Master): Rename into... (Build_Finalization_Collection): ...this. * exp_ch7.adb (Allows_Finalization_Master): Rename into... (Allows_Finalization_Collection): ...this. (Build_BIP_Cleanup_Stmts): Adjust to renamings. (Build_Anonymous_Master): Rename into... (Build_Anonymous_Collection): ...this. Adjust to renamings. (Build_Finalization_Master): Rename into... (Build_Finalization_Collection): ...this. Adjust to renamings. (Build_Finalizer): Adjust comment to renamings. * exp_ch13.adb (Expand_N_Free_Statement): Adjust to renamings. * exp_util.adb (Build_Allocate_Deallocate_Proc): Likewise. (Requires_Cleanup_Actions): Adjust comment to renamings. * freeze.adb (Freeze_All): Likewise. * rtsfind.ads (RTU_Id): Remove System_Finalization_Masters. (RE_Id): Remove RE_Finalization_Master & RE_Finalization_Master_Ptr add RE_Finalization_Collection & RE_Finalization_Collection_Ptr. Adjust RE_Add_Offset_To_Address and RE_Finalization_Scope_Master. (RE_Unit_Table): Remove entries for RE_Finalization_Master & RE_Finalization_Master_Ptr, add ones for RE_Finalization_Collection & RE_Finalization_Collection_Ptr. Also adjust those of RE_Add_Offset_To_Address and RE_Finalization_Scope_Master. * sem_ch3.adb (Access_Type_Declaration): Adjust to renamings. * sem_ch6.adb (Create_Extra_Formals): Likewise. * sem_util.adb (Designated_Subtype_Mark): Likewise. * libgnat/s-finpri.ads: Add clauses for Ada.Finalization and System.Storage_Elements. (Finalization_Collection): New limited controlled type. (Finalization_Collection_Ptr): Likewise. (Initialize): New overriding procedure. (Finalize): Likewise. (Finalization_Started): Likewise. (Collection_Node): New type. (Collection_Node_Ptr): Likewise. (Attach_Node_To_Collection): New procedure. (Detach_Node_From_Collection): Likewise. (Header_Size): New function. (Add_Offset_To_Address): Likewise. * libgnat/s-finpri.adb (Add_Offset_To_Address): New function. (Attach_Node_To_Collection): New procedure. (Detach_Node_From_Collection): Likewise. (Finalization_Started): Likewise. (Finalize): New overriding procedure. (Header_Size): New function. (Initialize): New overriding procedure. * libgnat/s-spsufi.ads (Finalize_And_Deallocate): Adjust comment. * libgnat/s-spsufi.adb: Remove clause for Finalization_Masters and add clause for Finalization_Primitives. (Finalize_And_Deallocate): Finalize the Collection component. * libgnat/s-stposu.ads: Remove clause for Finalization_Masters and add clause for Finalization_Primitives. (Root_Subpool): Replace Master component with Collection. (Allocate_Any_Controlled): Replace Context_Master parameter with Context_Collection parameter. * libgnat/s-stposu.adb: Remove clauses for Finalization_Masters and add clauses for Finalization_Primitives. (Address_To_FM_Node_Ptr): Delete. (To_Collection_Node_Ptr): New instance of Ada.Unchecked_Conversion. (Adjust_Controlled_Dereference): Adjust comment to renamings. (Allocate_Any_Controlled): Replace Context_Master parameter with Context_Collection parameter. Adjust to renamings. (Deallocate_Any_Controlled): Adjust to renamings. (Print_Subpool): Likewise. * libgnat/s-finmas.ads: Delete. * libgnat/s-finmas.adb: Likewise.
2024-05-07ada: Remove redundant guard against empty list of actionsPiotr Trojanek1-14/+11
Code cleanup. gcc/ada/ * exp_ch4.adb (Useful): Remove redundant check for empty list, because iteration with First works also for empty list; rename local variable from L to Action.
2024-05-06ada: Rework processing of special objects needing finalizationEric Botcazou1-0/+4
This reworks the processing of special objects needing finalization in the new implementation. These special objects, i.e. return object in extended return statements and transient objects, cannot be automatically handled by the post-processing phase because they have additional requirements, either conditional finalization for the former or immediate finalization for the latter and, therefore, a specific processing during expansion is needed for them before the post-processing phase can complete the work. The previous scheme used to do minimal processing during expansion, leaving the bulk of the work to the post-processing phase. Unfortunately this scheme turned out not to be stable for Expression_With_Actions nodes under copying by means of New_Copy_Tree or equivalent devices. The new scheme moves a bit more processing to the expansion, namely the generation of the attachment to the master node, whose result can then be naturally copied by New_Copy_Tree. A side effect is to further simplify the implementation of Build_Finalizer in Exp_Ch7, which has one fewer special case to deal with. gcc/ada/ * einfo.ads (Finalization_Master_Node_Or_Object): Rename into... (Finalization_Master_Node): ...this and adjust description. * exp_ch4.adb (Process_Transient_In_Expression): Attach the object to its master node here. * exp_ch7.ads (Attach_Object_To_Master_Node): New declaration. * exp_ch7.adb (Attach_Object_To_Master_Node): New procedure. (Build_Finalizer.Process_Declarations): Examine the type of a variable to spot master nodes. (Build_Finalizer.Process_Object_Declaration): Look only at the object and deal specifically with the case of a master node. (Build_Finalizer.Build_BIP_Cleanup_Stmts): Move to child function of Attach_Object_To_Master_Node. (Build_Finalizer.Make_Address_For_Finalize): Move to... (Insert_Actions_In_Scope_Around.Process_Transient_In_Scope): Attach the object to its master node here. (Make_Address_For_Finalize): ...here. (Make_Master_Node_Declaration): Adjust to above renaming and set Finalization_Master_Node only on the object. (Make_Suppress_Object_Finalize_Call): Adjust to above renaming and attach the object to its master node here. * exp_util.adb (Requires_Cleanup_Actions): Examine the type of a variable to spot master nodes. * gen_il-fields.ads (Opt_Field_Enum): Adjust to above renaming. * gen_il-gen-gen_entities.adb (Allocatable_Kind): Likewise. * rtsfind.ads (RE_Id): Add RE_Chain_Node_To_Master. (RE_Unit_Table): Add entry for RE_Chain_Node_To_Master. * libgnat/s-finpri.ads (Chain_Node_To_Master): New declaration. * libgnat/s-finpri.adb (Chain_Node_To_Master): New procedure. (Attach_Object_To_Master): Call it. (Finalize_Master): Do not raise Program_Error on null addresses. (Finalize_Object): Add assertion that the address is not null.
2024-05-06ada: Partial implementation of redesign of support for object finalizationEric Botcazou1-90/+33
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.
2024-03-07Fix bogus error on allocator for array type with Dynamic_PredicateEric Botcazou1-2/+4
This is a regression present on all active branches: the compiler gives a bogus error on an allocator for an unconstrained array type declared with a Dynamic_Predicate because Apply_Predicate_Check is invoked directly on a subtype reference, which it cannot handle. This moves the check to the resulting access value (after dereference) like in Expand_Allocator_Expression. gcc/ada/ PR ada/113979 * exp_ch4.adb (Expand_N_Allocator): In the subtype indication case, call Apply_Predicate_Check on the resulting access value if needed. gcc/testsuite/ * gnat.dg/predicate15.adb: New test.
2024-01-22Update copyright years.Marc Poulhiès1-1/+1
2023-12-19ada: Further cleanup in finalization machineryEric Botcazou1-143/+135
This removes the setting of the Is_Ignored_Transient flag on the temporaries needing finalization created by Expand_Ctrl_Function_Call when invoked from within the dependent expressions of conditional expressions. This flag tells the general finalization machinery to disregard the object. But temporaries needing finalization present in action lists of dependent expressions are picked up by Process_Transients_In_Expression, which deals with their finalization and sets the Is_Finalized_Transient flag on them. Now this latter flag has exactly the same effect as Is_Ignored_Transient as far as the general finalization machinery is concerned, so setting the flag is unnecessary. In the end, the flag can be decoupled entirely from transient objects and renamed into Is_Ignored_For_Finalization. This also moves around the declaration of a local variable and turns a library-level procedure into a nested procedure. gcc/ada/ * einfo.ads (Is_Ignored_Transient): Rename into... (Is_Ignored_For_Finalization): ...this. * gen_il-fields.ads (Opt_Field_Enum): Adjust to above renaming. * gen_il-gen-gen_entities.adb (Object_Kind): Likewise. * exp_aggr.adb (Expand_Array_Aggregate): Likewise. * exp_ch7.adb (Build_Finalizer.Process_Declarations): Likewise. * exp_util.adb (Requires_Cleanup_Actions): Likewise. * exp_ch4.adb (Expand_N_If_Expression): Move down declaration of variable Optimize_Return_Stmt. (Process_Transient_In_Expression): Turn procedure into a child of... (Process_Transients_In_Expression): ...this procedure. * exp_ch6.adb (Expand_Ctrl_Function_Call): Remove obsolete setting of Is_Ignored_Transient flag on the temporary if within a dependent expression of a conditional expression.
2023-12-19ada: Plug small loophole in finalization machineryEric Botcazou1-0/+8
The path in Expand_N_If_Expression implementing the special optimization for an unidimensional array type and dependent expressions with static bounds fails to call Process_Transients_In_Expression on their list of actions. gcc/ada/ * exp_ch4.adb (Expand_N_If_Expression): Also add missing calls to Process_Transients_In_Expression on the code path implementing the special optimization for an unidimensional array type and dependent expressions with static bounds.
2023-12-19ada: Further cleanup in finalization machineryEric Botcazou1-88/+66
This streamlines the submachinery that makes it so that the finalization of temporaries created for EWAs and conditional expressions is deferred to the enclosing context. The original implementation was using a deep tree traversal for EWAs, which was later restricted to immediate subexpressions; this further flattens it to the traversal of the immediate list of actions of the EWA in keeping with the implementation for conditional expressions. This should not change anything because the enclosing context found by the machinery is the same, whatever the starting position in a nest of EWAs or conditional expressions. gcc/ada/ * exp_ch4.adb (Process_If_Case_Statements): Rename into... (Process_Transients_In_Expression): ...this and beef up comment. (Expand_N_Case_Expression): Call Process_Transients_In_Expression unconditionally on the list of actions of each alternative. (Expand_N_Expression_With_Actions): Do not deal with actions in nested subexpressions, but call Process_Transients_In_Expression on the list of actions only. (Expand_N_If_Expression): Adjust to above renaming. Add missing calls to Process_Transients_In_Expression in the case when an EWA is not used because of Minimize_Expression_With_Actions.
2023-11-30ada: Rework fix for wrong finalization of qualified aggregate in allocatorEric Botcazou1-7/+17
The problem is that there is no easy method to insert an action after an arbitrary node in the tree, so the original fix does not correctly work when the allocator is nested in another expression. Therefore this moves the burden of the insertion from Apply_Predicate_Check to Expand_Allocator_Expression and restricts the new processing to the case where it is really required. gcc/ada/ * checks.ads (Apply_Predicate_Check): Add Deref boolean parameter. * checks.adb (Apply_Predicate_Check): Revert latest change. Use Loc local variable to hold the source location. Use a common code path for the generic processing and make a dereference if Deref is True. * exp_ch4.adb (Expand_Allocator_Expression): Compute Aggr_In_Place earlier. If it is true, do not call Apply_Predicate_Check on the expression on entry but on the temporary on exit with a dereference. * sem_res.adb (Resolve_Actuals): Add explicit parameter association in call to Apply_Predicate_Check.
2023-11-30ada: Fix predicate check failure in Expand_Allocator_ExpressionEric Botcazou1-8/+9
The For_Special_Return_Object flag needs to be accessed on entry of the procedure in case the allocator is rewritten during the processing. gcc/ada/ * exp_ch4.adb (Expand_Allocator_Expression): Add Special_Return boolean constant to hold the value of For_Special_Return_Object for the allocator and use it throughout the procedure.
2023-11-07ada: Rename Is_Limited_View to reflect actual queryYannick Moy1-1/+1
Function Sem_Aux.Is_Limited_View returns whether the type is "inherently limited" in a slightly different way from the "immutably limited" definition in Ada 2012. Rename for clarity. gcc/ada/ * exp_aggr.adb: Apply the renaming. * exp_ch3.adb: Same. * exp_ch4.adb: Same. * exp_ch6.adb: Same. * exp_ch7.adb: Same. * exp_util.adb: Same. * freeze.adb: Same. * sem_aggr.adb: Same. * sem_attr.adb: Same. * sem_aux.adb: Alphabetize Is_Limited_Type. Rename. * sem_aux.ads: Same. * sem_ch3.adb: Apply the renaming. * sem_ch6.adb: Same. * sem_ch8.adb: Same. * sem_prag.adb: Same. * sem_res.adb: Same. * sem_util.adb: Same.
2023-07-04ada: Small adjustments to new procedure Expand_Unchecked_Union_EqualityEric Botcazou1-6/+10
The procedure is not stable under repeated invocation. Now it may be called twice on the same node, for example during the expansion of the renaming of the predefined equality operator after the unchecked union type is frozen. gcc/ada/ * exp_ch4.ads (Expand_Unchecked_Union_Equality): Only take a single parameter. * exp_ch4.adb (Expand_Unchecked_Union_Equality): Add guard against repeated invocation on the same node. * exp_ch6.adb (Expand_Call): Only pass a single actual parameter in the call to Expand_Unchecked_Union_Equality.
2023-07-03ada: Fix renaming of predefined equality operator for unchecked union typesEric Botcazou1-409/+273
The problem is that the predefined equality operator for unchecked union types is implemented out of line by invoking a function that takes more parameters than the two operands, which means that the renaming is not seen as type conforming with this function and, therefore, is rejected. The way out is to implement these additional parameters as "extra" formal parameters, since this kind of parameters is not taken into account for semantic checks. The change also factors out the duplicated generation of actuals for these additional parameters into a single procedure. gcc/ada/ * exp_ch3.ads (Build_Variant_Record_Equality): Add Spec_Id as second parameter. * exp_ch3.adb (Build_Variant_Record_Equality): For unchecked union types, build the additional parameters as extra formal parameters. (Expand_Freeze_Record_Type.Build_Variant_Record_Equality): Pass Empty as Spec_Id in call to Build_Variant_Record_Equality. * exp_ch4.ads (Expand_Unchecked_Union_Equality): New procedure. * exp_ch4.adb (Expand_Composite_Equality): In the presence of a function implementing composite equality, do not special case the unchecked union types, and only convert the operands if the base types are not the same like in Build_Equality_Call. (Build_Equality_Call): Do not special case the unchecked union types and relocate the operands only once. (Expand_N_Op_Eq): Do not special case the unchecked union types. (Expand_Unchecked_Union_Equality): New procedure implementing the specific expansion of calls to the predefined equality function. * exp_ch6.adb (Is_Unchecked_Union_Equality): New predicate. (Expand_Call): Call Is_Unchecked_Union_Equality to determine whether to call Expand_Unchecked_Union_Equality or Expand_Call_Helper. * exp_ch8.adb (Build_Body_For_Renaming): Set Has_Delayed_Freeze flag earlier on Id and pass Id in call to Build_Variant_Record_Equality.
2023-06-27ada: Fix double finalization of case expression in concatenationEric Botcazou1-35/+23
This streamlines the expansion of case expressions by not wrapping them in an Expression_With_Actions node when the type is not by copy, which avoids the creation of a temporary and the associated finalization issues. That's the same strategy as the one used for the expansion of if expressions when the type is by reference, unless Back_End_Handles_Limited_Types is set to True. Given that it is never set to True, except by a debug switch, and has never been implemented, this parameter is removed in the process. gcc/ada/ * debug.adb (d.L): Remove documentation. * exp_ch4.adb (Expand_N_Case_Expression): In the not-by-copy case, do not wrap the case statement in an Expression_With_Actions node. (Expand_N_If_Expression): Do not test Back_End_Handles_Limited_Types * gnat1drv.adb (Adjust_Global_Switches): Do not set it. * opt.ads (Back_End_Handles_Limited_Types): Delete.
2023-06-27ada: Fix too late finalization and secondary stack release in iterator loopsEric Botcazou1-26/+0
Sem_Ch5 contains an entire machinery to deal with finalization actions and secondary stack releases around iterator loops, so this removes a recent fix that was made in a narrower case and instead refines the condition under which this machinery is triggered. As a side effect, given that finalization and secondary stack management are still entangled in this machinery, this also fixes the counterpart of a leak for the former, which is a finalization occurring too late. gcc/ada/ * exp_ch4.adb (Expand_N_Quantified_Expression): Revert the latest change as it is subsumed by the machinery in Sem_Ch5. * sem_ch5.adb (Prepare_Iterator_Loop): Also wrap the loop statement in a block in the name contains a function call that returns on the secondary stack.
2023-06-13ada: Add missing ss_mark/ss_release in quantified expressionsBob Duff1-0/+26
If a quantified expression says "for all ... of F(...)" where F(...) is a function call that returns on the secondary stack, we need to clean up the secondary stack. This patch adds the required ss_mark/ss_release in that case. gcc/ada/ * exp_ch4.adb (Expand_N_Quantified_Expression): Detect the secondary-stack case, and find the innermost scope where we should mark/release, and Set_Uses_Sec_Stack on that. Skip intermediate blocks and loops that are part of expansion.
2023-06-13ada: Factor out tag assignments from type in expanderEric Botcazou1-25/+3
They are performed in a few different places during expansion. gcc/ada/ * exp_util.ads (Make_Tag_Assignment_From_Type): Declare. * exp_util.adb (Make_Tag_Assignment_From_Type): New function. * exp_aggr.adb (Build_Record_Aggr_Code): Call the above function. (Initialize_Simple_Component): Likewise. * exp_ch3.adb (Build_Record_Init_Proc.Build_Assignment): Likewise. (Build_Record_Init_Proc.Build_Init_Procedure ): Likewise. (Make_Tag_Assignment): Likewise. Rename local variable and call Unqualify to go through qualified expressions. * exp_ch4.adb (Expand_Allocator_Expression): Likewise.
2023-05-29ada: Fix wrong result for membership test of null in null-excluding access typeEric Botcazou1-3/+5
The result must be False as per the RM 4.5.2 (30.2/4) clause. gcc/ada/ * exp_ch4.adb (Expand_N_In): Deal specifically with a null operand.
2023-05-29ada: Fix wrong finalization for call to BIP function in conditional expressionEric Botcazou1-51/+120
This happens when the call is a dependent expression of the conditional expression, and the conditional expression is either the expression of a simple return statement or the return expression of an expression function. The reason is that the special processing of "tail calls" for BIP functions, i.e. calls that are the expression of simple return statements or the return expression of expression functions, is not applied. This change makes sure that it is applied by distributing the simple return statements enclosing conditional expressions into the dependent expressions of the conditional expressions in almost all cases. As a side effect, this elides a temporary in the nonlimited by-reference case, as well as a pair of calls to Adjust/Finalize in the nonlimited controlled case. gcc/ada/ * exp_ch4.adb (Expand_N_Case_Expression): Distribute simple return statements enclosing the conditional expression into the dependent expressions in almost all cases. (Expand_N_If_Expression): Likewise. (Process_Transient_In_Expression): Adjust to the above distribution. * exp_ch6.adb (Expand_Ctrl_Function_Call): Deal with calls in the dependent expressions of a conditional expression. * sem_ch6.adb (Analyze_Function_Return): Deal with the rewriting of a simple return statement during the resolution of its expression.
2023-05-26ada: Use truncation for dynamic conversions from floating point to fixed pointEric Botcazou1-2/+5
This changes the implementation of dynamic conversions from floating-point to ordinary fixed-point types, from rounding (to the nearest number) to truncation (toward zero), so as to make them consistent with both static conversions between these types and also the value of the Machine_Rounds attribute, which is False for all fixed-point types with GNAT. The rounding is still available under the debug switch -gnatd.N for the sake of backward compatibility with the previous implementation. gcc/ada/ * debug.adb (d.N): Document new usage. * exp_ch4.adb (Expand_N_Type_Conversion): Copy the Float_Truncate flag when rewriting a floating-point to fixed-point conversion as a floating-point to integer conversion. * exp_fixd.adb: Add with and use clauses for Debug. (Expand_Convert_Fixed_To_Fixed): Generate a truncation in all cases except if the result is explicitly rounded. (Expand_Convert_Integer_To_Fixed): Likewise. (Expand_Convert_Float_To_Fixed): Generate a truncation for all kind of fixed-point types, except if the result is explicitly rounded, or -gnatd.N is specified and the type is an ordinary fixed-point type. * sinfo.ads (Float_Truncate): Document usage for floating-point to fixed-point conversions.
2023-05-26ada: Crash on function returning allocated object containing tasksJavier Miranda1-0/+19
The frontend crashes when a function returns an object of a limited type that may have task components, has discriminants, and the object is created with an allocator. gcc/ada/ * exp_ch4.adb (Expand_N_Allocator): If an allocator with constraints is called in the return statement of a function returning a general access type, then propagate to the itype the master of the general access type (since it is the master associated with the returned object).
2023-05-26ada: Simplify expansion of set membershipPiotr Trojanek1-10/+7
Code cleanup; semantics is unaffected. gcc/ada/ * exp_ch4.adb (Expand_Set_Membership): Simplify by using Evolve_Or_Else.
2023-05-26ada: Cleanup expansion of membership operators into attribute ValidPiotr Trojanek1-22/+4
Code cleanup; semantics is unaffected. gcc/ada/ * exp_ch4.adb (Is_OK_Object_Reference): Replace loop with a call to Unqual_Conv; consequently, change object from variable to constant; replace an IF statement with an AND THEN expression.
2023-05-25ada: Missing warning on null-excluding array aggregate componentJavier Miranda1-0/+5
The compiler does not report warnings on the initialization of arrays of null-excluding access type components by means of iterated component association, when the expression initializing each component is either a conditional expression or a case expression that may initialize some component with a null value. gcc/ada/ * sem_aggr.adb (Warn_On_Null_Component_Association): New subprogram. (Empty_Range): Adding missing support for iterated component association node. (Resolve_Array_Aggregate): Report warning on iterated component association that may initialize some component of an array of null-excluding access type components with a null value. * exp_ch4.adb (Expand_N_Expression_With_Actions): Add missing type check since the subtype of the EWA node and the subtype of the expression may differ.