aboutsummaryrefslogtreecommitdiff
path: root/gcc/ada/libgnat
AgeCommit message (Collapse)AuthorFilesLines
2024-09-10ada: Whitespace cleanup in declaration of calendar-related routinesPiotr Trojanek1-6/+6
Code cleanup. gcc/ada/ * libgnat/s-os_lib.ads: Remove extra whitespace.
2024-09-05ada: Integrate new diagnostics in the frontendViljar Indus2-1/+3
Integrate diagnostic messages using the new implementation to the codebase. New diagnostic implementation uses GNAT.Lists as a building block. Tampering checks that were initially implemented for those lists are not critical for this implementation and they lead to overly complex code. Add a generic parameter Tampering_Checks to control whether the tempering checks should be applied for the lists. Make tampering checks conditional for GNAT.Lists gcc/ada/ * par-endh.adb: add call to new diagnostic for end loop errors. * sem_ch13.adb: add call to new diagnostic for default iterator error and record representation being too late. * sem_ch4.adb: Add new diagnostic for wrong operands. * sem_ch9.adb: Add new diagnostic for a Lock_Free warning. * libgnat/g-lists.adb (Ensure_Unlocked): Make checks for tampering conditional. * libgnat/g-lists.ads: Add parameter Tampering_Checks to control whether tampering checks should be executed. * backend_utils.adb: Add new gcc switches '-fdiagnostics-format=sarif-file' and '-fdiagnostics-format=sarif-stderr'. * debug.adb: document -gnatd_D switch. * diagnostics-brief_emitter.adb: New package for displaying diagnostic messages in a compact manner. * diagnostics-brief_emitter.ads: Same as above. * diagnostics-constructors.adb: New pacakge for providing simpler constructor methods for new diagnostic objects. * diagnostics-constructors.ads: Same as above. * diagnostics-converter.adb: New package for converting old Error_Msg_Object-s to Diagnostic_Types. * diagnostics-converter.ads: Same as above. * diagnostics-json_utils.adb: Package for utility methods related to emitting JSON. * diagnostics-json_utils.ads: Same as above. * diagnostics-pretty_emitter.adb: New package for displaying diagnostic messages in a more elaborate manner. * diagnostics-pretty_emitter.ads: Same as above. * diagnostics-repository.adb: New package for collecting all created error messages. * diagnostics-repository.ads: Same as above. * diagnostics-sarif_emitter.adb: New pacakge for converting all of the diagnostics into a report in the SARIF format. * diagnostics-sarif_emitter.ads: Same as above. * diagnostics-switch_repository.adb: New package containing the definitions for all of the warninging switches. * diagnostics-switch_repository.ads: Same as above. * diagnostics-utils.adb: Contains various utility methods for the diagnostic pacakges. * diagnostics-utils.ads: Same as above. * diagnostics.adb: Contains the definitions and common functions for all the new diagnostics objects. * diagnostics.ads: Same as above. * errout.adb: Relocate the old implementations for brief and pretty printing the diagnostic messages and the entrypoint to the new implementation if a debug switch is used. * errout.ads: Improve documentation. Make Set_Msg_Text publicly available. * opt.ads: Add the flag SARIF_File which controls whether the diagnostic messages should be printed to a file in the SARIF format. Add the flag SARIF_Output to control whether the diagnostic messages should be printed to std-err in the SARIF format. * gcc-interface/Make-lang.in: Add new pacakages to the object list. * gcc-interface/Makefile.in: Add new pacakages to the object list.
2024-08-23ada: Fix incorrect tracebacks on WindowsSebastian Poeplau1-1/+25
PECOFF symbols don't have a size attached to them. The symbol size that System.Object_Reader.Read_Symbol guesses to make up for the lack of information can be wrong when the symbol table doesn't match the algorithm's expectations; in particular that's the case when function symbols aren't sorted by address. To avoid incorrect tracebacks caused by wrong symbol size guesses, don't use the symbol size for PECOFF files when producing a traceback and instead pick the symbol with the highest address lower than the target address. gcc/ada/ * libgnat/s-dwalin.adb (Symbolic_Address): Ignore symbol size in address-to-symbol translation for PECOFF files.
2024-08-23ada: Update libraries with the limited flagViljar Indus6-7/+7
Records without a limited keyword now emit a warning if they contain a member that has an inherently limited type. gcc/ada/ * libgnat/a-coinho__shared.ads: add limited keyword. * libgnat/g-awk.adb: add limited keyword. * libgnat/g-comlin.ads: add limited keyword. * libgnat/s-excmac__arm.ads: add limited keyword. * libgnat/s-excmac__gcc.ads: add limited keyword. * libgnat/s-soflin.ads: add limited keyword.
2024-08-23ada: Fix style in lines starting with assignment operatorPiotr Trojanek5-21/+21
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-06ada: Reject use-clause conflicts in the run-time libraryBob Duff8-3/+43
This patch fixes a bug where GNAT would fail to detect certain errors when compiling the run-time library. In particular, if two overloaded homographs are both directly visible, it would pick one, rather than complaining about the ambiguity. The problem was that some special-purpose code in Sem_Ch8 was trying to make a user name take precedence over some run-time library declaration that (incorrectly) appears to be visible because of rtsfind. The solution is to disable that code while compiling the run-time library itself. In addition, we fix the newly-found errors in the run-time library. gcc/ada/ * sem_ch8.adb (Find_Direct_Name): Disable the special-purpose code when we are actually compiling the run-time library itself. * libgnarl/a-exetim__posix.adb: Fix newly-found use-clause conflicts. * libgnat/a-direct.adb: Likewise. * libgnat/a-nbnbin.adb: Likewise. * libgnat/a-timoio__128.adb: Likewise. * libgnat/a-timoio.adb: Likewise. * libgnat/a-wtmoio__128.adb: Likewise. * libgnat/a-wtmoio.adb: Likewise. * libgnat/a-ztmoio__128.adb: Likewise. * libgnat/a-ztmoio.adb: Likewise.
2024-08-02ada: Add contracts to Ada.Strings.Unbounded and adapt implementationYannick Moy4-260/+2068
Add complete functional contracts to all subprograms in Ada.Strings.Unbounded, except Count, following the specification from Ada RM A.4.5. These contracts are similar to the contracts found in Ada.Strings.Fixed and Ada.Strings.Bounded. A difference is that type Unbounded_String is controlled, thus we avoid performing copies of a parameter Source with Source'Old, and instead apply 'Old attribute on the enclosing call, such as Length(Source)'Old. As Unbounded_String is controlled, the implementation is not in SPARK. Instead, we have separately proved a slightly different implementation for which Unbounded_String is not controlled, against the same specification. This ensures that the specification is consistent. To minimize differences between this test from the SPARK testsuite and the actual implementation (the one in a-strunb.adb), and to avoid overflows in the actual implementation, some code is slightly rewritten. Delete and Insert are modified to return the correct result in all cases allowed by the standard. The same contracts are added to the version in a-strunb__shared.ads and similar implementation patches are applied to the body a-strunb__shared.adb. In particular, tests are added to avoid overflows on strings for which the last index is Natural'Last, and the computations that involve Sum to guarantee that an exception is raised in case of overflow are rewritten to guarantee correct detection and no intermediate overflows (and such tests are applied consistently between the procedure and the function when both exist). gcc/ada/ * libgnat/a-strunb.adb (Sum, Saturated_Sum, Saturated_Mul): Adapt function signatures to more precise types that allow proof. (function "&"): Conditionally assign a slice to avoid possible overflow which only occurs when the assignment is a noop (because the slice is empty in that case). (Append): Same. (function "*"): Retype K to avoid a possible overflow. Add early return on null length for proof. (Delete): Fix implementation to return the correct result in all cases allowed by the Ada standard. (Insert): Same. Also avoid possible overflows. (Length): Rewrite as expression function for proof. (Overwrite): Avoid possible overflows. (Slice): Same. (To_String): Rewrite as expression function for proof. * libgnat/a-strunb.ads: Extend Assertion_Policy to new contracts used. Add complete functional contracts to all subprograms of the public API except Count. * libgnat/a-strunb__shared.adb (Sum): Adapt function signature to more precise types that allow proof. (function "&"): Conditionally assign a slice to avoid possible overflow. (function "*"): Retype K to avoid a possible overflow. (Delete): Fix implementation to return the correct result in all cases allowed by the Ada standard. (Insert): Avoid possible overflows. (Overwrite): Avoid possible overflows. (Replace_Slice): Same. (Slice): Same. (To_String): Rewrite as expression function for proof. * libgnat/a-strunb__shared.ads: Extend Assertion_Policy to new contracts used. Add complete functional contracts to all subprograms of the public API except Count. Mark public part of spec as in SPARK.
2024-08-02ada: Add leap second support to conversion of Unix_TimeTonu Naks1-65/+70
Unix timestamp jumps one second back when a leap second is applied and doesn't count cumulative leap seconds. This was not taken into account in conversions between Unix time and Ada time. Now fixed. gcc/ada/ * libgnat/a-calend.adb: Modify unix time handling.
2024-08-02ada: Implement No_Raise aspect & pragma on subprogramsEric Botcazou1-0/+15
The new aspect is automatically set on the Adjust and Finalize primitives of finalizable types, unless Relaxed_Finalization is explicitly set to False, but it can also be specified directly on subprograms. It is also available in earlier versions of the language by means of the associated pragma. gcc/ada/ * aspects.ads (Aspect_Id): Add Aspect_No_Raise identifier. (Implementation_Defined_Aspect): Add True for Aspect_No_Raise. (Is_Representation_Aspect): Add False for Aspect_No_Raise. (Aspect_Names): Add Name_No_Raise for Aspect_No_Raise. (Aspect_Delay): Add Always_Delay for Aspect_No_Raise. * checks.ads (Raise_Checks_Suppressed): New function. (Apply_Raise_Check): New procedure. * checks.adb (Apply_Raise_Check): New procedure. (Raise_Checks_Suppressed): New function. * doc/gnat_rm/gnat_language_extensions.rst (Generalized Finalization): Update. * doc/gnat_rm/implementation_defined_aspects.rst (No_Raise): New. * doc/gnat_rm/implementation_defined_characteristics.rst (Check names): Document Raise_Check and alphabetize others. * doc/gnat_rm/implementation_defined_pragmas.rst (No_Raise): New. * einfo.ads (No_Raise): New flag defined in subprograms and generic subprograms. * exp_ch6.adb (Expand_N_Subprogram_Body): Call Apply_Raise_Check at the end of the processing. * exp_ch11.adb (Get_RT_Exception_Name): Add alternative for PE_Raise_Check_Failed to case statement. * gen_il-fields.ads (Opt_Field_Enum): Add No_Raise identifier. * gen_il-gen-gen_entities.adb (Subprogram_Kind): Add No_Raise as semantical flag. (Generic_Subprogram_Kind): Likewise. * par-prag.adb (Prag): Add alternative for Pragma_No_Raise to case statement. * sem_ch13.adb (Validate_Finalizable_Aspect): Set No_Raise on the Adjust and Finalize primitives if Relaxed_Finalization is set. * sem_prag.adb (Analyze_Pragma): Add alternative for Pragma_No_Raise to case statement. (Sig_Flag): Add 0 for Pragma_No_Raise. * snames.ads-tmpl (Remaining pragma names): Add Name_No_Raise. (Names of recognized checks): Add Name_Raise_Check. (Pragma_Id): Add Pragma_No_Raise identifier. * types.ads (Raise_Check): New named number. (All_Checks): Adjust. (RT_Exception_Code): Add PE_Raise_Check_Failed identifier. (Rkind): Add PE_Reason for PE_Raise_Check_Failed and alphabetize. * types.h (RT_Exception_Code): Add PE_Raise_Check_Failed as 38. (LAST_REASON_CODE): Adjust. * libgnat/a-except.adb (Rcheck_PE_Raise_Check): New procedure with pragmas Export, No_Return and Machine_Attributes. (Rmsg_38): New string constant. * gnat_rm.texi: Regenerate.
2024-08-02ada: Improve documenation about security of PRGNsJohannes Kliemann1-0/+2
The pseudo random number generators used in GNAT are not suitable for applications that require cryptographic security. While this was mentioned in some places others did not have a corresponding note, leading to these generators being used in a non-suitable context. gcc/ada/ * doc/gnat_rm/standard_library_routines.rst: Add note to section of Ada.Numerics.Discrete_Random and Ada.Numerics.Float_Random. * doc/gnat_rm/the_gnat_library.rst: Add note to section about GNAT.Random_Numbers. * libgnat/a-nudira.ads: Add note about cryptographic properties. * gnat_rm.texi: Regenerate. * gnat_ugn.texi: Regenerate.
2024-08-01ada: Fix computation of new size when reallocating unbounded stringYannick Moy1-1/+1
The procedure Realloc_For_Chunk which is used to reallocate an unbounded string when needed may lead in theory to an overflow, due to the use of variable S_Length denoting the current allocated length instead of Source.Last denoting the current string length. Now fixed. This has no effect in practice since the only targets that use this version of Ada.Strings.Unbounded do not have enough memory to make it possible to have an overflow here. gcc/ada/ * libgnat/a-strunb.adb (Realloc_For_Chunk): Fix computation of new size.
2024-08-01ada: Update contracts on Strings librariesYannick Moy3-29/+27
The contracts of Ada.Strings.Bounded.To_String and Ada.Strings.Fixed.Delete are updated to reflect the standard spec and to allow proof of callers. gcc/ada/ * libgnat/a-strbou.ads (To_String): Add a postcondition to state the value of bounds of the returned string, which helps with proof of callers. * libgnat/a-strfix.adb (Delete): Fix implementation to produce correct result in all cases. For example, returned string should always have a lower bound of 1, which was not respected in one case. This was not detected by proof, since this code was dead according to the too strict precondition. * libgnat/a-strfix.ads (Delete): State the correct precondition from standard which allows a value of Through beyond the last valid index, and also restricts values of From from below. Update the Contract_Cases accordingly to allow new values of parameters.
2024-08-01ada: Fix bug in resolution of Ghost_PredicateBob Duff2-1/+2
This patch fixes a failure of name resolution when a range attribute reference appears in a Ghost_Predicate and the ghost policy is Ignore. gcc/ada/ * sem_ch13.adb (Add_Predicate): Remove the premature "return;". Ghost code needs to be processed by later code in this procedure even when ignored; otherwise the second pass of name resolution fails much later. However, protect Set_SCO_Pragma_Enabled and Add_Condition with "if not Is_Ignored_Ghost_Pragma"; these parts should not happen if the ghost code is Ignored. * libgnat/interfac__2020.ads (Unsigned_8): Minor reformatting. * libgnat/interfac.ads (IEEE_Extended_Float): Minor comment improvement.
2024-08-01ada: Implement full relaxed finalization semantics for controlled objectsEric Botcazou2-15/+23
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: Remove obsolete workaroundEric Botcazou2-19/+0
It is possible to call the "+" operator of System.Storage_Elements directly as done for example in Expand_Interface_Thunk. gcc/ada/ * exp_ch7.adb (Make_Address_For_Finalize): Generate a direct call to the "+" operator of System.Storage_Elements. (Make_Finalize_Address_Stmts): Likewise. * rtsfind.ads (RE_Id): Remove RE_Add_Offset_To_Address. (RE_Unit_Table): Remove entry for RE_Add_Offset_To_Address. * libgnat/s-finpri.ads (Add_Offset_To_Address): Delete. * libgnat/s-finpri.adb (Add_Offset_To_Address): Likewise.
2024-06-27ada: Remove last uses of System.Address_Operations in runtime libraryEric Botcazou11-49/+64
This completes the switch from using System.Address_Operations to using only System.Storage_Elements in the runtime library. The remaining uses were for simple optimizations that can be done by the optimizer alone. gcc/ada/ * libgnat/s-carsi8.adb: Remove clauses for System.Address_Operations and use only operations of System.Storage_Elements for addresses. * libgnat/s-casi16.adb: Likewise. * libgnat/s-casi32.adb: Likewise. * libgnat/s-casi64.adb: Likewise. * libgnat/s-casi128.adb: Likewise. * libgnat/s-carun8.adb: Likewise. * libgnat/s-caun16.adb: Likewise. * libgnat/s-caun32.adb: Likewise. * libgnat/s-caun64.adb: Likewise. * libgnat/s-caun128.adb: Likewise. * libgnat/s-geveop.adb: Likewise.
2024-06-27ada: Implement first half of Generalized FinalizationEric Botcazou1-3/+7
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-13ada: Minor cleanups in generic formal matchingBob Duff3-3/+3
Minor rewording of a warning. Disallow positional notation for <> (but disable this check), and fix resulting errors. Copy use clauses. gcc/ada/ * sem_ch12.adb (Check_Fixed_Point_Actual): Minor rewording; it seems more proper to say "operator" rather than "operation". (Matching_Actual): Give an error for <> in positional notation. This is a syntax error. Disable this for now. (Analyze_Associations): Copy the use clause in all cases. The "mustn't recopy" comment seems wrong, because New_Copy_Tree preserves Slocs. * libgnat/a-ticoau.ads: Fix violation of new postion-box error. * libgnat/a-wtcoau.ads: Likewise. * libgnat/a-ztcoau.ads: Likewise.
2024-06-13ada: Streamline elaboration of local tagged typesEric Botcazou6-37/+223
This set of changes is aimed at streamlining the code generated for the elaboration of local tagged types. The dispatch tables and other related data structures are built dynamically on the stack for them and a few of the patterns used for this turn out to be problematic for the optimizer: 1. the array of primitives in the dispatch table is default-initialized to null values by calling the initialization routine of an unconstrained array type, and then immediately assigned an aggregate made up of the same null values. 2. the external tag is initialized by means of a dynamic concatenation involving the secondary stack, but all the elements have a fixed size. 3. the _size primitive is saved in the TSD by means of the dereference of the address of the TSD that was previously saved in the dispatch table. gcc/ada/ * Makefile.rtl (GNATRTL_NONTASKING_OBJS): Add s-imad32$(objext), s-imad64$(objext) and s-imagea$(objext). * exp_atag.ads (Build_Set_Size_Function): Replace Tag_Node parameter with Typ parameter. * exp_atag.adb: Add clauses for Sinfo.Utils. (Build_Set_Size_Function): Retrieve the TSD object statically. * exp_disp.adb: Add clauses for Ttypes. (Make_DT): Call Address_Image{32,64] instead of Address_Image. (Register_Primitive): Pass Tag_Typ to Build_Set_Size_Function. * rtsfind.ads (RTU_Id): Remove System_Address_Image and add System_Img_Address_{32;64}. (RE_Id): Remove entry for RE_Address_Image and add entries for RE_Address_Image{32,64}. * rtsfind.adb (System_Descendant): Adjust to above changes. * libgnat/a-tags.ads (Address_Array): Suppress initialization. * libgnat/s-addima.adb (System.Address_Image): Call the appropriate routine based on the address size. * libgnat/s-imad32.ads: New file. * libgnat/s-imad64.ads: Likewise. * libgnat/s-imagea.ads: Likewise. * libgnat/s-imagea.adb: Likewise. * gcc-interface/Make-lang.in (GNAT_ADA_OBJS) [$(STAGE1)=False]: Add ada/libgnat/s-imad32.o and ada/libgnat/s-imad64.o.
2024-06-13ada: Add support for symbolic backtraces with DLLs on WindowsEric Botcazou3-28/+29
This puts Windows on par with Linux as far as backtraces are concerned. gcc/ada/ * libgnat/s-tsmona__linux.adb (Get): Move down descriptive comment. * libgnat/s-tsmona__mingw.adb: Add with clause and use clause for System.Storage_Elements. (Get): Pass GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT in the call to GetModuleHandleEx and remove the subsequent call to FreeLibrary. Upon success, set Load_Addr to the base address of the module. * libgnat/s-win32.ads (GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS): Use shorter literal. (GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT): New constant.
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-06-10ada: Remove streaming facilities from generics for formal containersYannick Moy2-92/+0
The dependency on Ada.Streams is problematic for light runtimes. As these streaming facilities are in fact not used in formal containers, remove the corresponding dead code. gcc/ada/ * libgnat/a-chtgfo.adb (Generic_Read, Generic_Write): Remove. * libgnat/a-chtgfo.ads: Same. Remove dependency on Ada.Streams.
2024-06-10ada: Fix usage of SetThreadAffinityMaskRonan Desplanques1-1/+1
This patches fixes the signature of the binding to SetThreadAffinityMask in the run-time library. It also fixes the error checking after calls to SetThreadAffinityMask. The previous code behaved as if SetThreadAffinityMask returned 1 on success, but it in fact returns a pointer value on success and 0 on failure. gcc/ada/ * libgnarl/s-taprop__mingw.adb (Set_Task_Affinity): Fix usage of SetThreadAffinityMask. * libgnat/s-winext.ads (SetThreadAffinityMask): Fix binding signature.
2024-06-10ada: Remove incorrect assertion in run-timeRonan Desplanques1-11/+11
There is a special case of file paths on Windows that are absolute but don't start with a drive letter: UNC paths. This patch removes an assertion in System.OS_Lib.Normalize_Pathname that failed to take this case into account. It also renames a local subprogram of Normalize_Pathname to make its purpose clearer. gcc/ada/ * libgnat/s-os_lib.adb (Normalize_Pathname): Remove incorrect assert statement. (Missed_Drive_Letter): Rename into... (Drive_Letter_Omitted): This.
2024-05-21Fix Ada runtime library breakage on Solaris (bis)Eric Botcazou1-4/+1
Recent changes made to the runtime library broke again its build on Solaris because it uses Solaris threads instead of POSIX threads on this platform. gcc/ada/ PR ada/115168 * libgnarl/s-taprop__solaris.adb (Initialize): Fix pasto. * libgnat/s-oslock__solaris.ads (Owner_Int): Delete. (Owner_ID): Change the designated type to Integer.
2024-05-21ada: Add new Mingw task priority mappingJustin Squirek1-3/+24
This patch adds a new mapping (Non_FIFO_Underlying_Priorities) for dynamically setting task priorities in Windows when pragma Task_Dispatching_Policy (FIFO_Within_Priorities) is not present. Additionally, it documents the requirement to specify the pragma in order to use Set_Priority in the general case. gcc/ada/ * doc/gnat_ugn/platform_specific_information.rst: Add note about different priority level granularities under different policies in Windows and move POSIX related info into new section. * libgnarl/s-taprop.ads: Add note about Task_Dispatching_Policy. * libgnarl/s-taprop__mingw.adb: (Set_Priority): Add use of Non_FIFO_Underlying_Priorities. * libgnat/system-mingw.ads: Add documentation for modifying priority mappings and add alternative mapping Non_FIFO_Underlying_Priorities. * gnat_ugn.texi: Regenerate.
2024-05-20ada: Add direct workaround for limitations of RTSfind mechanismEric Botcazou1-8/+11
This adds a direct workaround for the spurious compilation errors caused by the presence of preconditions/postconditions in the Interfaces.C unit, which trip on limitations of the RTSfind mechanism when it comes to visibility, as well as removes an indirect workaround that was added very recently. These errors were first triggered in the context of finalization and worked around by preloading the System.Finalization_Primitives unit. Now they also appear in the context of tasking, and it turns out that the preloading trick does not work for separate compilation units. gcc/ada/ * exp_ch7.ads (Preload_Finalization_Collection): Delete. * exp_ch7.adb (Allows_Finalization_Collection): Revert change. (Preload_Finalization_Collection): Delete. * opt.ads (Interface_Seen): Likewise. * scng.adb (Scan): Revert latest change. * sem_ch10.adb: Remove clause for Exp_Ch7. (Analyze_Compilation_Unit): Revert latest change. * libgnat/i-c.ads: Use a fully qualified name for the standard "+" operator in the preconditons/postconditions of subprograms.
2024-05-20ada: Use System.Address for address computation in System.Pool_GlobalSebastian Poeplau1-3/+4
Some architectures don't let us convert System.Storage_Elements.Integer_Address back to a valid System.Address. Using the arithmetic operations on System.Address from System.Storage_Elements prevents the problem while leaving semantics unchanged. gcc/ada/ * libgnat/s-pooglo.adb (Allocate): Use arithmetic on System.Address to compute the aligned address.
2024-05-20ada: One more adjustment coming from aliasing considerationsEric Botcazou1-2/+5
It is needed on PowerPC platforms because of specific calling conventions. gcc/ada/ * libgnat/g-sothco.ads (In_Addr): Add aspect Universal_Aliasing.
2024-05-20ada: Small cleanup in System.Finalization_Primitives unitEric Botcazou2-24/+28
It has been made possible by recent changes. gcc/ada/ * libgnat/s-finpri.ads (Collection_Node): Move to private part. (Collection_Node_Ptr): Likewise. (Header_Alignment): Change to declaration and move completion to private part. (Header_Size): Likewise. (Lock_Type): Delete. (Finalization_Collection): Move Lock component and remove default value for Finalization_Started component. * libgnat/s-finpri.adb (Initialize): Reorder statements.
2024-05-18Fix Ada runtime library breakage on SolarisEric Botcazou1-3/+4
The recent changes made to the runtime library broke its build on Solaris because it uses Solaris threads instead of POSIX threads on this platform. gcc/ada/ PR ada/115133 * libgnarl/s-osinte__solaris.ads (mutex_t): Fix typo. * libgnarl/s-taprop__solaris.adb (Record_Lock): Add conversion. (Check_Sleep): Likewise. (Record_Wakeup): Likewise. (Check_Unlock): Likewise. * libgnarl/s-tasini.adb (Initialize_RTS_Lock): Add pragma Import on the overlaid variable. (Finalize_RTS_Lock): Likewise. (Acquire_RTS_Lock): Likewise. (Release_RTS_Lock): Likewise. * libgnarl/s-taspri__solaris.ads (To_RTS_Lock_Ptr): New instance of Ada.Unchecked_Conversion. * libgnat/s-oslock__solaris.ads: Add with clause for Ada.Unchecked_Conversion. (array_type_9): Add missing name qualification. (record_type_3): Likewise. (mutex_t): Fix formatting.
2024-05-17ada: Start the initialization of the tasking runtime earlierEric Botcazou1-1/+3
This installs the tasking versions of the RTS_Lock manipulation routines very early, before the elaboration of all the Ada units of the program, including those of the runtime, because this elaboration may require the initialization of RTS_Lock objects. gcc/ada/ * bindgen.adb (Gen_Adainit): Generate declaration and call to the imported procedure __gnat_tasking_runtime_initialize if need be. * libgnat/s-soflin.ads (Locking Soft-Links): Add commentary. * libgnarl/s-tasini.adb (Tasking_Runtime_Initialize): New procedure exported as __gnat_tasking_runtime_initialize. Initialize RTS_Lock manipulation routines here instead of... (Init_RTS): ...here.
2024-05-17ada: Further adjustments coming from aliasing considerationsEric Botcazou2-0/+14
They are needed on 32-bit platforms because of different calling conventions and again in the units implementing AltiVec and Streams support. gcc/ada/ * libgnat/g-alvevi.ads: Add pragma Universal_Aliasing for all the view types. * libgnat/s-stratt.ads: Likewise for Fat_Pointer type.
2024-05-17ada: Replace spinlocks with fully-fledged locks in finalization collectionsEric Botcazou9-12/+372
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: Do not query the modification time of a special file.Steve Baird1-2/+16
In Ada.Directories, the function Modification_Time raises Name_Error if it is called for a special file. So don't do that in Start_Search_Internal. gcc/ada/ * libgnat/a-direct.adb (Start_Search_Internal): Do not call Modification_Time for a special file; declare a Calendar.Time constant No_Time and use that instead.
2024-05-17ada: Couple of adjustments coming from aliasing considerationsEric Botcazou3-7/+61
The first adjustment is to the expansion of implementation types for array types with peculiar index types, for which the aliased property set on the component of the original type must be copied; the implicit base type also needs to be properly marked if the implementation type is constrained. The second adjustment is to selected types in the runtime, which need to be marked with pragma Universal_Aliasing because of their special usage. gcc/ada/ * exp_pakd.adb (Create_Packed_Array_Impl_Type): For non-bit-packed array types, propagate the aliased property of the component. (Install_PAT): Set fields on the implicit base type of an array. * libgnat/a-stream.ads (private part): Add pragma Universal_Aliasing for Stream_Element. * libgnat/g-alleve.ads: Add pragma Universal_Aliasing for all the vector types. * libgnat/g-alleve__hard.ads: Likewise.
2024-05-17ada: Fix containers' Reference_Preserving_Key functions' memory leaksSteve Baird6-2/+56
Fix memory leaks in containers' Reference_Preserving_Key functions Make the same change in each of 3 Ada.Containers child units: Ordered_Sets, Indefinite_Ordered_Sets, and Bounded_Ordered_Sets. The function Reference_Preserving_Key evaluates an allocator of type Key_Access whose storage was not being reclaimed. Update the Finalize procedure for type Reference_Control_Type to free that storage. But this change introduces a possible erroneous double-free situation if an object is copied (because the original and the copy will each be finalized at some point). So also introduce an Adjust procedure which allocates a copy of the allocated object. Another possible solution to this problem (which is not being implemented yet) is based on implementing AI22-0082. Also include a fix for a bug in Sem_Util.Has_Some_Controlled_Component that was discovered while working on this. gcc/ada/ * sem_util.adb (Has_Some_Controlled_Component): Fix a bug which causes (in some cases involving a Disable_Controlled aspect specification) Needs_Finalization to return different answers for one type depending on whether the function is called before or after the type is frozen. * libgnat/a-coorse.ads: Type Control_Reference_Type gets an Adjust procedure. * libgnat/a-cborse.ads: Likewise. * libgnat/a-ciorse.ads: Likewise * libgnat/a-coorse.adb: (Finalize): Reclaim allocated Key_Type object. (Adjust): New procedure; prevent sharing of non-null Key_Access values by allocating a copy. * libgnat/a-cborse.adb: Likewise. * libgnat/a-ciorse.adb: Likewise.
2024-05-16ada: Exception on Indefinite_Vector aggregate with loop_parameter_specificationGary Dismukes1-1/+1
Constraint_Error is raised on evaluation of a container aggregate with a loop_parameter_specification for the type Indefinite_Vector. This happens due to the Aggregate aspect for type Indefinite_Vector specifying the Empty_Vector constant for the type's Empty operation rather than using the type's primitive Empty function. This problem shows up as a recent regression relative to earlier compilers, evidently due to recent fixes in the container aggregate area, which uncovered this issue of the wrong specification in Ada.Containers.Indefinite_Vectors. The compiler incorrectly initializes the aggregate object using the Empty_Vector constant rather than invoking the New_Vector function to allocate the vector object with the appropriate number of elements, and subsequent calls to Replace_Element fail because the vector object is empty. In addition to correcting the Indefinite_Vectors generic package, checking is added to give an error for an attempt to specify the Empty operation as a constant rather than a function. (Also note that another AdaCore package that needs a similar correction is the VSS.Vector_Strings package.) gcc/ada/ * libgnat/a-coinve.ads (type Vector): In the Aggregate aspect for this type, the Empty operation is changed to denote the Empty function, rather than the Empty_Vector constant. * exp_aggr.adb (Expand_Container_Aggregate): Remove code for handling the case where the Empty_Subp denotes a constant object, which should never happen (and add an assertion that Empty_Subp must denote a function). * sem_ch13.adb (Valid_Empty): No longer allow the entity to be an E_Constant, and require the (optional) parameter of an Empty function to be of a signed integer type (rather than any integer type).
2024-05-16ada: Propagate Program_Error from failed finalization of collectionEric Botcazou1-6/+6
This aligns finalization collections with finalization masters when it comes to propagating an exception raised by the finalization of a specific object, by always propagating Program_Error instead of the aforementioned exception. gcc/ada/ * libgnat/s-finpri.adb (Raise_From_Controlled_Operation): New declaration of imported procedure moved from... (Finalize_Master): ...there. (Finalize): Call Raise_From_Controlled_Operation instead of Reraise_Occurrence to propagate the exception, if any.
2024-05-16ada: Minor performance improvement for dynamically-allocated controlled objectsEric Botcazou2-22/+6
The values returned by Header_Alignment and Header_Size are known at compile time and powers of two on almost all platforms, so inlining them by means of an expression function improves the object code generated for alignment and size calculations involving them. gcc/ada/ * libgnat/s-finpri.ads: Add use type clause for Storage_Offset. (Header_Alignment): Turn into an expression function. (Header_Size): Likewise. * libgnat/s-finpri.adb: Remove use type clause for Storage_Offset. (Header_Alignment): Delete. (Header_Size): Likewise.
2024-05-16ada: Fix latent alignment issue for dynamically-allocated controlled objectsEric Botcazou4-37/+66
Dynamically-allocated controlled objects are attached to a finalization collection by means of a hidden header placed right before the object, which means that the size effectively allocated must naturally account for the size of this header. But the allocation must also account for the alignment of this header in order to have it properly aligned. gcc/ada/ * libgnat/s-finpri.ads (Header_Alignment): New function. (Header_Size): Adjust description. (Master_Node): Put Finalize_Address as first component. (Collection_Node): Likewise. * libgnat/s-finpri.adb (Header_Alignment): New function. (Header_Size): Return the object size in storage units. * libgnat/s-stposu.ads (Adjust_Controlled_Dereference): Replace collection node with header in description. * libgnat/s-stposu.adb (Adjust_Controlled_Dereference): Likewise. (Allocate_Any_Controlled): Likewise. Pass the maximum of the specified alignment and that of the header to the allocator. (Deallocate_Any_Controlled): Likewise to the deallocator.
2024-05-16ada: Implement per-finalization-collection spinlocksEric Botcazou2-16/+75
This changes the implementation of finalization collections from using the global task lock to using per-collection spinlocks. Spinlocks are a good fit in this context because they are very cheap and therefore can be taken with a fine granularity only around the portions of code implementing the shuffling of pointers required by attachment and detachment actions. gcc/ada/ * libgnat/s-finpri.ads (Lock_Type): New modular type. (Collection_Node): Add Enclosing_Collection component. (Finalization_Collection): Add Lock component. * libgnat/s-finpri.adb: Add clauses for System.Atomic_Primitives. (Attach_Object_To_Collection): Lock and unlock the collection. Save a pointer to the enclosing collection in the node. (Detach_Object_From_Collection): Lock and unlock the collection. (Finalize): Likewise. (Initialize): Initialize the lock. (Lock_Collection): New procedure. (Unlock_Collection): Likewise.
2024-05-14ada: Decouple attachment from dynamic allocation for controlled objectsEric Botcazou4-193/+153
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: Correct System.Win32.LocalFileTimeToFileTime wrapper typoPhilippe Gil1-2/+2
The parameters should be swapped to fit Fileapi.h documentation. BOOL LocalFileTimeToFileTime( [in] const FILETIME *lpLocalFileTime, [out] LPFILETIME lpFileTime ); gcc/ada/ * libgnat/s-win32.ads (LocalFileTimeToFileTime): Swap parameters.
2024-05-13ada: Rename finalization scope masters into finalization mastersEric Botcazou2-9/+9
Now that what was previously called "finalization master" has been renamed into "finalization collection" in the front-end, we can also rename what was initially called "finalization scope master" into "finalization master". These entities indeed drive the finalization of all the objects that require it, directly for (statically) declared objects or indirectly for dynamically allocated objects (that is to say, through finalization collections). gcc/ada/ * exp_ch7.adb: Adjust the description of finalization management. (Build_Finalizer): Rename scope master into master throughout. * rtsfind.ads (RE_Id): Replace RE_Finalization_Scope_Master with RE_Finalization_Master. (RE_Unit_Table): Replace entry for RE_Finalization_Scope_Master with entry for RE_Finalization_Master. * libgnat/s-finpri.ads (Finalization_Scope_Master): Rename into... (Finalization_Master): ...this. (Attach_Object_To_Master): Adjust to above renaming. (Chain_Node_To_Master): Likewise. (Finalize_Master): Likewise. * libgnat/s-finpri.adb (Attach_Object_To_Master): Likewise. (Chain_Node_To_Master): Likewise. (Finalize_Master): Likewise.
2024-05-13ada: Remove dynamic frame in System.Image_D and document it in System.Image_FEric Botcazou6-8/+70
The former can easily be removed while the latter cannot. gcc/ada/ * libgnat/s-imaged.ads (System.Image_D): Add Uns formal parameter. * libgnat/s-imaged.adb: Add with clauses for System.Image_I, System.Value_I_Spec and System.Value_U_Spec. (Uns_Spec): New instance of System.Value_U_Spec. (Int_Spec): New instance of System.Value_I_Spec. (Image_I): New instance of System.Image_I. (Set_Image_Integer): New renaming. (Set_Image_Decimal): Replace 'Image with call to Set_Image_Integer. * libgnat/s-imde32.ads (Uns32): New subtype. (Impl): Pass Uns32 as second actual paramter to Image_D. * libgnat/s-imde64.ads (Uns64): New subtype. (Impl): Pass Uns64 as second actual paramter to Image_D. * libgnat/s-imde128.ads (Uns128): New subtype. (Impl): Pass Uns128 as second actual paramter to Image_D. * libgnat/s-imagef.adb (Set_Image_Fixed): Document bounds for the A, D and AF local constants.
2024-05-13ada: Couple of comment tweaks to latest changeEric Botcazou2-13/+16
This replaces a few remaining references to "master" by "collection" and makes a couple of additional tweaks in comments. gcc/ada/ * libgnat/s-finpri.adb (Finalize): Replace "master" by "collection" in comments and add a comment about the form of the loop. * libgnat/s-stposu.adb (Allocate_Any_Controlled): Tweak comment.
2024-05-13ada: Replace finalization masters with finalization collectionsEric Botcazou8-578/+369
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-13ada: Remove deprecated VxWorks interrupt connection APIAshley Gay2-223/+1
The VxWorks 7 API to use hardware interrupts is the VxBus subsystem. GNAT API still provides bindings for the deprecated (VxWorks 6) routines. A direct consequence of this change is that Attach_Handler cannot be used anymore (the VxBus subsystem should be used instead). This patch removes all the functions that are not supported by VxWorks 7 anymore. To warn for the usage of Attach_Handler, it adds the 'Obsolescent' pragma to to this routine so the comiler will advise the user if this function is called directly or through a pragma. gcc/ada/ * Makefile.rtl: remove i-vxinco.* from the build * doc/gnat_rm/the_gnat_library.rst: Remove i-vxinco.ads from the units documentation. * impunit.adb: Remove i-vxinco from the list of available units in GNATstudio. * libgnarl/i-vxinco.adb: Remove. * libgnarl/i-vxinco.ads: Ditto. * libgnarl/s-interr__vxworks.adb: enrich comment * libgnarl/s-vxwext__kernel.ads: fix comment * libgnat/i-vxwork.ads: Remove deprecated interrupt connections API, as well as an example. * libgnat/i-vxwork__x86.ads: Ditto and add the paragma Obscolescent to Attach_Handler * gnat_rm.texi: Regenerate.
2024-05-13ada: Decouple finalization masters from storage poolsEric Botcazou2-52/+0
The coupling came from the build-in-place protocol but is now unnecessary because the storage pool reference is always passed along with the master reference in this protocol. No functional changes. gcc/ada/ * exp_ch3.adb (Build_Heap_Or_Pool_Allocator): Use the BIPstoragepool formal parameter to retrieve the pool in the presence of a master. * exp_ch6.adb (Make_Build_In_Place_Call_In_Allocator): Always pass a pool reference along with the master reference. (Make_Build_In_Place_Call_In_Object_Declaration): Likewise. * exp_ch7.adb (Build_BIP_Cleanup_Stmts): Use the BIPstoragepool formal parameter to retrieve the pool in the presence of a master. (Create_Anonymous_Master): Do not call Set_Base_Pool. (Build_Finalization_Master): Likewise. * rtsfind.ads (RE_Id): Remove RE_Base_Pool and RE_Set_Base_Pool. (RE_Unit_Table): Remove associated entries. * libgnat/s-finmas.ads: Remove clause for System.Storage_Pools. (Any_Storage_Pool_Ptr): Delete. (Finalization_Master): Remove Base_Pool component. (Base_Pool): Delete. (Set_Base_Pool): Likewise. * libgnat/s-finmas.adb (Base_Pool): Likewise. (Set_Base_Pool): Likewise. (Print_Master): Do not print Base_Pool.