aboutsummaryrefslogtreecommitdiff
path: root/gcc/ada/sem_ch6.adb
AgeCommit message (Collapse)AuthorFilesLines
2025-11-27ada: Couple of small and unrelated cleanupsEric Botcazou1-9/+3
No functional changes. gcc/ada/ChangeLog: * exp_ch11.adb (Expand_N_Handled_Sequence_Of_Statement): Merge the eslif condition with the if condition for cleanup actions. * sem_ch6.adb (Analyze_Procedure_Call.Analyze_Call_And_Resolve): Get rid of if statement whose condition is always true. * sinfo.ads (Finally_Statements): Document their purpose.
2025-11-27ada: Streamline implementation of masters in Exp_Ch9Eric Botcazou1-34/+19
The incidental discovery of an old issue and its resolution has exposed the convoluted handling of masters in Exp_Ch9, which uses two totally different approaches to achieve the same goal, respectively in Build_Master_Entity and Build_Class_Wide_Master, the latter being quite hard to follow. The handling of activation chains for extended return statements is also a bit complex. This gets rid of the second approach entirely for masters, as well as makes the handling of activation chains uniform for all nodes. No functional changes. gcc/ada/ChangeLog: * gen_il-gen-gen_nodes.adb (N_Extended_Return_Statement): Add Activation_Chain_Entity semantic field. * exp_ch3.adb (Build_Master): Use Build_Master_{Entity,Renaming} in all cases. (Expand_N_Object_Declaration): Small tweak. * exp_ch6.adb (Make_Build_In_Place_Iface_Call_In_Allocator): Use Build_Master_{Entity,Renaming} to build the master. * exp_ch7.adb (Expand_N_Package_Declaration): Do not guard the call to Build_Task_Activation_Call for the sake of consistency. * exp_ch9.ads (Build_Class_Wide_Master): Delete. (Find_Master_Scope): Likewise. (Build_Protected_Subprogram_Call_Cleanup): Move to... (First_Protected_Operation): Move to... (Mark_Construct_As_Task_Master): New procedure. * exp_ch9.adb (Build_Protected_Subprogram_Call_Cleanup): ...here. (First_Protected_Operation): ...here. (Build_Activation_Chain_Entity): Streamline handling of extended return statements. (Build_Class_Wide_Master): Delete. (Build_Master_Entity): Streamline handling of extended return statements and call Mark_Construct_As_Task_Master on the context. (Build_Task_Activation_Call): Assert that the owner is not an extended return statement. (Find_Master_Scope): Delete. (Mark_Construct_As_Task_Master): New procedure. * sem_ch3.adb (Access_Definition): Use Build_Master_{Entity,Renaming} in all cases to build a master. * sem_ch6.adb (Check_Anonymous_Return): Rename to... (Check_Anonymous_Access_Return_With_Tasks): ...this. At the end, call Mark_Construct_As_Task_Master on the parent node. (Analyze_Subprogram_Body_Helper): Adjust to above renaming. (Create_Extra_Formals): Do not set Has_Master_Entity here. * sinfo.ads (Activation_Chain_Entity): Adjust description.
2025-11-21ada: No extra formals on anonymous access types of C subprogramsJavier Miranda1-0/+11
Extra formals must not be added to anonymous access to subprogram types defined in the profile of imported C subprograms. gcc/ada/ChangeLog: * sem_ch6.adb (Create_Extra_Formals): Do not add extra formals to anonymous access to subprogram types defined in the profile of subprograms that have foreign convention.
2025-11-18ada: Enforce checks on access to interface type conversionsJavier Miranda1-0/+2
The patch enforces checks on access to interface type conversions internally generated by the frontend to displace the pointer to a tagged type object (pointer named "this" in the C++ terminology) from a dispatch table to a another dispatch table. gcc/ada/ChangeLog: * exp_util.ads (Flag_Interface_Pointer_Displacement): New subprogram. * exp_util.adb (Flag_Interface_Pointer_Displacement): Ditto. * exp_attr.adb (Add_Implicit_Interface_Type_Conversion): Flag type conversions internally added to displace the pointer to the object. (Expand_N_Attribute_Reference): Ditto. * exp_ch4.adb (Displace_Allocator_Pointer): Ditto. * exp_ch6.adb (Expand_Simple_Function_Return): Ditto. (Make_Build_In_Place_Call_In_Allocator): Ditto. (Make_CPP_Constructor_Call_In_Allocator): Ditto. * exp_disp.adb (Expand_Interface_Actuals): Ditto. * exp_intr.adb (Expand_Dispatching_Constructor_Call): Ditto. * sem_ch6.adb (Analyze_Function_Return): Ditto. * sem_disp.adb (Propagate_Tag): Ditto. * sem_res.adb (Resolve_Actuals): Ditto. (Valid_Conversion): Rely on the new flag to handle the type conversion as a conversion added to displace the pointer to the object. Factorize code handling general and anonymous access types. * sem_type.adb (Interface_Present_In_Ancestor): For concurrent types add missing handling of class-wide types. Noticed working on this issue. * sinfo.ads (Is_Interface_Pointer_Displacement): Document this new flag. * gen_il-fields.ads (Is_Interface_Pointer_Displacement): New flag. * gen_il-gen-gen_nodes.adb (Is_Interface_Pointer_Displacement): New flag on N_Type_Conversion nodes. * gen_il-internals.adb (Image): Add Is_Interface_Pointer_Displacement flag image.
2025-11-18ada: Fix bogus error about null exclusion for designated type with multiple ↵Eric Botcazou1-1/+1
views It comes from the new legality check retroactively introduced by AI12-0289, but the implementation is fooled by the presence of both an incomplete and a partial view for a tagged type. gcc/ada/ChangeLog: PR ada/111433 * sem_util.ads (Incomplete_Or_Partial_View): Add Partial_Only formal parameter. * sem_util.adb (Incomplete_Or_Partial_View): Likewise. Do not look for an incomplete view if it is set to True. * sem_ch6.adb (Check_Conformance.Null_Exclusions_Match): Pass True for Partial_Only in the call to Incomplete_Or_Partial_View.
2025-11-18ada: Add rule check for call argumentsViljar Indus1-0/+1
Implement SPARK RM 6.9(18). If an assignment to a part of a ghost variable occurs in a ghost entity, then the variable should be assertion-level-dependent on this entity. [This includes both assignment statements and passing a ghost variable as an out or in out mode actual parameter.] gcc/ada/ChangeLog: * ghost.adb (Check_Procedure_Call_Levels): New function for implementing the check. * ghost.ads (Check_Procedure_Call_Levels): Likewise. * sem_ch6.adb (Analyze_Procedure_Call): Check the levels after the call has been resolved and the previous ghost region has been restored.
2025-11-18ada: Reserve Is_Constructor for Ada constructorsDenis Mazzucato1-0/+1
This patch renames old Is_Constructor to a new Is_CPP_Constructor and reserves Is_Constructor for Ada constructors. gcc/ada/ChangeLog: * sem_util.adb (Is_Constructor_Procedure): Replace by Is_Constructor. * sem_util.ads: Likewise. * sem_ch6.adb (Analyze_Direct_Attribute_Definition): Set Is_Constructor. * einfo.ads: Use Is_Constructor for Ada constructors, and Is_CPP_Constructor for CPP constructors. * exp_ch6.adb: Likewise. * exp_disp.adb: Likewise. * freeze.adb: Likewise. * gen_il-fields.ads: Likewise. * gen_il-gen-gen_entities.adb: Likewise. * gen_il-internals.adb: Likewise. * par-ch6.adb: Likewise. * sem_prag.adb: Likewise. * treepr.adb: Likewise.
2025-11-03ada: Avoid Ignored ghost code behavior in Codepeer_ModeViljar Indus1-2/+5
When the frontend is called by it should treat all ghost code as checked. Avoid removing expansion in ignored ghost code regions when Codepeer_Mode is active. gcc/ada/ChangeLog: * sem_ch6.adb (Analyze_Subprogram_Body_Helper): Avoid disabling the expander for ignored ghost regions if Codepeer_Mode is active. * sem_ch7.adb (Analyze_Package_Body_Helper): Likewise. * freeze.adb (Freeze_Entity): Avoid triggering special freezing action for entities within ignored ghost regions in Codepeer_Mode.
2025-11-03ada: Direct attribute definition for constructorsDenis Mazzucato1-83/+91
This patch introduces the 'Constructor attribute and implements its direct attribute definition syntax within subprogram specification. This new shorthand avoids having to come up with an arbitrary subprogram name and to type out the constructor aspect. Before, constructors where defined through the aspect Constructor, which has been removed. Furthermore, this patch prepares for the expansion of direct attribute definitions to other attributes. gcc/ada/ChangeLog: * errout.adb (Set_Msg_Node): Support N_Attribute_Reference and nodes that denotes direct attribute definitions. * exp_dbug.ads: Description for the encoding of direct attribute definitions as tick are hard to deal in entity names. * erroutc.adb (Set_Msg_Insertion_Name): Replace underscore between prefix and attribute name in direct attribute definitions; at this point we lost the semantic information of node type and we resort to match the string name as described in exp_dbug.adb. * exp_aggr.adb (Convert_To_Positional): Use Needs_Construction and Has_Default_Constructor. * exp_ch3.adb (Build_Record_Init_Proc) (Expand_N_Object_Declaration): Likewise. * exp_attr.adb (Expand_N_Attribute_Reference): Likewise. * exp_ch4.adb (Expand_N_Allocator): Likewise. * exp_ch6.adb (Prepend_Constructor_Procedure_Prologue): Use Is_Constructor_Procedure. (Make_Parent_Constructor_Call): Use Direct_Attribute_Definition_Name. * gen_il-fields.ads: Remove Constructor_List and Constructor_Name. * gen_il-gen-gen_entities.adb: Likewise. * einfo.ads (Needs_Construction): Add description. (Has_Delayed_Aspects): Adjust indentation. * par-ch13.adb (P_Attribute_Designators): Parse attribute designators. (P_Representation_Clause): Use P_Attribute_Designators. * par-ch6.adb (P_Subprogram): Support attribute designators in subprogram name. (Rewrites_Entity_If_Direct_Attribute_Def): Fix the specification node in case of direct attribute definitions. * par-endh.adb (Check_End, Same_Label): Likewise. * par.adb (P_Attribute_Designators): Specification. * sem_attr.adb (Analyze_Attribute): Error when using 'Constructor outside procedure specification. (Analyze_Attribute): Add error handling code. * sem_ch3.adb (Analyze_Aspect_Specifications): Likewise. * sem_ch6.adb (Analyze_Direct_Attribute_Definition): Handle direct attribute definitions. Add error handling code for the 'Construction attribute and set constructor flags when necessary. (Analyze_Subprogram_Specification): Use Analyze_Direct_Attribute_Definition. * sem_util.adb (Direct_Attribute_Definition_Name): Name of entities created for direct attribute definitions. We emit an error if multiple attributes. (Is_Direct_Attribute_Subp_Spec): Helper to check whether a subprogram specification is a direct attribute definition. (Is_Constructor_Procedure): Helper to check whether a subprogram is a constructor procedure. (Has_Default_Constructor): Check whether the default constructor exists. (Default_Constructor): Not used anymore. (Parameter_Count): Likewise. (Process_End_Label): Get_Attribute_Reference_Name_String encodes also direct attribute definition end labels. * sem_util.ads: Likewise. * snames.ads-tmpl: Support for 'Constructor attribute. * snames.adb-tmpl (Is_Direct_Attribute_Definition_Name): Helper to check attributes allowed in direct attribute definitions. * aspects.ads: Remove constructor aspect. * sem_ch13.adb: Likewise.
2025-09-15ada: Update ghost code SPARK RM rulesViljar Indus1-7/+7
gcc/ada/ChangeLog: * contracts.adb: Update SPARK RM reference numbers. * freeze.adb: Likewise. * ghost.adb: Likewise. * ghost.ads: Likewise. * sem_ch12.adb: Likewise. * sem_ch3.adb: Likewise. * sem_ch6.adb: Likewise. * sem_prag.adb: Likwise. * sem_res.adb: Likewise.
2025-09-15ada: Avoid ghost context check in early freezeViljar Indus1-0/+9
We freeze the expression for expression functions that complete before we have set up the ghost region from both the existing spec and body. Avoid triggering the ghost context checks during the analysis for this early freeze as the expression will be reanalyzed when we analyze the new function body created for the expression function. gcc/ada/ChangeLog: * sem_ch6.adb (Analyze_Expression_Function): Disable ghost checks during the early freeze.
2025-09-09ada: Update the uses of Is_Ignored*_In_CodegenViljar Indus1-2/+3
Replace calls to Is_Ignored_Ghost_Entity and Predicates_Ignored with their In_Codegen versions in places where we would analyze those nodes differently from checked nodes. Describe the motive and use cases for those In_Codegen functions. gcc/ada/ChangeLog: * contracts.adb: Use the In_Codegen function instead. * exp_ch3.adb: Likewise. * exp_ch5.adb: Likewise. * exp_ch6.adb: Likewise. * exp_ch7.adb: Likewise. * exp_ch9.adb: Likewise. * exp_disp.adb: Likewise. * exp_util.adb: Likewise. * freeze.adb: Likewise. * ghost.adb: Likewise. * inline.adb: Likewise. * repinfo.adb: Likewise. * sem_ch10.adb: Likewise. * sem_ch13.adb: Likewise. * sem_ch3.adb: Likewise. * sem_ch6.adb: Likewise. * sem_elab.adb: Likewise. * sem_res.adb: Likewise. * sem_util.adb (Predicates_Ignored_In_Codegen): Add new function for the Predicates_Ignored property. (Predicates_Enabled): Use Predicates_Ignored_In_Codegen instead. * sem_util.ads (Predicates_Ignored_In_Codegen): New function. (Is_Ignored_In_Codegen): Add documentation on how _In_Codegen functions should be used.
2025-09-09ada: Adding support to defer the addition of extra formals (part 2)Javier Miranda1-14/+27
Adjust previous patch to improve the support for AI05-0151-1/08. gcc/ada/ChangeLog: * exp_attr.adb (Rewrite_Attribute_Proc_Call): Add new parameter to calls to Create_Extra_Formals. (Expand_N_Attribute_Reference): Ditto. * exp_ch3.adb (Expand_Freeze_Record_Type): Ditto. * exp_ch6.adb (Expand_Call_Helper): Ditto. * exp_disp.adb (Expand_Dispatching_Call): Ditto. * freeze.adb (Check_Itype): Ditto. (Freeze_Expression): Ditto. * sem_ch6.adb (Analyze_Subprogram_Body_Helper): Ditto. (Create_Extra_Formals): Add new formal, and use it to determine if the creation of the extra formals can be deferred. Add the new parameter to calls to Create_Extra_Formals. (Is_Unsupported_Extra_Actuals_Call): Adjust the code to improve its performance when the result is known. (Is_Unsupported_Extra_Formals_Entity): Ditto. Add new formal * sem_ch6.ads (Create_Extra_Formals): Add new formal. (Is_Unsupported_Extra_Formals_Entity): Ditto.
2025-09-09ada: Fix inheritance of Is_Primitive and legality check for nonoverridable ↵Denis Mazzucato1-8/+11
aspects This patch fixes the identification of inherited subprograms as primitive operations via the Is_Primitive flag. This is essential in the context of the new legality check which makes sure that, if any subprogram denoted by a nonoverridable aspect of a type T with formal or return of either type T or access T, then all denoted subprograms should be primitive operations. Note that all valid interpretations of a subprogram are denoted by the aspect under evaluation, all of these needs to be primitive then. This is a respin of eng/toolchain/gnat!2039 gcc/ada/ChangeLog: * sem_ch13.adb (Check_Nonoverridable_Aspect_Subprograms): Add the new legality check in Check_Nonoverridable_Aspect_Subprograms for nonoverridable aspects to check whether the denoted subprograms satisfy MR 13.1.1(18.4/6), otherwise we emit an error. Fix spacing. * sem_ch6.adb (New_Overloaded_Entity): Set Is_Primitive flag for inherited primitives, and filter out homonym candidates without a function specification as parents.
2025-08-04ada: Keep Ghost_Mode related variables in a recordViljar Indus1-11/+8
Simplify the storing process for ghost mode related variables and make the process more extendable if new ghost mode related features are added. gcc/ada/ChangeLog: * atree.adb: update references to Ghost_Mode. * exp_ch3.adb: use a structure type to store all of the existing ghost mode related state variables. * exp_disp.adb: Likewise. * exp_spark.adb: Likewise. * exp_util.adb: Likewise. * expander.adb: Likewise. * freeze.adb: Likewise and replace references to existing ghost mode variables. * ghost.adb (Install_Ghost_Region): install the changes of the region in to the new Ghost_Config structure. (Restore_Ghost_Region): Use the new Ghost_Config instead. In general replace all references to the existing ghost mode variables with the new structure equivalent. * ghost.ads (Restore_Ghost_Region): update the spec. * opt.ads (Ghost_Config_Type): A new type that has two of the previous ghost code related global variables as memembers - Ghost_Mode and Ignored_Ghost_Region. (Ghost_Config) New variable to store the previous Ghost_Mode and Ignored_Ghost_Region info. * rtsfind.adb: Replace references to existing ghost mode variables. * sem.adb: Likewise. * sem_ch12.adb: Likewise. * sem_ch13.adb: Likewise. * sem_ch3.adb: Likewise. * sem_ch5.adb: Likewise. * sem_ch6.adb: Likewise. * sem_ch7.adb: Likewise. * sem_prag.adb: Likewise. * sem_util.adb: Likewise.
2025-07-22ada: Fix crash when creating extra formals for aliased typesDenis Mazzucato1-3/+4
This patch makes sure that we return the same decision for all aliased types when checking if the BIP task extra actuals are needed. gcc/ada/ChangeLog: * sem_ch6.adb (Might_Need_BIP_Task_Actuals): Before retrieving the original corresponding operation we retrieve first the root of the aliased chain.
2025-07-22ada: Fix unnecessary extra RE_Activation_Chain_Access with No_Task_PartsDenis Mazzucato1-11/+27
This patch checks the presence of No_Task_Parts on any ancestor or inherited interface, not only its root type, since No_Task_Parts prohibits tasking for any of its descendant. In case the current subprogram is overridden/inherited, we need to return the same value we would return for the original corresponding operation. The aspect No_Task_Parts is nonoverridable and applies also when specified in a partial view. gcc/ada/ChangeLog: * sem_ch6.adb (Might_Need_BIP_Task_Actuals): Check whether No_Task_Parts is enabled in any of the derived types, or interfaces, from the user-defined primitive return type. * sem_ch13.adb (Analyze_Aspect_Specifications): Add No_Task_Parts and No_Controlled_Parts to the representation chain to be visible in the full view of private types. * aspects.ads (Nonoverridable_Aspect_Id): As per GNAT RM, No_Task_Parts is nonoverridable. * sem_util.adb (Check_Inherited_Nonoverridable_Aspects): Likewise. * sem_util.ads: Fix typo and style. * sem_disp.adb: Missing comment.
2025-07-22ada: Adding support to defer the addition of extra formalsJavier Miranda1-46/+701
Add support to create the extra formals when the underlying type of some formal type or return type of a subprogram, subprogram type or entry is not available when the entity is frozen. For example, when a function that returns a private type is frozen before the full-view of its private type is analyzed. gcc/ada/ChangeLog: * einfo.ads (Extra_Formals): Complete documentation. (Has_First_Controlling_Parameter_Aspect): Place it in alphabetical order. (Has_Frozen_Extra_Formals): New attribute. * gen_il-fields.ads (Has_Frozen_Extra_Formals): New entity field. * gen_il-gen-gen_entities.adb (Has_Frozen_Extra_Formals): Adding new entity flag to subprograms, subprogram types, and and entries. * gen_il-internals.adb (Image): Adding Has_Frozen_Extra_Formals. * exp_ch3.adb (Build_Array_Init_Proc): Freeze its extra formals. (Build_Init_Procedure): Freeze its extra formals. (Expand_Freeze_Record_Type): For tagged types with foreign convention create the extra formals of primitives with convention Ada. * exp_ch6.ads (Create_Extra_Actuals): New subprogram. * exp_ch6.adb (Check_BIP_Actuals): Adding assertions. (Create_Extra_Actuals): New subprogram that factorizes code from Expand_Call_Helper. (Expand_Call_Helper): Adding support to defer the addition of extra actuals. Move the code that adds the extra actuals to a new subprogram. (Is_Unchecked_Union_Equality): Renamed as Is_Unchecked_Union_Predefined_ Equality_Call. * exp_ch7.adb (Create_Finalizer): Freeze its extra formals. (Wrap_Transient_Expression): Link the temporary with its relocated expression to facilitate locating the expression in the expanded code. * exp_ch9.ads (Expand_N_Entry_Declaration): Adding one formal. * exp_ch9.adb (Expand_N_Entry_Declaration): Defer the expansion of the entry if the extra formals are not available; analyze the built declarations for the record type that holds all the parameters if the expansion of the entry declaration was deferred. * exp_disp.adb (Expand_Dispatching_Call): Handle deferred extra formals. (Set_CPP_Constructors): Freeze its extra formals. * freeze.adb (Freeze_Entity): Create the extra actuals of acccess to subprograms whose designated type is a subprogram type. (Freeze_Subprogram): Adjust assertion to support deferred extra formals, and freeze extra formals of non-dispatching subprograms with foreign convention. Added assertion to check matching of formals in thunks. * sem_aux.adb (Get_Called_Entity): Adding documentation. * sem_ch3.adb (Analyze_Full_Type_Declaration): Create the extra formals of deferred subprograms, subprogram types and entries; create also the extra actuals of deferred calls. * sem_ch6.ads (Freeze_Extra_Formals): New subprogram. (Deferred_Extra_Formals_Support): New package. * sem_ch6.adb (Analyze_Subprogram_Body_Helper): Create the extra formals of subprograms without separate spec. (Add_Extra_Formal): Add documentation. (Has_Extra_Formals): Removed. (Parent_Subprogram): Adding documentation. (Create_Extra_Formals): Defer adding extra formals if the underlying_type of some formal type or return type is not available. (Extra_Formals_Match_OK): Add missing check on the extra formals of unchecked unions. (Freeze_Extra_Formals): New subprogram. (Deferred_Extra_Formals_Support): New package. * sem_ch9.adb (Analyze_Entry_Declaration): Freeze its extra formals. * sem_ch13.adb (New_Put_Image_Subprogram): ditto. * sem_util.ads (Is_Unchecked_Union_Equality): New subprogram. * sem_util.adb (Is_Unchecked_Union_Equality): ditto.
2025-07-18ada: Incorrect resolution of prefixed calls with overriding private subprogramGary Dismukes1-28/+63
The compiler incorrectly treats an overriding private subprogram that should not be visible outside a package (because it only overrides in the private part) as a possible interpretation for a call using prefixed notation outside of the package. This can result in an ambiguity if there is another subprogram with the same name but a different profile declared in the visible part of the package, or can result in resolving to the private operation in cases where it shouldn't resolve. This happens due to the compiler improperly concluding that the private overriding subprogram overrides an inherited subprogram in the package visible part, even though the only inherited subprogram is in the private part, as a result of a misuse of the Overridden_Operation field, which, contrary to what its name suggests, actually refers to operations of the parent type, rather than to the operations derived from the parent's operations. gcc/ada/ChangeLog: * einfo.ads: Document new field Overridden_Inherited_Operation and list it as a field for the entity kinds that it applies to. * gen_il-fields.ads (type Opt_Field_Enum): Add new literal Overridden_Inherited_Operation to the type. * gen_il-gen-gen_entities.adb: Add Overridden_Inherited_Operation as a field of entities of kinds E_Enumeration_Literal and Subprogram_Kind. * sem_ch4.adb (Is_Callable_Private_Overriding): Change name (was Is_Private_Overriding). Replace Is_Hidden test on Overridden_Operation with test of Is_Hidden on the new field Overridden_Inherited_Operation. * sem_ch6.adb (New_Overloaded_Entity): Set the new field Overridden_Inherited_Operation on an operation derived from an interface to refer to the inherited operation of a private extension that's overridden by the derived operation. Also set that field in the more common cases of an explicit subprogram that overrides, to refer to the inherited subprogram that is overridden. (Contrary to its name, the Overridden_Operation field of the overriding subprogram, which is also set in these places, refers to the *parent* subprogram from which the inherited subprogram is derived.) Also, remove a redundant Present (Alias (S)) test in an if_statement and the dead "else" part of that statement.
2025-07-03ada: Remove unnecessary "return;" statementsBob Duff1-1/+0
A "return;" at the end of a procedure is unnecessary and misleading. This patch removes them. gcc/ada/ChangeLog: * checks.adb: Remove unnecessary "return;" statements. * eval_fat.adb: Likewise. * exp_aggr.adb: Likewise. * exp_attr.adb: Likewise. * exp_ch3.adb: Likewise. * exp_ch4.adb: Likewise. * exp_ch5.adb: Likewise. * exp_ch6.adb: Likewise. * exp_unst.adb: Likewise. * krunch.adb: Likewise. * layout.adb: Likewise. * libgnat/s-excdeb.adb: Likewise. * libgnat/s-trasym__dwarf.adb: Likewise. * par-endh.adb: Likewise. * par-tchk.adb: Likewise. * sem.adb: Likewise. * sem_attr.adb: Likewise. * sem_ch6.adb: Likewise. * sem_elim.adb: Likewise. * sem_eval.adb: Likewise. * sfn_scan.adb: Likewise.
2025-06-30ada: Fix crash on nested access-to-subprogram typesRonan Desplanques1-6/+7
This patch fixes a crash on some subprograms with anonymous access-to-subprogram parameters by removing delayed freezing of subprograms in some cases where it wasn't necessary. The -gnatD output for itypes is also improved. gcc/ada/ChangeLog: * sem_ch6.adb (Check_Delayed_Subprogram, Possible_Freeze): Restrict cases where freezing is delayed. * sem_ch6.ads (Check_Delayed_Subprogram): Improve documentation comment. * sprint.adb (Write_Itype): Improve output.
2025-06-10ada: Move Check_Discriminant_Conformance to Sem_Ch3Ronan Desplanques1-243/+0
Check_Discriminant_Conformance is really only about concepts defined in chapter 3 of the Ada reference manual, so it fits better in Sem_Ch3 than in Sem_Ch6. gcc/ada/ChangeLog: * sem_ch6.adb, sem_ch6.ads (Check_Discriminant_Conformance): Move to … * sem_ch3.adb (Check_Discriminant_Conformance): … here.
2025-06-09ada: Call Mutate_Ekind earlier for formal entitiesRonan Desplanques1-55/+52
This patch migrates the handling of "premature usage" type of error to the Is_Self_Hidden mechanism. gcc/ada/ChangeLog: * sem_ch6.adb (Set_Formal_Mode): Extend profile. Move parts of the body… (Process_Formals): … here. Move call to Set_Formal_Mode earlier. Call Set_Is_Not_Self_Hidden in second traversal.
2025-06-06ada: Add new aspect Program_Exit for SPARKPiotr Trojanek1-1/+1
A new aspect Program_Exit is added for SPARK to specify that a subprogram can exit the entire program, e.g. GNAT.System.OS_Exit. The implementation is based on the existing machinery for similar aspects, in particular, for aspects Subprogram_Variant and Always_Terminates. gcc/ada/ChangeLog: * aspects.ads (Aspect_Id): Add new aspect identifier. (Aspect_Argument): Specify argument for the new aspect. (Is_Representation_Aspect): New aspect is not a representation aspect. (Aspect_Names): Map new aspect to name. (Aspect_Delay): New aspect is always delayed. * contracts.adb (Expand_Subprogram_Contract) (Add_Pre_Post_Condition, Add_Contract_Item) (Analyze_Entry_Or_Subprogram_Contract) (Analyze_Entry_Or_Subprogram_Body_Contract) (Analyze_Subprogram_Body_Stub_Contract): Support new aspect. * contracts.ads (Add_Contract_Item, Analyze_Entry_Or_Subprogram_Contract, Analyze_Entry_Or_Subprogram_Body_Contract, Analyze_Subprogram_Body_Stub_Contract): Mention new contract in comment. * doc/gnat_rm/implementation_defined_aspects.rst (Aspect Program_Exit): Document new aspect. * doc/gnat_rm/implementation_defined_pragmas.rst (Pragma Program_Exit): Document new pragma. * einfo-utils.adb (Get_Pragma): Support new pragma. * einfo-utils.ads (Get_Pragma): Mention new pragma in comment. * exp_prag.adb (Expand_Pragma_Program_Exit): Expand new pragma; body. * exp_prag.ads (Expand_Pragma_Program_Exit): Expand new pragma; spec. * inline.adb (Remove_Aspects_And_Pragmas): Support new pragma. * par-prag.adb (Prag): Support new pragma. * sem_attr.adb (Analyze_Attribute_Old_Result): Accept attribute Old in new pragma. * sem_ch12.adb (Implementation of Generic Contracts): Mention new aspect in comment. * sem_ch13.adb (Insert_Pragma, Analyze_Aspect_Specifications): Convert new new aspect to pragma. * sem_ch6.adb (Analyze_Subprogram_Body_Helper): Renumber subsequent rule in comment. * sem_prag.adb (Check_Postcondition_Use_In_Inlined_Subprogram) (Contract_Freeze_Error): Mention new pragma in comment. (Analyze_Pragma): Support new pragma; renumber subsequent rule in comment. (Analyze_Program_Exit_In_Decl_Part): Analyze new pragma; body. (Sig_Flags): References in new pragma are significant when detecting unreferenced objects. * sem_prag.ads (Aspect_Specifying_Pragma) (Assertion_Expression_Pragma, Pragma_Significant_To_Subprograms): Support new aspect and pragma. (Analyze_Program_Exit_In_Decl_Part): Analyze new pragma; spec. (Find_Related_Package_Or_Body): Mention new pragma in comment. * sem_util.adb (Is_Subprogram_Contract_Annotation): Support new pragma. * sem_util.ads (Is_Subprogram_Contract_Annotation): Mention new pragma in comment. * sinfo.ads (Is_Generic_Contract_Pragma): Mention new pragma in comment. * snames.ads-tmpl (Preset Names, Pragma_Id): Add name and pragma identifiers. * gnat_rm.texi: Regenerate.
2025-06-06ada: Move Incomplete_View from node to entity fieldPiotr Trojanek1-4/+2
The Incomplete_View property of a type was attached to its full type declaration as a semantic field, but retrieving it from there required low-level tree navigation and caused code duplication. In one case we relied on internal class-wide type being attached to the corresponding full type declaration, which is an undocumented assumption. It seems better to attach this field to entities, just like we do with Full_View and many other type properties. Ideally, this field should be present just in type entities, but currently we set it before setting the proper entity kind. Behavior is unaffected. This is rather a code cleanup, originating from the need to use Incomplete_View in GNATprove. gcc/ada/ChangeLog: * einfo.ads (Incomplete_View): Move from Sinfo; adapt wording. * exp_ch3.adb (Build_Record_Init_Proc): Adapt retrieval of Incomplete_View. * gen_il-fields.ads (Opt_Field_Enum): Move Incomplete_View from node to entity field. * gen_il-gen-gen_entities.adb (Gen_Entities): Add field. * gen_il-gen-gen_nodes.adb (Gen_Nodes): Remove field. * sem_ch3.adb (Analyze_Full_Type_Declaration, Check_Anonymous_Access_Component): Adapt setting of Incomplete_View. * sem_ch6.adb (Analyze_Subprogram_Body_Helper): Adapt retrieval of Incomplete_View for class-wide types; no longer rely on class-wide type being attached to non-classwide type declaration. * sem_util.adb (Collect_Primitive_Operations): Adapt retrieval of Incomplete_View. * sinfo.ads (Incomplete_View): Move to Einfo.
2025-06-06ada: Initial prototype of constructorssquirek1-0/+83
The patch implements the experimental constructors RFC. Currently a WIP. gcc/ada/ChangeLog: * aspects.ads: Add support for constructors. * exp_aggr.adb: Likewise. * exp_attr.adb: Likewise. * exp_ch3.adb: Likewise. * exp_ch4.adb: Likewise. * exp_util.adb: Likewise. * gen_il-fields.ads: Likewise. * gen_il-gen-gen_entities.adb: Likewise. * gen_il-gen-gen_nodes.adb: Likewise. * par-ch4.adb: Likewise. * sem_aggr.adb: Likewise. * sem_attr.adb, sem_attr.ads: Likewise. * sem_ch13.adb: Likewise. * sem_ch3.adb: Likewise. * sem_ch5.adb: Likewise. * sem_ch6.adb: Likewise. * sem_res.adb: Likewise. * sem_util.adb, sem_util.ads: Likewise. * snames.ads-tmpl: Likewise.
2025-06-06ada: Allow IN OUT parameters for first parameter of traversal functionsClaire Dross1-0/+17
In general, functions in SPARK cannot have parameters of mode IN OUT unless they are annotated with the Side_Effects aspect. Borrowing traversal functions are special functions which can return a part of their first parameter as an access-to-variable type. This might not be allowed in Ada if the parameter is a constant. Allow the first parameter of borrowing traversal functions to have mode IN OUT. gcc/ada/ChangeLog: * sem_ch6.adb (Analyze_SPARK_Subprogram_Specification): Allow the first parameter of functions whose return type is an anonymous access-to-variable type to have mode IN OUT.
2025-06-05ada: Missing error on expression function returning incomplete typeJavier Miranda1-0/+5
When the type of the expression of an expression function is an incomplete type, the frontend does not report the expected error. gcc/ada/ChangeLog: * sem_ch6.adb (Analyze_Expression_Function): Add missing check on premature use of incomplete type.
2025-06-05ada: Cleanup preanalysis of static expressions (part 6)Javier Miranda1-6/+6
Rename Preanalyze_Spec_Expression as Preanalyze_And_Resolve_Spec_Expression, Preanalyze_Assert_Expression as Preanalyze_And_Resolve_Assert_Expression, and Preanalyze_Default_Expression as Preanalyze_And_Resolve_Default_Expression; cleanup the version of Preanalyze_Assert_Expression without context type. gcc/ada/ChangeLog: * sem.ads: Update reference to renamed subprogram in documentation. * sem_ch3.ads (Preanalyze_Assert_Expression): Renamed. (Preanalyze_Spec_Expression): Renamed. * sem_ch3.adb (Preanalyze_Assert_Expression): Renamed and code cleanup. (Preanalyze_Spec_Expression): Renamed. (Preanalyze_Default_Expression): Renamed. * contracts.adb: Update calls to renamed subprograms. * exp_pakd.adb: Ditto. * exp_util.adb: Ditto. * freeze.adb: Ditto. * sem_ch12.adb: Ditto. * sem_ch13.adb: Ditto. * sem_ch6.adb: Ditto. * sem_prag.adb: Ditto. * sem_res.adb (Preanalyze_And_Resolve): Add to the version without context type the special handling for GNATprove mode provided by the version with context type; required to cleanup the body of Preanalyze_Assert_Expression.
2025-01-13ada: Remove redundant parentheses inside unary operatorsPiotr Trojanek1-2/+2
GNAT already emits a style warning when redundant parentheses appear inside logical and short-circuit operators. A similar warning will be soon emitted for unary operators as well. This patch removes the redundant parentheses to avoid future build errors. gcc/ada/ChangeLog: * checks.adb, exp_dist.adb, exp_imgv.adb, exp_util.adb, libgnarl/a-reatim.adb, libgnat/a-coinve.adb, libgnat/a-nbnbre.adb, libgnat/a-ngcoty.adb, libgnat/a-ngelfu.adb, libgnat/a-ngrear.adb, libgnat/a-strbou.ads, libgnat/a-strfix.ads, libgnat/a-strsea.adb, libgnat/a-strsea.ads, libgnat/a-strsup.ads, libgnat/a-strunb__shared.ads, libgnat/g-alleve.adb, libgnat/g-spitbo.adb, libgnat/s-aridou.adb, libgnat/s-arit32.adb, libgnat/s-dourea.ads, libgnat/s-genbig.adb, libgnat/s-imager.adb, libgnat/s-statxd.adb, libgnat/s-widthi.adb, sem_attr.adb, sem_ch10.adb, sem_ch3.adb, sem_ch6.adb, sem_ch7.adb, sem_dim.adb, sem_prag.adb, sem_res.adb, uintp.adb: Remove redundant parentheses inside NOT and ABS operators.
2025-01-09ada: Fix missing detection of late equality operator returning subtype of ↵Eric Botcazou1-2/+10
Boolean In Ada 2012, the compiler fails to check that a primitive equality operator for an untagged record type must appear before the type is frozen, when the operator returns a subtype of Boolean. This plugs the legality loophole but adds the debug switch -gnatd_q to go back to the previous state. gcc/ada/ChangeLog: PR ada/18765 * debug.adb (d_q): Document new usage. * sem_ch6.adb (New_Overloaded_Entity): Apply the special processing to all equality operators whose base result type is Boolean, but do not enforce the new Ada 2012 freezing rule if the result type is a proper subtype of it and the -gnatd_q switch is specified.
2025-01-07Update copyright years.Marc Poulhiès1-1/+1
2025-01-07ada: Cleanup preanalysis of static expressions (part 2)Javier Miranda1-23/+23
According to RM 13.14(8/4), a static expression in an aspect specification does not cause freezing; however, the frontend performs many calls to Preanalyze_Spec_Expression made during the analysis of aspects. This patch, suggested by Eric Botcazou, takes care of this additional code cleanup which requires also replacing many occurrences of the global variable In_Spec_Expression by calls to Preanalysis_Active. gcc/ada/ChangeLog: * exp_util.adb (Insert_Actions): Document behavior under strict preanalysis. * sem.ads (In_Strict_Preanalysis): New subprogram. (Preanalysis_Active): Replace 'and' operator by 'and then'. * sem.adb (In_Strict_Preanalysis): Ditto. * sem_attr.adb (Check_Dereference): Replace In_Spec_Expression occurrence by call to Preanalysis_Active, and document it. (Resolve_Attribute [Atribute_Access]): Ditto. (Eval_Attribute): No evaluation under strict preanalysis. (Validate_Static_Object_Name): No action under strict preanalysis. * sem_ch13.adb (Check_Aspect_At_End_Of_Declarations): Replace calls to Preanalyze_Spec_Expression by calls to Preanalyze_And_Resolve. (Check_Aspect_At_Freeze_Point): Ditto. (Resolve_Aspect_Expressions [Dynamic/Static/Predicate aspects]): Code cleanup adjusting the code to emulate Preanalyze_And_Resolve, instead of Preanalyze_Spec_Expression. (Resolve_Aspect_Expressions [CPU/Interrupt_Priority/Priority/ Storage_Size aspects]): Replace calls to Preanalyze_Spec_Expression by call to Preanalyze_And _Resolve. * sem_ch3.adb (Analyze_Object_Declaration): Replace In_Spec_Expression occurrence by call to Preanalysis_Active. (Find_Type_Of_Object): Add documentation. * sem_ch4.adb (Analyze_Case_Expression): Replace In_Spec_Expression occurrence by call to Preanalysis_Active. * sem_ch6.adb (Analyze_Expression_Function): Minor code reorganization moving the code preanalyzing the expression after the new body has been inserted in the tree to ensure that its Parent attribute is available for preanalysis. * sem_cat.adb (Validate_Static_Object_Name): No action under strict preanalysis. * sem_elab.adb (Check_For_Eliminated_Subprogram): Replace In_Spec_Expression occurrence by call to Preanalysis_Active. * sem_eval.adb (Eval_Intrinsic_Call [Name_Enclosing_Entity]): Ditto. * sem_elim.adb (Check_For_Eliminated_Subprogram): Ditto. * sem_res.adb (Resolve_Entity_Name): Ditto.
2025-01-07ada: Add "finally" GNAT extensionRonan Desplanques1-0/+17
This patch adds a new reserved word, "finally", and accompanying new syntax that's similar to the Java equivalent. gcc/ada/ChangeLog: * atree.adb (Parent_Or_List_Containing): New function. * atree.ads (Parent_Or_List_Containing): Likewise. * gen_il-fields.ads: Add new field. * gen_il-gen-gen_nodes.adb (Gen_Nodes): Extend handled sequence of statements node. * par-ch11.adb (P_Handled_Sequence_Of_Statements, P_Exception_Handler): Add new syntactic construct. * par-ch5.adb (P_Sequence_Of_Statements): Likewise. * par.adb: Likewise. * par-util.adb (Check_Future_Keyword): Warn that "finally" becomes a reserved word with extensions. * scans.adb (Initialize_Ada_Keywords): Add new reserved word. * snames.adb-tmpl: Likewise. * snames.ads-tmpl: Likewise. * scans.ads: Likewise. * sem_ch11.adb (Analyze_Handled_Statements): Adapt to new node field. * sem_ch5.adb (Analyze_Exit_Statement): Add legality check. (Analyze_Goto_Statement): Likewise. * sem_ch6.adb (Analyze_Return_Statement): Likewise. * sinfo-utils.adb (Lowest_Common_Ancestor, Destroy_Element): New subprograms. * sinfo-utils.ads (Lowest_Common_Ancestor): New function. * sinfo.ads: Add documentation for new field. * xsnamest.adb: Fix typo in comment. * doc/gnat_rm/gnat_language_extensions.rst: Document new extension. * warnsw.adb: Add new option. * warnsw.ads: Likewise. * exp_ch11.adb (Expand_N_Handled_Sequence_Of_Statements): Add abort deferral to finally part. * gnat_rm.texi: Regenerate. * gnat_ugn.texi: Regenerate. * gcc-interface/trans.cc (Handled_Sequence_Of_Statements_to_gnu): Handle finally statements.
2025-01-06ada: null procedure cannot be used as compilation unitBob Duff1-8/+0
This patch gives a syntax error if a null procedure is used as a compilation unit. The error was already given during semantic analysis; now it is given in the parser, which is more convenient for other tools like gprbuild, because the -gnats switch now gives the error. Note that the old message "null procedure cannot be declared at library level" was wrong; "library level" is not the same thing as "is a library unit". gcc/ada/ChangeLog: * par-ch10.adb (P_Compilation_Unit): Give an error for "is null". * sem_ch10.adb (Analyze_Subunit): Remove check for "is null" as a subunit. * sem_ch6.adb (Analyze_Subprogram_Declaration): Remove check for "is null" as a library unit.
2025-01-06ada: Cleanup preanalysis of static expressionsJavier Miranda1-0/+6
Complete previous patch; required to avoid regressions in GNATProve. gcc/ada/ChangeLog: * sem_ch6.adb (Analyze_Expression_Function): Set the parent of the new node to be the parent of the original to get the proper context, which is needed for complete error reporting and for semantic analysis. Patch suggested by Eric Botcazou.
2025-01-06ada: Fix incorrect incomplete type errorViljar Indus1-1/+3
In Ada 2005 even if the formal is using a tagged limited type then the type should not be considered incomplete. gcc/ada/ChangeLog: * sem_ch6.adb (Analyze_Subprogram_Body_Helper): Exchange_Limited_Views also in Ada 2005.
2025-01-03ada: Warn on unmodified parameters of expression functionsBob Duff1-6/+10
If an 'out' or 'in out' parameter is not modified in a function body, we warn. However, the warning was missing when we have an expression function instead of a proper body. This patch enables the warning on expression functions. gcc/ada/ChangeLog: * sem_ch6.adb (Analyze_Expression_Function): Mark the implicit spec for an expression function as Comes_From_Source. (Analyze_Null_Procedure): Minor cleanup. * sem_warn.adb (Source_E1): New function to compute whether to give warnings. In particular, return True for [in] out parameters of expression functions.
2024-12-13ada: Cleanup preanalysis of static expressionsJavier Miranda1-19/+3
During preanalysis, the frontend does not generate freeze nodes. The exception to this rule occurs during the preanalysis of default and per-object expressions, where static expressions are frozen. A patch merged six years ago to address an issue in this area introduced additional complexity and confusion regarding the frontend's behavior in such cases. The purpose of this patch is to revert that change, simplifying the support for the preanalysis of static expressions to make it cleaner and easier to understand. gcc/ada/ChangeLog: * sem.ads (Inside_Preanalysis_Without_Freezing): Removed. * sem.adb (Semantics): Remove Inside_Preanalysis_Without_Freezing. * sem_ch6.adb (Preanalyze_Formal_Expression): Removed. * sem_ch3.ads (Preanalyze_Assert_Expression): Add documentation. (Preanalyze_Spec_Expression): Add documentation. * sem_ch3.adb (Preanalyze_Assert_Expression) Code cleanup. (Preanalyze_Default_Expression): Code cleanup. * sem_res.ads (Preanalyze_With_Freezing_And_Resolve): Removed. * sem_res.adb (Preanalyze_With_Freezing_And_Resolve): Removed. (Preanalyze_And_Resolve): Code cleanup. * freeze.adb (Freeze_Entity): No freeze under strict preanalysis. (Freeze_Expression): Code cleanup. (Freeze_Expr_Types): Replace call to Preanalyze_Spec_Expression by strict preanalysis during preanalysis of a duplicate of the expression performed to have available the minimum decoration to locate referenced unfrozen types. * sem_aggr.adb (Resolve_Array_Aggregate): Minor code cleanup. * sem_attr.adb (Resolve_Attribute): Add documentation. * sem_ch13.adb (Resolve_Aspect_Expressions[Aspect_Default_Value]): Replace call to Preanalyze_Spec_Expression by Preanalyze_And_Resolve. (Resolve_Aspect_Expressions[Aspect_Default_Component_Value]): Ditto. * sem_ch8.adb (Set_Entity_Or_Discriminal): Code cleaup. * sem_prag.adb (Analyze_Initial_Condition_In_Decl_Part): Replace call to Preanalyze_Assert_Expression by call to Preanalyze_And_Resolve. (Analyze_Pre_Post_Condition): Replace call to Preanayze_Spec_Expression by call to Preanalyze_Assert_Expression. * sem_util.ads (In_Pragma_Expression): Adding a formal to extend the functionality of this subprogram. (Within_Static_Expression): New subprogram. * sem_util.adb (In_Pragma_Expression): Ditto. (Within_Static_Expression): Ditto. * checks.adb (Install_Null_Excluding_Check): No check during preanalysis. (Install_Primitive_Elaboration_Check): Ditto.
2024-12-12ada: Improve task entry context detectionRonan Desplanques1-0/+10
Access parameters are not allowed in specifications of task entries. Before this patch, the compiler failed to detect that case in accept statements that were not directly in their task body's scopes. This patch fixes this issue. gcc/ada/ChangeLog: * sem_ch3.adb (Access_Definition): Remove test for task entry context. * sem_ch6.adb (Process_Formals): Add improved test for task entry context.
2024-11-12ada: Elide the copy in aggregate returns for nonlimited typesEric Botcazou1-3/+8
This implements elision of the copy operation for aggregate returns, i.e. simple return statements whose expression is an aggregate, in the case of nonlimited by-reference types (the copy operation is already elided for limited types), which comprise controlled and tagged types. This is the copy operation in the called function, that is to say the copy from the anonymous object built for the aggregate to the anonymous return object. The implementation simply extends that of limited types, which rewrites the simple return statement as an extended return statement internally and then leverages the built-in-place implementation of return objects for these statements. gcc/ada/ChangeLog: * exp_aggr.adb (Is_Build_In_Place_Aggregate_Return): Also return True for functions returning on the secondary stack or returning a by-reference type if the back end exposes its return slot. (Expand_Array_Aggregate): Call Is_Build_In_Place_Aggregate_Return to spot aggregates to be built in place. * exp_ch3.adb (Make_Allocator_For_Return): Add missing condition in assertion pragma deduced from Expand_Subtype_From_Expr. * exp_ch6.adb (Expand_Simple_Function_Return): Rewrite the statement as an extended return statement if the expression is an aggregate whose expansion is delayed. Properly relocate the expression in this case. * sem_ch6.adb: Add clauses for Exp_Aggr. (Analyze_Function_Return): Do not apply the predicate check to an aggregate whose expansion is delayed. Extended the processing of case expressions to all conditional expressions.
2024-11-04ada: Missing precondition runtime check in inherited primitiveJavier Miranda1-3/+1
When a derived tagged type implements interface types in addition to deriving from its parent type, and a primitive inherited from its parent type corresponds to an inherited primitive that has class-wide preconditions, then the generated code fails to check the class-wide preconditions inherited from the interface primitive. gcc/ada/ChangeLog: * einfo.ads (Is_Dispatch_Table_Wrapper): Complete documentation. * exp_ch6.adb (Install_Class_Preconditions_Check): Dispatch table wrappers do not require installing the check since it is performed by the caller. (Class_Preconditions_Subprogram): Use new predicate Is_LSP_Wrapper. * freeze.adb (Check_Inherited_Conditions): Rename Postcond_Wrappers to Condition_Wrappers to handle implicitly inherited subprograms that implement pre-/postconditions inherited from interface primitives. Use new predicate Is_LSP_Wrapper. * sem_disp.adb (Check_Dispatching_Operation): Complete assertion to handle functions returning class-wide types. * exp_util.ads (Is_LSP_Wrapper): New subprogram. * exp_util.adb (Is_LSP_Wrapper): New subprogram. * contracts.adb (Process_Spec_Postconditions): Use Is_LSP_Wrapper. (Process_Inherited_Conditions): Use Is_LSP_Wrapper. * sem_ch6.adb (New_Overloaded_Entity): Use Is_LSP_Wrapper. * sem_util.adb (Nearest_Class_Condition_Subprogram): Use Is_LSP_Wrapper.
2024-10-08ada: Improved support for incomplete parameter typesSteve Baird1-1/+3
Fix two bugs uncovered by a recent ACATS test C3A1005: a freezing problem and a case where a user-defined equality function for an incomplete type was incorrectly hidden from use-clause visibility by the "corresponding" predefined op (which doesn't actually exist). gcc/ada/ChangeLog: * sem_ch6.adb (Analyze_Subprogram_Body_Helper): Don't freeze here if Has_Delayed_Freeze returns True. * sem_type.adb (Valid_Equality_Arg): Treat an incomplete type like a limited type because neither has an implicitly-defined equality primitive. (Covers): If either argument is an incomplete type whose full view is available, then look through to the full view. * sem_res.adb (Resolve_Actuals): If the actual parameter type is complete and the formal parameter type is not, then update the formal parameter type to use the complete view.
2024-10-08ada: Legal access discriminant default expression incorrectly rejectedSteve Baird1-0/+39
If a limited private partial view of a type has an access discriminant with a default expression, and if the type (perhaps tagged, perhaps not) is completed by deriving from an immutably limited type, then the default discriminant expression should not be rejected. gcc/ada/ChangeLog: * sem_ch6.adb (Check_Discriminant_Conformance): In testing whether a default expression is permitted for an access discriminant, we need to know whether the discriminated type is immutably limited. Handle another part of this test that cannot easily be handled in Sem_Aux.Is_Immutably_Limited. This involves declaring a new local function, Is_Derived_From_Immutably_Limited_Type.
2024-08-29ada: Missing legality check when type completedSteve Baird1-0/+26
Refine previous fix to better handle tagged cases. gcc/ada/ * sem_ch6.adb (Check_Discriminant_Conformance): Immediately after calling Is_Immutably_Limited_Type, perform an additional test that one might reasonably imagine would instead have been part of Is_Immutably_Limited_Type. The new test is a call to a new function Has_Tagged_Limited_Partial_View whose implementation includes a call to Incomplete_Or_Partial_View, which cannot be easily be called from Is_Immutably_Limited_Type (because sem_aux, which is in the closure of the binder, cannot easily "with" sem_util). * sem_aux.adb (Is_Immutably_Limited): Include N_Derived_Type_Definition case when testing Limited_Present flag.
2024-08-29ada: Avoid creating continuation messages without an intended parentViljar Indus1-3/+9
The messages modified in this patch do not have a clear intended parent. This causes a lot of issues when grouping continuation messages together with their parent. This can be confusing as it is not obvious what was the parent message that caused this problem or in worst case scenarios the message not being printed alltogether. These modified messages do not seem to be related to any concrete error message and thus should be treated as independent messages. gcc/ada/ * sem_ch12.adb (Abandon_Instantiation): Remove continuation characters from the error message. * sem_ch13.adb (Check_False_Aspect_For_Derived_Type): Remove continuation characters from the error message. * sem_ch6.adb (Assert_False): Avoid creating a continuation message without a parent. If no primary message is created then the message is considered as primary. gcc/testsuite/ChangeLog: * gnat.dg/interface6.adb: Adjust test.
2024-08-23ada: First controlling parameter aspectJavier Miranda1-2/+12
gcc/ada/ * sem_ch6.adb (Check_Private_Overriding): Improve code detecting error on private function with controlling result. Fixes the regression of ACATS bde0003.
2024-08-23ada: Fix style in lines starting with assignment operatorPiotr Trojanek1-2/+2
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-23ada: First controlling parameter aspectJavier Miranda1-14/+69
This patch adds support for a new GNAT aspect/pragma that modifies the semantics of dispatching primitives. When a tagged type has this aspect/pragma, only subprograms that have the first parameter of this type will be considered dispatching primitives; this new pragma/aspect is inherited by all descendant types. gcc/ada/ * aspects.ads (Aspect_First_Controlling_Parameter): New aspect. Defined as implementation defined aspect that has a static boolean value and it is converted to pragma when the value is True. * einfo.ads (Has_First_Controlling_Parameter): New attribute. * exp_ch9.adb (Build_Corresponding_Record): Propagate the aspect to the corresponding record type. (Expand_N_Protected_Type_Declaration): Analyze the inherited aspect to add the pragma. (Expand_N_Task_Type_Declaration): ditto. * freeze.adb (Warn_If_Implicitly_Inherited_Aspects): New subprogram. (Has_First_Ctrl_Param_Aspect): New subprogram. (Freeze_Record_Type): Call Warn_If_Implicitly_Inherited_Aspects. (Freeze_Subprogram): Check illegal subprograms of tagged types and interface types that have this new aspect. * gen_il-fields.ads (Has_First_Controlling_Parameter): New entity field. * gen_il-gen-gen_entities.adb (Has_First_Controlling_Parameter): The new field is a semantic flag. * gen_il-internals.adb (Image): Add Has_First_Controlling_Parameter. * par-prag.adb (Prag): No action for Pragma_First_Controlling_Parameter since processing is handled entirely in Sem_Prag. * sem_ch12.adb (Validate_Private_Type_Instance): When the generic formal has this new aspect, check that the actual type also has this aspect. * sem_ch13.adb (Analyze_One_Aspect): Check that the aspect is applied to a tagged type or a concurrent type. * sem_ch3.adb (Analyze_Full_Type_Declaration): Derived tagged types inherit this new aspect, and also from their implemented interface types. (Process_Full_View): Propagate the aspect to the full view. * sem_ch6.adb (Is_A_Primitive): New subprogram; used to factor code and also clarify detection of primitives. * sem_ch9.adb (Check_Interfaces): Propagate this new aspect to the type implementing interface types. * sem_disp.adb (Check_Controlling_Formals): Handle tagged type that has the aspect and has subprograms overriding primitives of tagged types that lack this aspect. (Check_Dispatching_Operation): Warn on dispatching primitives disallowed by this new aspect. (Has_Predefined_Dispatching_Operation_Name): New subprogram. (Find_Dispatching_Type): Handle dispatching functions of tagged types that have the new aspect. (Find_Primitive_Covering_Interface): For primitives of tagged types that have the aspect and override a primitive of a parent type that does not have the aspect, we must temporarily unset attribute First_Controlling_ Parameter to properly check conformance. * sem_prag.ads (Aspect_Specifying_Pragma): Add new pragma. * sem_prag.adb (Pragma_First_Controlling_Parameter): Handle new pragma. * snames.ads-tmpl (Name_First_Controlling_Parameter): New name. * warnsw.ads (Warn_On_Non_Dispatching_Primitives): New warning. * warnsw.adb (Warn_On_Non_Dispatching_Primitives): New warning; not set by default when GNAT_Mode warnings are enabled, nor when all warnings are enabled (-gnatwa).
2024-08-08ada: Missing legality check when type completedSteve Baird1-0/+14
An access discriminant is allowed to have a default value only if the discriminated type is immutably limited. In the case of a discriminated limited private type declaration, this rule needs to be checked when the completion of the type is seen. gcc/ada/ * sem_ch6.adb (Check_Discriminant_Conformance): Perform check for illegal access discriminant default values when the completion of a limited private type is analyzed. * sem_aux.adb (Is_Immutably_Limited): If passed the not-yet-analyzed entity for the full view of a record type, test the Limited_Present flag (which is set by the parser).