aboutsummaryrefslogtreecommitdiff
path: root/gcc/ada/sem_ch6.adb
AgeCommit message (Collapse)AuthorFilesLines
2 daysada: 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.
2 daysada: 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.
8 daysada: 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.
8 daysada: 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.
8 daysada: 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).
2024-08-06ada: Fix propagation of SPARK_Mode for renaming-as-bodyYannick Moy1-0/+9
The value of SPARK_Mode associated with a renaming-as-body might not be the correct one, when the private part of the package containing the declaration has SPARK_Mode Off while the public part has SPARK_Mode On. This may lead to analysis of code by GNATprove that should not be analyzed. gcc/ada/ * freeze.adb (Build_Renamed_Body): Propagate SPARK_Pragma to body build from renaming, so that locally relevant value is taken into account. * sem_ch6.adb (Analyze_Expression_Function): Propagate SPARK_Pragma to body built from expression function, so that locally relevant value is taken into account.
2024-08-01ada: Define No_Return flag only for subprogramsEric Botcazou1-2/+2
...instead of defining it for all entities. gcc/ada/ * einfo.ads (No_Return): Change description and adjust accordingly. * gen_il-gen-gen_entities.adb (Entity_Kind): Remove No_Return. (Subprogram_Kind): Add No_Return. (Generic_Subprogram_Kind): Likewise. * sem_ch6.adb (Analyze_Return_Statement): Adjust No_Return test.
2024-08-01ada: Implement full relaxed finalization semantics for controlled objectsEric Botcazou1-0/+4
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 support for bodies in -gnatcegArnaud Charlet1-82/+0
The support for generating C for Ada code is moved to GNAT LLVM. Keep support for generating header files from Ada spec files which is the remaining usage of -gnatceg. gcc/ada/ * bindgen.adb, bindusg.adb, debug.adb, einfo.ads, exp_aggr.adb, exp_attr.adb, exp_ch11.adb, exp_ch3.adb, exp_ch4.adb, exp_ch6.adb, exp_ch7.adb, exp_ch8.adb, exp_dbug.adb, exp_dbug.ads, exp_intr.adb, exp_unst.adb, exp_util.adb, exp_util.ads, freeze.adb, gen_il-fields.ads, gen_il-gen-gen_entities.adb, gnat1drv.adb, inline.adb, opt.ads, osint-c.adb, osint-c.ads, sem_attr.adb, sem_ch12.adb, sem_ch3.adb, sem_ch4.adb, sem_ch6.adb, sem_elab.adb, sem_res.adb, sinfo.ads, snames.ads-tmpl, switch-b.adb, switch-c.adb: Major clean up to remove C code generation for bodies.
2024-06-27ada: Overridden operation field not correctly set for controlling result ↵Martin Clochard1-47/+35
wrappers Implicit wrapper overridings generated for functions with controlling result when deriving with null extension may have field Overridden_Operation incorrectly set, when making several such derivations in succession. This happens because overridings were assumed to come from source, and entities generated by Derive_Subprograms were also assumed to be derived from source subprograms. Overridden_Operation could be set to the entity generated by Derive_Subprograms for the same type, resulting in a cycle between Overriden_Operation and Alias fields, causing non-termination in GNATprove. gcc/ada/ * sem_ch6.adb (Check_Overriding_Indicator) Remove Comes_From_Source filter. (New_Overloaded_Entity) Move up special case of LSP_Subprogram, and remove Comes_From_Source filter.
2024-06-14ada: Add prototype for mutably tagged typesJustin Squirek1-2/+8
This patch implements mutably tagged types via the new Size'Class aspect. gcc/ada/ * doc/gnat_rm/gnat_language_extensions.rst: Add documentation for mutably tagged type feature. * aspects.ads: Add registration for 'Size'Class. * einfo.ads: Add documentation for new components Class_Wide_Equivalent_Type and Is_Mutably_Tagged_Type. * exp_aggr.adb (Gen_Assign): Assume associated mutably tagged type when class-wide equivalent type is encountered. (Contains_Mutably_Tagged_Type): New subprogram. (Convert_To_Positional): Assume associated mutably tagged type when class-wide equivalent type is encountered. (Is_Static_Element): Assume associated mutably tagged type when class-wide equivalent type is encountered. (Expand_Array_Aggregate): Assume associated mutably tagged type when class-wide equivalent type is encountered. (Expand_Record_Aggregate): Force mutably tagged records to be expanded into assignments. * exp_ch3.adb (Build_Array_Init_Proc): Assume associated mutably tagged type when class-wide equivalent type is encountered. (Simple_Initialization_OK): Disallow simple initialization for class-wide equivalent types. (Build_Init_Statements): Assume associated mutably tagged type when class-wide equivalent type is encountered. (Expand_Freeze_Array_Type): Ignore building of record init procs for mutably tagged types. (Expand_N_Full_Type_Declaration): Replace mutably tagged type declarations with their associated class-wide equivalent types. (Default_Initialize_Object): Add special handling for mutably tagged types. * exp_ch4.adb (Expand_N_Allocator): Add initialization for mutably tagged types. (Expand_Record_Equality): Generate mutably tagged unchecked conversions. * exp_ch5.adb (Expand_N_Assignment_Statement): Generate a special assignment case for class-wide equivalent types which does tag assignments and ignores certain checks. * exp_ch6.adb (Expand_Call_Helper): Propagate constrained extra formal actuals for mutably tagged types. * exp_ch7.adb (Make_Init_Call): Handle mutably tagged type initialization. * exp_util.adb (Make_CW_Equivalent_Type): Modify to handle mutably tagged objects which contain no initialization expression. (Make_Subtype_From_Expr): Modify call to Make_CW_Equivalent_Type. * exp_util.ads (Make_CW_Equivalent_Type): Move declaration from body to spec. * freeze.adb (Size_Known): No longer return false automatically when a class-wide type is encountered. (Freeze_Entity): Ignore error messages about size not being known for mutably tagged types. * gen_il-fields.ads: Register new fields Class_Wide_Equivalent_Type and Is_Mutably_Tagged_Type. * gen_il-gen-gen_entities.adb: Register new fields Class_Wide_Equivalent_Type and Is_Mutably_Tagged_Type for type entities. * mutably_tagged.adb, mutably_tagged.ads (Corresponding_Mutably_Tagged_Type): New subprogram. (Depends_On_Mutably_Tagged_Ext_Comp): New subprogram. (Get_Corresponding_Mutably_Tagged_Type_If_Present): New subprogram. (Get_Corresponding_Tagged_Type_If_Present): New subprogram. (Is_Mutably_Tagged_Conversion): New subprogram. (Is_Mutably_Tagged_CW_Equivalent_Type): New subprogram. (Make_Mutably_Tagged_Conversion): New subprogram. (Make_CW_Size_Compile_Check): New subprogram. (Make_Mutably_Tagged_CW_Check): New subprogram. * sem_aggr.adb (Resolve_Array_Aggregate): Skip tag checks for class-wide equivalent types. (Resolve_Aggr_Expr): Assume associated mutably tagged type when class-wide equivalent type is encountered. * sem_attr.adb (Analyze_Attribute): Allow 'Tag on mutably tagged types. (Resolve_Attribute): Detect errors for dependence of mutably tagged extension type component. * sem_ch12.adb (Instantiate_Object): Detect errors for dependence of mutably tagged extension type component. * sem_ch13.adb (Analyze_One_Aspect): Propagate 'Size'Class to class-wide type. (Analyze_Attribute_Definition_Clause): Add handling of 'Size'Class by generating class-wide equivalent types and checking for illegal uses. * sem_ch2.adb (Analyze_Identifier): Generate unchecked conversion for class-wide equivalent types. * sem_ch3.adb (Analyze_Component_Declaration): Avoid unconstrained errors on mutably tagged types. (Analyze_Object_Declaration): Rewrite declarations of mutably tagged types to use class-wide equivalent types. (Array_Type_Declaration): Modify arrays of mutably tagged types to use their corresponding class-wide equivalent types. (Derived_Type_Declaration): Add various checks for mutably tagged derived types. * sem_ch4.adb (Analyze_Allocator): Replace reference to mutably tagged type with cooresponding tagged type. (Process_Indexed_Component): Generate unchecked conversion for class-wide equivalent type. (Analyze_One_Call): Generate unchecked conversion for class-wide equivalent types. (Analyze_Selected_Component): Assume reference to class-wide equivalent type is associated mutably tagged type. (Analyze_Type_Conversion): Generate unchecked conversion for class-wide equivalent type. * sem_ch5.adb (Analyze_Assignment): Assume associated mutably tagged type when class-wide equivalent type is encountered. (Analyze_Iterator_Specification): Detect errors for dependence of mutably tagged extension type component. * sem_ch6.adb (Create_Extra_Formals): Add code to generate extra formal for mutably tagged types to signal if they are constrained. * sem_ch8.adb (Analyze_Object_Renaming): Detect error on renaming of mutably tagged extension type component. (Analyze_Renaming_Primitive_Operation): Detect error on renaming of mutably tagged extension type component. * sem_res.adb (Resolve_Actuals): Allow class-wide arguments on class-wide equivalent types. (Valid_Conversion): Assume associated mutably tagged type when class-wide equivalent type is encountered. * sem_util.adb (Is_Fully_Initialized_Type): Flag mutably tagged types as fully initialized. (Needs_Simple_Initalization): Flag class-wide equivalent types as needing initialization. * gnat_rm.texi: Regenerate. * gcc-interface/Make-lang.in: Add entry for mutably_tagged.o.
2024-06-13ada: List subprogram body entities in scopesYannick Moy1-0/+9
Add entities of kind E_Subprogram_Body to the list of entities associated to a given scope. This ensures that representation information is correctly output for object and type declarations inside these subprogram bodies. This is useful for outputing that information fron the compiler with the switch -gnatR, as well as for getting precise representation information inside GNATprove. Remove ad-hoc code inside repinfo.adb that retrieved this information in only some cases. gcc/ada/ * exp_ch5.adb (Expand_Iterator_Loop_Over_Container): Skip entities of kind E_Subprogram_Body. * repinfo.adb (List_Entities): Remove special case for subprogram bodies. * sem_ch6.adb (Analyze_Subprogram_Body_Helper): List subprogram body entities in the enclosing scope.
2024-06-10ada: Storage_Error in indirect call to function returning limited typeJavier Miranda1-5/+7
At runtime the code generated by the compiler reports the exception Storage_Error in an indirect call through an access-to-subprogram variable that references a function returning a limited tagged type object. gcc/ada/ * sem_ch6.adb (Might_Need_BIP_Task_Actuals): Add support for access-to-subprogram parameter types. * exp_ch6.adb (Add_Task_Actuals_To_Build_In_Place_Call): Add dummy BIP parameters to access-to-subprogram types that may reference a function that has BIP parameters.
2024-05-16ada: Avoid checking parameters of protected proceduresViljar Indus1-2/+5
The compiler triggers warnings on generated protected procedures if the procedure does not have an explicit spec. Instead check if the body was created for a protected procedure if the spec is not present. gcc/ada/ * sem_ch6.adb (Analyze_Subprogram_Body_Helper): If the spec is not present for a subprogram body then check if the body definiton was created for a protected procedure.