aboutsummaryrefslogtreecommitdiff
path: root/gcc/ada/sem_res.adb
AgeCommit message (Collapse)AuthorFilesLines
12 daysada: Do not generate incorrect warning about redundant type conversionSteve Baird1-10/+10
If -gnatwr is enabled, then in some cases a type conversion between two different Boolean types incorrectly results in a warning that the conversion is redundant. gcc/ada/ChangeLog: * sem_res.adb (Resolve_Type_Conversion): Replace code for detecting a similar case with a more comprehensive test.
2025-06-06ada: Initial prototype of constructorssquirek1-0/+2
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: Improve large unconstrained-but-definite warningRonan Desplanques1-13/+3
Before this patch, Check_Discriminant_Use called Is_Limited type on entities before they were fully analyzed. That caused Is_Limited_Type to incorrectly return False for records that are limited because they have a limited component. This patch pushes back the emissions of the Check_Discriminant_Use warning after analysis of record declarations. A new field to E_Record_Type entity is added to take relevant discriminant uses into account. gcc/ada/ChangeLog: * gen_il-fields.ads: New field. * gen_il-gen-gen_entities.adb: New field. * einfo.ads: Document new field. * sem_res.adb (Check_Discriminant_Use): Record relevant uses in new field. Move warning emission to... * sem_ch3.adb (Analyze_Full_Type_Declaration): ... Here.
2025-06-05ada: Mark constants inside a declare expression as referencedViljar Indus1-0/+1
Expressions within a declare expression were simply bound to locally defined constants. However they were never marked as referenced. This would trigger an unreferenced constant warning if -gnatwu was used. gcc/ada/ChangeLog: * sem_res.adb (Resolve_Declare_Expression): Mark used local variables inside a declare expression as referenced.
2025-06-05ada: Cleanup preanalysis of static expressions (part 6)Javier Miranda1-4/+7
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-06-05ada: Avoid calling Resolve with Stand.Any_Fixed as the expected typeSteve Baird1-0/+2
When we call Resolve for an expression, we pass in the expected type for that expression. In the absence of semantic errors, that expected type should never be any of the "Any_xxx" types declared in stand.ads (e.g., Any_Array, Any_Numeric, Any_Real). In particular, it should never be Any_Fixed. Fix a case in which this rule was being violated. gcc/ada/ChangeLog: * sem_res.adb (Set_Mixed_Mode_Operand): If we are about to call Resolve passing in Any_Fixed as the expected type, then instead pass in the fixed point type of the other operand (i.e., B_Typ).
2025-01-13ada: Remove redundant parentheses inside unary operatorsPiotr Trojanek1-1/+1
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-07Update copyright years.Marc Poulhiès1-1/+1
2025-01-07ada: Cleanup preanalysis of static expressions (part 2)Javier Miranda1-1/+1
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-03ada: Simplify check for No_Coextensions restrictionPiotr Trojanek1-2/+2
Code cleanup; semantics is unaffected. gcc/ada/ChangeLog: * sem_res.adb (Resolve_Alocator): Move unrelated code out of a declare block.
2025-01-03ada: Improve and correct support for inheritance of nonoverriding aspectsGary Dismukes1-4/+9
This set of changes fixes various issues with the handling of inheritance of nonoverridable aspects (such as for Aggregate, and the indexing and iterator aspects, among others), plus improves some of the error reporting related to those. The prior implementation incorrectly handled types derived from container types with respect to such aspect inheritance, not properly inheriting the parent type's aspects, leading to rejection of legal constructs (such as container aggregates for the derived type). Also, various errors were incorrect (such as stating the wrong aspect) or unclear. In the case of types with indexing aspects, the resolution of indexed names for such types involved locating the eligible indexing functions anew with the analysis of each indexed name, which was both inefficient and wrong in some cases. That is addressed by locating the functions once, when the aspects are resolved, rather doing the location of those in two places, which is a maintenance hazard and could result in inconsistent resolution. Note that this completes work originally undertaken by Ed Schonberg that was also worked on by Steve Baird. gcc/ada/ChangeLog: * diagnostics-constructors.adb (Make_Default_Iterator_Not_Primitive_Error): Revise message to match message change made in sem_ch13.adb. * freeze.adb (Freeze_Record_Type): Output appropriate aspect name in error message, using Get_Name_String. (Freeze_Entity): For derived types, call Analyze_Aspects_At_Freeze_Point on the parent type, and call Inherit_Nonoverridable_Aspects on the type (for both parent type and any progenitor types). Add with_clause for System.Case_Util. * gen_il-fields.ads: Add Aspect_Subprograms to type Opt_Field_Enum. * gen_il-gen-gen_nodes.adb: Add field Aspect_Subprograms to N_Aspect_Specification nodes. * sem_ch4.adb (Try_Container_Indexing): Remove Find_Indexing_Operations and the code calling it. Add new function Indexing_Interpretations for retrieving the eligible indexing functions from the appropriate aspect's Aspect_Subprograms list and call that instead of Find_Value_Of_Aspect. * sem_ch7.adb (Analyze_Package_Specification): In loop over entities, call Analyze_Aspects_At_Freeze_Point for types that have delayed aspects. * sem_ch13.ads (Analyze_Aspects_At_Freeze_Point): Add Nonoverridable_Only formal to restrict processing to nonoverridable aspects. (Check_Function_For_Indexing_Aspect): New exported procedure renamed from Check_One_Function and moved to library level. * sem_ch13.adb (Analyze_Aspects_At_Freeze_Point): Test new formal Nonoverridable_Only formal to skip processing of aspects that are not nonoverridable when the formal is True. Skip the processing for Aspect_Full_Access_Only when Nonoverridable_Only is True. Call Check_Indexing_Functions in the case of indexing aspects (procedure moved from Analyze_Attribute_Definition_Clause to top level). (Analyze_Aspect_Specifications): Locate closest ancestor type with an explicit matching aspect to determine the aspect spec to reference in the error about a nonoverridable aspect not confirming an inherited aspect (skipping intermediate derived parents). Ensures that we retain existing errors flagged on explicit ancestor aspects rather than implicit inherited ones. Change names of variables Parent_Type and Inherited_Aspect to Ancestor_Type and Ancestor_Aspect respectively for clarity. (Analyze_Attribute_Definition_Clause): Move nested subprograms Check_Iterator_Functions and Check_Primitive_Function to top level of package. Move Check_Indexing_Functions (and its nested subprograms) from here to within Analyze_Aspects_At_Freeze_Point (adding some formal parameters and adjusting the code appropriately, and no longer call it from this procedure). (Is_CW_Or_Access_To_CW): Add test for the parent type having the indexing aspect for proper setting of Aspect_Specification_Is_Inherited. Delete "???" comment. (Look_Through_Anon_Access): Remove unneeded tests of Is_Access_Constant and Name_Constant_Indexing, which lead to wrong messages in some cases. (Check_Function_For_Indexing_Aspect): Procedure renamed from Check_One_Function and moved to library level (was nested within Check_Indexing_Functions), plus added formals (including Valid, to check result). Move scope test to beginning, to immediately exclude subprograms not declared immediately within the same scope as the type. Improve several error messages. Add error checking for Constant_Indexing functions. Append the function entity to the Aspect_Subprograms list of the aspect specification. Move code for checking for nonconfirming index aspects and for checking for illegal indexing aspects on full views to Check_Indexing_Functions. (Check_Indexing_Functions): Move procedure Illegal_Indexing from here to within Check_Function_For_Indexing_Aspect. Add a comment to the loop over interpretations about the checking being done as legality rules rather than resolution rules, plus a note referencing AI22-0084. Check for nonconfirming indexing aspects and illegal indexing aspects on full views here rather than in Check_One_Function (now named Check_Function_For_Indexing_Aspect). Remove function Check_One_Function (moved to library level and renamed), and call Check_Function_For_Indexing_Aspect instead. (Check_Inherited_Indexing): Improve spec comment. Remove nested function Same_Chars, and replace call Same_Chars with call to Sem_Util.Same_Name. Replace call to Illegal_Indexing with call to Error_Msg_NE. (Check_One_Function): Unnested from Check_Indexing_Functions, rename to Check_Function_For_Indexing_Aspect, move body to library level, and move declaration to Sem_Ch13 spec. (Analyze_Attribute_Definition_Clause, case Attribute_Default_Iterator): Improve error message related to tagged-type requirement. Suppress call to Check_Iterator_Functions for attribute definition clauses associated with inherited aspects. Remove error checking that is redundant with checking done in Check_Iterator_Functions. (Check_Aspect_At_Freeze_Point, case Attribute_Default_Iterator): Call Check_Iterator_Functions (only if the aspect is not Comes_From_Source). (Check_Iterator_Functions): Procedure unnested from Analyze_Attribute_Definition_Clause. Add formals Typ and Expr. Error messages corrected to say "aspect Default_Iterator" instead of "aspect Iterator". (Valid_Default_Iterator): Improve error message to say "must be a local primitive or class-wide function" instead of "must be a primitive function". (Check_Primitive_Function): Unnested from Analyze_Attribute_Definition_Clause. Add formal Ent. (Rep_Item_Too_Late): Return False when an attribute_definition_clause is not Comes_From_Source, since it was generated by the compiler (such as for an inherited aspect). (Resolve_Aspect_Aggregate): Capture implementation base type. (Valid_Empty): Use implementation base types for result type comparison. (Valid_Add_Named): Use impl base types for comparison of formal's type. (Valid_Add_Unnamed): Use impl base types for comparison of formal's type. (Valid_New_Indexed): Use impl base types for result type comparison. (Validate_Literal_Aspect): Return immediately when aspect does not have Comes_From_Source True (no point in validating inherited aspects). * sem_res.adb (Has_Applicable_User_Defined_Literal): Remove Base_Type comparison and always call Corresponding_Op_Of_Derived_Type for derived types. Add "???" comment about issue with wrapper functions (and indicate that it would be nice to eliminate the call to Corresponding_Primitive_Op). * sem_util.ads (Inherit_Nonoverridable_Aspects): New procedure. (Corresponding_Op_Of_Derived_Type): Update spec comment to indicate return of Ancestor_Op and name changed from Corresponding_Primitive_Op. * sem_util.adb (Check_Inherited_Nonoverridable_Aspects): Fix name in header comment. (Corresponding_Op_Of_Derived_Type): Move declaration of Typ down with other local variables. Remove Assert that doesn't apply in some cases. Simply return Ancestor_Op when it isn't a primitive (it can be a class-wide op). Function name changed from Corresponding_Primitive_Op. (Find_Untagged_Type_Of): Add test of Is_Type (E) as a guard for checking Direct_Primitive_Operations. Remove Assert (False), and return Empty when the primitive is not found. (Profile_Matches_Ancestor): Change comparisons to use implementation base types of the operations' formal and result types. Add tests for interface ancestors. Revise "???" comment. (Is_Confirming): Simplify name-matching test to use the names associated with the aspects rather than going to the N_Attribute_Definition_Clause nodes (may facilitate elimination of those clauses at some point). (Inherit_Nonoverridable_Aspects): New procedure to traverse the aspects of a derived type's parent type and create inherited versions of the parent type's nonoverridable aspects, identifying the appropriate subprograms for each such inherited aspect. (Inherit_Nonoverridable_Aspect): New procedure nested in Inherit_Nonoverridable_Aspects to inherit individual nonoverridable aspects. Identifies the corresponding subprogram(s) associated with an inherited nonoverridable aspect. In the case of indexing aspects, new eligible indexing functions of the type are also identified here, and the entities of all of the identified subprograms are appended to the aspect's Aspect_Subprograms Elist. Add a "???" comment about this. * sinfo.ads: Add documentation for the new Aspect_Subprograms field.
2024-12-13ada: Cleanup preanalysis of static expressionsJavier Miranda1-47/+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-13ada: Refactor code of Check_Ambiguous_Call and Valid_ConversionJavier Miranda1-17/+7
gcc/ada/ChangeLog: * sem_res.adb (Report_Ambiguous_Argument): Code cleanup. (Resolve): Code cleanup.
2024-12-12ada: Refactor code of Check_Ambiguous_Call and Valid_ConversionJavier Miranda1-2/+1
gcc/ada/ChangeLog: * sem_res.adb (Is_Ambiguous_Operand): Add missing decoration of the operand when it is labeled overloaded but has just one interpretation.
2024-11-26ada: Clean up previous changeEric Botcazou1-10/+6
gcc/ada/ChangeLog: * sem_res.adb (Valid_Conversion): Do not initialize Opnd_Type before calling Get_Corresponding_Mutably_Tagged_Type_If_Present.
2024-11-26ada: Refactor code of Check_Ambiguous_Call and Valid_ConversionJavier Miranda1-229/+315
Code cleanup; factorizing code. gcc/ada/ChangeLog: * sem_ch2.adb (Check_Ambiguous_Call): Replace code factorized code by call to the new subprogram Is_Ambiguous_Operand. * sem_res.ads (Is_Ambiguous_Operand): New subprogram that factorizes previous code in Check_Ambiguous_Call and Valid_Conversion. * sem_res.adb (Is_Ambiguous_Operand): New subprogram. (Valid_Tagged_Conversion): Replace factorized code by call to the new subprogram Is_Ambiguous_Operand. (Report_Error_N): New subprogram. (Report_Error_NE): New subprogram. (Report_Interpretation): New subprogram. (Conversion_Error_N): Removed; replaced by Report_Error_N. (Conversion_Error_NE): Removed; replaced by Report_Error_NE. (Valid_Conversion): Update Opnd_Type after the call to Is_Ambiguous_Operand in the overloaded case.
2024-11-18ada: Constraint error not raised in ACATS test c413007Javier Miranda1-1/+1
Reverse the meaning of switch -gnatd_P; that is, enable by default the generating of a runtime check when the prefix of the call is an access-to-subprogram type with a null value. gcc/ada/ChangeLog: * sem_res.adb (Resolve_Actuals): Add by default a null-exclusion check on the prefix of the call when it is an access-type; it can be disabled using -gnatd_P. * debug.adb (gnatd_P): Update documentation.
2024-11-12ada: Get rid of N_Unchecked_Expression nodeEric Botcazou1-18/+3
This node is used in a single place in the front-end: it wraps the newly built N_Indexed_Component nodes on the left-hand side of assignments generated to elaborate array aggregates, and its effect is to disable range checks for the expressions of these nodes. Most of the code in the front-end does not expect to encounter it at all, which leads to weird effects when this actually happens after changes are made to the processing of array aggregates. This change replaces the node by the Kill_Range_Check flag already present on N_Unchecked_Type_Conversion, but with a slightly adjusted semantics. gcc/ada/ChangeLog: * exp_aggr.adb (Build_Array_Aggr_Code.Gen_Assign): Do not call Checks_Off on the newly built N_Indexed_Component node but instead set Kill_Range_Check on it. * exp_ch4.ads (Expand_N_Unchecked_Expression): Delete. * exp_ch4.adb (Expand_N_Indexed_Component): Remove handling of N_Unchecked_Expression. (Expand_N_Unchecked_Expression): Delete. (Expand_N_Unchecked_Type_Conversion): Propagate the Assignment_OK flag and rewrite the node manually. * exp_util.adb (Insert_Actions): Remove handling of N_Unchecked_Expression. (Side_Effect_Free): Likewise. * expander.adb (Expand): Likewise. * gen_il-gen-gen_nodes.adb (N_Indexed_Component): Add flag Kill_Range_Check for the purpose of semantics. (N_Unchecked_Expression): Delete. * gen_il-internals.ads (Type_Frequency): Remove entry for N_Unchecked_Expression. * gen_il-types.ads (Opt_Type_Enum): Remove N_Unchecked_Expression. * pprint.adb (Expression_Image): Remove handling of N_Unchecked_Expression. * sem.adb (Analyze): Likewise. * sem_ch4.ads (Analyze_Unchecked_Expression): Delete. * sem_ch4.adb (Analyze_Unchecked_Expression): Likewise. * sem_res.adb (Resolve_Unchecked_Expression): Likewise. (Resolve): Remove handling of N_Unchecked_Expression. (Resolve_Indexed_Component): Do not call Apply_Scalar_Range_Check on the expressions if Kill_Range_Check is set on the node. * sem_util.adb (Is_Non_Preelaborable_Construct): Remove handling of N_Unchecked_Expression. * sinfo.ads (Kill_Range_Check): Document it for N_Indexed_Component. (Unchecked Expression): Delete specification. * sprint.adb (Sprint_Node_Actual): Remove handling of N_Unchecked_Expression. * tbuild.ads (Checks_Off): Delete. * tbuild.adb (Checks_Off): Likewise.
2024-11-04ada: Initial implementation of Extended_Access aspect (FE portion only)Steve Baird1-0/+32
The Extended_Access aspect can be specified to be True for certain access-to-unconstrained-array-subtype types. Such extended access types can designate objects that a normal general access type (with the same designated subtype) cannot, such as a slice of an aliased array object or an object that is represented without contiguous bounds information. gcc/ada/ChangeLog: * aspects.ads: Add Aspect_Extended_Access to Aspect_Id enumeration. * par-prag.adb: Add Pragma_Extended_Access to list of pragmas that get no interesting processing in the parser. * sem_attr.adb: Relax legality checks on Access/Unchecked_Access attribute references if access type is Extended_Access. * sem_ch12.adb (Validate_Access_Type_Instance): For an instance of a generic with a formal access type, check that formal and actual agree with with respect to Extended_Access aspect. * sem_prag.adb (Analyze_Pragma): Add analysis code for pragma Extended_Access. Set Pragma_Extended_Access element in Sig_Flags aggregate. * sem_prag.ads: Set Pragma_Extended_Access element in Aspect_Specifying_Pragma aggregate. * sem_res.adb (Valid_Conversion): Disallow extended-to-not-extended access conversion. * sem_util.adb (Is_Extended_Access_Access_Type): Implement new function. (Is_Aliased_View): If (and only if) the new Boolean For_Extended parameter is True, then a slice of an aliased non-bitpacked array is aliased, a constrained nominal subtype does not force a result of False, and a dereference of an extended access value is aliased. The last point is somewhat subtle. This is how we prevent covert fat-to-nonfat type conversions via things like "Not_Extended_Type'(Extended_Ptr.all'Access)" or passing Extended_Ptr.all as an actual parameter corresponding to an explicitly aliased formal parameter. * sem_util.ads (Is_Extended_Access_Type): Declare new function. (Is_Aliased_View): Add new defaults-False parameter For_Extended. * snames.ads-tmpl: Declare Name_Extended_Access Name_Id constant and Pragma_Extended_Access Pragma_Id enumeration literal.
2024-11-04ada: Assignment local variable only when it is usedPiotr Trojanek1-8/+8
Code cleanup; semantics is unaffected. gcc/ada/ChangeLog: * sem_res.adb (In_Decl): Rename and move local variable where it is used.
2024-11-04ada: Add null exclusion to avoid run-time checksPiotr Trojanek1-2/+2
By declaring access parameter with non-null qualifier, the compiler should avoid generating run-time checks in debug builds, resulting in a tiny performance improvement. Code cleanup; semantics is unaffected. gcc/ada/ChangeLog: * sem_res.adb (Type_In_P): Add non-null qualifier.
2024-11-04ada: Resolve intrinsic operators without homonymsPiotr Trojanek1-10/+37
Intrinsic operators are resolved by rewriting into a corresponding operator from the Standard package. Traversing homonyms just to find the corresponding operator was not particularly efficient; also, for the binary "-" it was finding the unary "-". There appears to be no difference in compiler behavior, but the new code should be more efficient and finding the correct operator seems to make more sense. gcc/ada/ChangeLog: * sem_res.adb (Resolve_Intrinsic_Operator) (Resolve_Intrinsic_Unary_Operator): Replace traversals of homonyms with a direct lookup.
2024-11-04ada: Fix asymmetry in resolution of unary intrinsic operatorsPiotr Trojanek1-0/+7
Resolution of binary and unary intrinsic operators differed when expansion was inactive. In particular, this affected GNATprove handling of Ada.Real_Time."abs" operator. This patch makes unary resolution behave like binary resolution. gcc/ada/ChangeLog: * sem_res.adb (Resolve_Intrinsic_Unary_Operator): Disable when expansion is inactive.
2024-10-25ada: Constraint error not raised in ACATS test c413007Javier Miranda1-37/+56
The Constraint_Error exception is not raised when a subprogram is called using prefix notation, and the prefix of the call is an access-to-subprogram type with a null value. This new check is enabled by switch -gnatd_P gcc/ada/ChangeLog: * gen_il-fields.ads: New node field (Is_Expanded_Prefixed_Call). * gen_il-gen-gen_nodes.adb: New semantic field for N_Function_Call and N_Procedure_Call_Statement nodes. * sem_ch4.adb (Complete_Object_Operation): Mark the rewritten node with the Is_Expanded_Prefixed_Call flag. * sem_res.adb (Check_Prefixed_Call): Code cleanup and addition of documentation. (Resolve_Actuals): Add a null-exclusion check on the prefix of the call when it is an access-type. * sinfo.ads: Adding new semantic flag (Is_Expanded_Prefixed_Call) to N_Function_Call and N_Procedure_Call_Statement nodes. * debug.adb: Adding documentation for switch d_P.
2024-10-25ada: Untagged incomplete view not detected in ACATS test b3a1a060Javier Miranda1-5/+47
Adding checks for RM 3.10.1(10): An actual parameter cannot be of an untagged incomplete view; the result object of a function call cannot be of an incomplete view. gcc/ada/ChangeLog: * sem_res.adb (Resolve_Actuals): Add checks for incomplete type actuals.
2024-10-08ada: Improved support for incomplete parameter typesSteve Baird1-0/+9
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: Add External_Initialization extensionRonan Desplanques1-6/+28
This patch introduces a GNAT extension that adds a new aspect, External_Initialization. A section is added to the reference manual with a description of what the aspect does. The implementation reuses existing mechanisms, in particular Sinput.L.Load_Source_File and Sem_Res.Set_String_Literal_Subtype. A new node kind is added, and nodes of that type are present in what is passed to the back ends. That makes it necessary to update the back ends to handle the new node type. The C interface is extended to make that possible. gcc/ada/ChangeLog: * aspects.ads: Add entities for External_Initialization. * checks.adb (Selected_Length_Checks): Add support for N_External_Initializer nodes. * doc/gnat_rm/gnat_language_extensions.rst: Add section for the added extension. * exp_util.adb (Insert_Actions): Add support for N_External_Initializer nodes. * fe.h (C_Source_Buffer): New function. * gen_il-fields.ads: Add new field. * gen_il-gen-gen_nodes.adb: Add N_External_Initializer node kind. * gen_il-gen.adb: Add new field type. * gen_il-types.ads: Add new node kind and new field type. * pprint.adb (Expr_Name): Handle new node kind. * sem.adb (Analyze): Add support for N_External_Initializer nodes. * sem_ch13.adb (Analyze_Aspect_Specifications, Check_Aspect_At_Freeze_Point): Add support for External_Initialization aspect. * sem_ch3.adb (Apply_External_Initialization): New subprogram. (Analyze_Object_Declaration): Add support for External_Initialization aspect. * sem_res.adb (Resolve_External_Initializer): New procedure. (Resolve): Add support for N_External_Initializer nodes. (Set_String_Literal_Subtype): Extend to handle N_External_Initializer nodes. * sinfo-utils.adb (Is_In_Union_Id): Adapt to new field addition. * sinfo.ads: Add documentation for new node kind and new field. * sinput.adb, sinput.ads (C_Source_Buffer): Add new C interface function. * snames.ads-tmpl: Add new aspect identifier. * sprint.adb (Sprint_Node_Actual): Add nop handling of N_External_Initializer nodes. * types.ads: Modify type to allow for new C interface. * gcc-interface/trans.cc (gnat_to_gnu): Handle new GNAT node type. * gcc-interface/Make-lang.in: Update list of stage1 run-time library units. * gnat-style.texi: Regenerate. * gnat_rm.texi: Regenerate. * gnat_ugn.texi: Regenerate.
2024-09-03ada: Do not warn for partial access to Atomic Volatile_Full_Access objectsEric Botcazou1-16/+30
The initial implementation of the GNAT aspect/pragma Volatile_Full_Access made it incompatible with Atomic, because it was not decided whether the read-modify-write sequences generated by Volatile_Full_Access would need to be implemented atomically when Atomic was also specified, which would have required a compare-and-swap primitive from the target architecture. But Ada 2022 introduced Full_Access_Only and retrofitted it into Atomic in the process, answering the above question by the negative, so the incompatibility between Volatile_Full_Access and Atomic was lifted in Ada 2012 as well, but the implementation was not entirely adjusted. In Ada 2012, it does not make sense to warn for the partial access to an Atomic object if the object is also declared Volatile_Full_Access, since the object will be accessed as a whole in this case (like in Ada 2022). gcc/ada/ * sem_res.adb (Is_Atomic_Ref_With_Address): Rename into... (Is_Atomic_Non_VFA_Ref_With_Address): ...this and adjust the implementation to exclude Volatile_Full_Access objects. (Resolve_Indexed_Component): Adjust to above renaming. (Resolve_Selected_Component): Likewise.
2024-08-02ada: Reject ambiguous function calls in interpolated string expressionsJavier Miranda1-1/+12
This patch enhances support for this language feature by rejecting more ambiguous function calls. In terms of name resolution, the analysis of interpolated expressions is now treated as an expression of any type, as required by the documentation. Additionally, support for nested interpolated strings has been removed. gcc/ada/ * gen_il-fields.ads (Is_Interpolated_String_Literal): New field. * gen_il-gen-gen_nodes.adb (Is_Interpolated_String_Literal): The new field is a flag handled by the parser (syntax flag). * par-ch2.adb (P_Interpolated_String_Literal): Decorate the new flag. * sem_ch2.adb (Analyze_Interpolated_String_Literal): Improve code detecting and reporting ambiguous function calls. * sem_res.adb (Resolve_Interpolated_String_Literal): Restrict resolution imposed by the context type to string literals that have the new flag. * sinfo.ads (Is_Interpolated_String_Literal): New field defined in string literals. Fix documentation of the syntax rule of interpolated string literal.
2024-08-02ada: Type conversion in instance incorrectly rejected.Steve Baird1-1/+1
In some cases, a legal type conversion in a generic package is correctly accepted but the corresponding type conversion in an instance of the generic is incorrectly rejected. gcc/ada/ * sem_res.adb (Valid_Conversion): Test In_Instance instead of In_Instance_Body.
2024-08-01ada: Style fixes: remove blank lines following 'begin' keywordsGhjuvan Lacambre1-1/+0
The GNAT style guide specifies that there must not be blank lines after 'begin' keywords. gcc/ada/ * backend_utils.adb (Scan_Common_Back_End_Switch): Remove blank line. * errout.adb (Output_JSON_Message): Likewise. * erroutc.adb (Set_Msg_Char): Likewise. * exp_aggr.adb (Two_Dim_Packed_Array_Handled): Likewise. * exp_pakd.adb (Expand_Packed_Address_Reference): Likewise. (Expand_Packed_Bit_Reference): Likewise. (Expand_Packed_Boolean_Operator): Likewise. (Expand_Packed_Element_Reference): Likewise. (Expand_Packed_Eq): Likewise. (Expand_Packed_Not): Likewise. * exp_prag.adb (Build_Dim3_Declaration): Likewise. * exp_strm.adb (Build_Elementary_Input_Call): Likewise. * freeze.adb (Find_Aspect_No_Parts): Likewise. (Get_Aspect_No_Parts_Value): Likewise. * gen_il-gen.adb (Compile): Likewise. * gnat1drv.adb (Adjust_Global_Switches): Likewise. * gnat_cuda.adb (Expand_CUDA_Package): Likewise. * gnatchop.adb (Read_File): Likewise. * gnatls.adb (Get_Runtime_Path): Likewise. * make.adb (Binding_Phase): Likewise. * par-ch11.adb (P_Exception_Choice): Likewise. * par-ch5.adb (P_Loop_Parameter_Specification): Likewise. * par-ch6.adb (Is_Extended): Likewise. * sem_attr.adb (Check_Dereference): Likewise. * sem_ch12.adb (Build_Subprogram_Decl_Wrapper): Likewise. * sem_ch3.adb (Build_Itype_Reference): Likewise. * sem_prag.adb (Validate_Compile_Time_Warning_Errors): Likewise. * sem_res.adb (Resolve_Declare_Expression): Likewise. * sem_util.adb (Build_Default_Subtype): Likewise. * sprint.adb (Sprint_Paren_Comma_List): Likewise.
2024-08-01ada: Remove support for bodies in -gnatcegArnaud Charlet1-20/+3
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: Bug using user defined string literals with interpolated stringsJavier Miranda1-1/+6
The frontend rejects the use of user defined string literals using interpolated strings. gcc/ada/ * sem_res.adb (Has_Applicable_User_Defined_Literal): Add missing support for interpolated strings.
2024-06-14ada: Add prototype for mutably tagged typesJustin Squirek1-0/+17
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: Revert changing a GNATProve mode message to a non-warningViljar Indus1-1/+1
GNATProve compiles the program multiple times. During the first run the warnings are suppressed. These messages need to be suppressed during that run in order to avoid having them duplicated in the following runs. Revert the previous changes as there currently is not a way to simply suppress info messages. gcc/ada/ * sem_res.adb (Resolve_Call): add warning insertion character into the info message.
2024-06-13ada: Remove warning insertion characters from info messagesViljar Indus1-1/+1
Remove warning insertion characters without switch characters from info messages. gcc/ada/ * par-ch7.adb: Remove warning characters from info message * par-endh.adb: Remove warning characters from info message * sem_res.adb: Remove warning characters from info message
2024-05-16ada: Fix missing length checks with case expressionsRonan Desplanques1-0/+3
This fixes an issue where length checks were not generated when the right-hand side of an assigment involved a case expression. gcc/ada/ * sem_res.adb (Resolve_Case_Expression): Add length check insertion. * exp_ch4.adb (Expand_N_Case_Expression): Add handling of nodes known to raise Constraint_Error.
2024-05-14ada: Reduce generated code duplication for streaming and Put_Image subprogramsSteve Baird1-5/+74
In the case of an untagged composite type, the compiler does not generate streaming-related subprograms or a Put_Image procedure when the type is declared. Instead, these subprograms are declared "on demand" when a corresponding attribute reference is encountered. In this case, hoist the declaration of the implicitly declared subprogram out as far as possible in order to maximize the chances that it can be reused (as opposed to generating an identical second subprogram) in the case where a second reference to the same attribute is encountered. Also relax some privacy-related rules to allow these procedures to do what they need to do even when constructed in a scope where some of those actions would normally be illegal. gcc/ada/ * exp_attr.adb: Change name of package Cached_Streaming_Ops to reflect the fact that it is now also used for Put_Image procedures. Similarly change other "Streaming_Op" names therein. Add Validate_Cached_Candidate procedure to detect case where a subprogram found in the cache cannot be reused. Add new generic procedure Build_And_Insert_Type_Attr_Subp; the "Build" part is handled by just calling a formal procedure; the bulk of this (generic) procedure's code has to with deciding where in the tree to insert the newly-constructed subprogram. Replace each later "Build" call (and the following Insert_Action or Compile_Stream_Body_In_Scope call) with a declare block that instantiates and then calls this generic procedure. Delete the now-unused procedure Compile_Stream_Body_In_Scope. A constructed subprogram is entered in the appropriate cache if the corresponding type is untagged; this replaces more complex tests. A new function Interunit_Ref_OK is added to determine whether an attribute reference occuring in one unit can safely refer to a cached subprogram declared in another unit. * exp_ch3.adb (Build_Predefined_Primitive_Bodies): A formal parameter was deleted, so delete the corresponding actual in a call. * exp_put_image.adb (Build_Array_Put_Image_Procedure): Because the procedure being built may be referenced more than once, the generated procedure takes its source position info from the type declaration instead of the (first) attribute reference. (Build_Record_Put_Image_Procedure): Likewise. * exp_put_image.ads (Build_Array_Put_Image_Procedure): Eliminate now-unused Nod parameter. (Build_Record_Put_Image_Procedure): Eliminate now-unused Loc parameter. * sem_ch3.adb (Constrain_Discriminated_Type): For declaring a subtype with a discriminant constraint, ignore privacy if Comes_From_Source is false (as is already done if Is_Instance is true). * sem_res.adb (Resolve): When passed two type entities that have the same underlying base type, Sem_Type.Covers may return False in some cases because of privacy. [This can happen even if Is_Private_Type returns False both for Etype (N) and for Typ; Covers calls Base_Type, which can take a non-private argument and yield a private result.] If Comes_From_Source (N) is False (e.g., for a compiler-generated Put_Image or streaming subprogram), then avoid that scenario by not calling Covers. Covers already has tests for doing this sort of thing (see the calls therein to Full_View_Covers), but the Comes_From_Source test is too coarse to apply there. So instead we handle the problem here at the call site. (Original_Implementation_Base_Type): A new function. Same as Implementation_Base_Type except if the Original_Node attribute of a non-derived type declaration indicates that it once was a derived type declaration. Needed for looking through privacy. (Valid Conversion): Ignore privacy when converting between different views of the same type if Comes_From_Source is False for the conversion. (Valid_Tagged_Conversion): An ancestor-to-descendant conversion is not an illegal downward conversion if there is no type extension involved (because the derivation was from an untagged view of the parent type).
2024-05-07ada: Fix missing flag for GNATproveYannick Moy1-0/+11
GNATprove expects the frontend to position correctly range check flags, on expressions which might lead to a range check failure. This was missing on in-out parameters of calls. Now fixed. There is no impact on compilation. gcc/ada/ * sem_res.adb (Resolve_Actuals): Add range check flag.
2024-05-06ada: Prevent inlining in GNATprove for memory leaksYannick Moy1-2/+3
In some cases, inlining a call in GNATprove could lead to missing a memory leak. Recognize such cases and do not inline such calls. gcc/ada/ * inline.adb (Call_Can_Be_Inlined_In_GNATprove_Mode): Add case to prevent inlining of call. * inline.ads: Likewise. * sem_res.adb (Resolve_Call): Update comment and message.
2024-02-26Finalization of object allocated by anonymous access designating local typeEric Botcazou1-7/+7
The finalization of objects dynamically allocated through an anonymous access type is deferred to the enclosing library unit in the current implementation and a warning is given on each of them. However this cannot be done if the designated type is local, because this would generate dangling references to the local finalization routine, so the finalization needs to be dropped in this case and the warning adjusted. gcc/ada/ PR ada/113893 * exp_ch7.adb (Build_Anonymous_Master): Do not build the master for a local designated type. * exp_util.adb (Build_Allocate_Deallocate_Proc): Force Needs_Fin to false if no finalization master is attached to an access type and assert that it is anonymous in this case. * sem_res.adb (Resolve_Allocator): Mention that the object might not be finalized at all in the warning given when the type is an anonymous access-to-controlled type. gcc/testsuite/ * gnat.dg/access10.adb: New test.
2024-01-22Update copyright years.Marc Poulhiès1-1/+1
2024-01-09ada: More aggressive inlining of subprogram calls in GNATprove modePiotr Trojanek1-4/+7
Previously if a subprogram call could not be inlined in GNATprove mode, then all subsequent calls to the same subprogram were not inlined either (because a failed attempt to inline clears flag Is_Inlined_Always and we tested this flag when attempting to inline subsequent calls). Now a failure in inlining of a particular call does not prevent inlining of subsequent calls to the same subprogram, except when inlining failed because the subprogram was detected to be recursive (which clears the Is_Inlined flag that we now examine). This change allows more checks to be proved and reduces interactions between inlining and SPARK legality checks. gcc/ada/ * sem_ch6.adb (Analyze_Subprogram_Specification): Set Is_Inlined flag by default in GNATprove mode. * sem_res.adb (Resolve_Call): Only look at flag which is cleared when inlined subprogram is detected to be recursive.
2023-12-19ada: Cleanup SPARK legality checkingYannick Moy1-100/+0
Move one SPARK legality check from GNAT to GNATprove, and cleanup other uses of SPARK_Mode for legality checking. gcc/ada/ * sem_ch4.adb (Analyze_Selected_Component): Check correct mode variable for GNATprove. * sem_prag.adb (Refined_State): Call SPARK_Msg_NE which checks value of SPARK_Mode before issuing a message. * sem_res.adb (Resolve_Entity_Name): Remove legality check for SPARK RM 6.1.9(1), moved to GNATprove.
2023-11-30ada: Rework fix for wrong finalization of qualified aggregate in allocatorEric Botcazou1-1/+1
The problem is that there is no easy method to insert an action after an arbitrary node in the tree, so the original fix does not correctly work when the allocator is nested in another expression. Therefore this moves the burden of the insertion from Apply_Predicate_Check to Expand_Allocator_Expression and restricts the new processing to the case where it is really required. gcc/ada/ * checks.ads (Apply_Predicate_Check): Add Deref boolean parameter. * checks.adb (Apply_Predicate_Check): Revert latest change. Use Loc local variable to hold the source location. Use a common code path for the generic processing and make a dereference if Deref is True. * exp_ch4.adb (Expand_Allocator_Expression): Compute Aggr_In_Place earlier. If it is true, do not call Apply_Predicate_Check on the expression on entry but on the temporary on exit with a dereference. * sem_res.adb (Resolve_Actuals): Add explicit parameter association in call to Apply_Predicate_Check.
2023-11-30ada: Remove SPARK legality checksYannick Moy1-95/+0
SPARK legality checks apply only to code with SPARK_Mode On, and are performed again in GNATprove for detecting SPARK-compatible declarations in code with SPARK_Mode Auto. Remove this duplication, to only perform SPARK legality checking in GNATprove. After this patch, only a few special SPARK legality checks are performed in the frontend, which could be moved to GNATprove later. gcc/ada/ * contracts.adb (Analyze_Entry_Or_Subprogram_Body_Contract): Remove checking on volatility. Remove handling of SPARK_Mode, not needed anymore. (Analyze_Entry_Or_Subprogram_Contract): Remove checking on volatility. (Check_Type_Or_Object_External_Properties): Same. (Analyze_Object_Contract): Same. * freeze.adb (Freeze_Record_Type): Same. Also remove checking on synchronized types and ghost types. * sem_ch12.adb (Instantiate_Object): Remove checking on volatility. (Instantiate_Type): Same. * sem_ch3.adb (Access_Type_Declaration): Same. (Derived_Type_Declaration): Remove checking related to untagged partial view. (Process_Discriminants): Remove checking on volatility. * sem_ch5.adb (Analyze_Loop_Parameter_Specification): Same. * sem_ch6.adb (Analyze_Procedure_Call): Fix use of SPARK_Mode where GNATprove_Mode was intended. * sem_disp.adb (Inherited_Subprograms): Protect against Empty node. * sem_prag.adb (Analyze_Global_In_Decl_Part): Remove checking on volatility. (Analyze_Pragma): Same. * sem_res.adb (Flag_Effectively_Volatile_Objects): Remove. (Resolve_Actuals): Remove checking on volatility. (Resolve_Entity_Name): Same. * sem_util.adb (Check_Nonvolatile_Function_Profile): Remove. (Check_Volatility_Compatibility): Remove. * sem_util.ads: Same.
2023-11-21ada: Fix spurious error on call with default parameter in generic packageEric Botcazou1-3/+11
This occurs when the default value is a function call returning a private type, and is caused by a bad interaction between two internal mechanisms. gcc/ada/ * sem_ch12.adb (Save_Global_References.Set_Global_Type): Beef up comment about the setting of the full view. * sem_res.adb (Resolve_Actuals.Insert_Default): Add another bypass for the case of a generic context.
2023-11-07ada: Fix incorrect resolution of overloaded function call in instanceEric Botcazou1-0/+2
The problem occurs when the function call is the operand of an equality operator, the type used to do the comparison is declared outside of the generic construct but visible inside it, and this generic construct also declares two functions with the same profile except for the result type, one result type being the aforementioned type, the other being derived from this type but not visible inside the generic construct. When the second operand is either a literal or also overloaded, the call may be resolved to the second function instead of the first in instances. gcc/ada/ * gen_il-fields.ads (Opt_Field_Enum): Add Compare_Type. * gen_il-gen-gen_nodes.adb (N_Op_Eq): Likewise. (N_Op_Ge): Likewise. (N_Op_Gt): Likewise. (N_Op_Le): Likewise. (N_Op_Lt): Likewise. (N_Op_Ne): Likewise. * sinfo.ads (Compare_Type): Document new field. * sem_ch4.adb (Analyze_Comparison_Equality_Op): If the entity is already present, set the Compare_Type on overloaded operands if it is present on the node. * sem_ch12.adb (Check_Private_View): Look into the Compare_Type instead of the Etype for comparison operators. (Copy_Generic_Node): Remove obsolete code for comparison operators. (Save_Global_References.Save_References): Do not walk into the descendants of N_Implicit_Label_Declaration nodes. (Save_Global_References.Set_Global_Type): Look into the Compare_Type instead of the Etype for comparison operators. * sem_res.adb (Resolve_Comparison_Op): Set Compare_Type. (Resolve_Equality_Op): Likewise.
2023-11-07ada: Rename Is_Limited_View to reflect actual queryYannick Moy1-2/+2
Function Sem_Aux.Is_Limited_View returns whether the type is "inherently limited" in a slightly different way from the "immutably limited" definition in Ada 2012. Rename for clarity. gcc/ada/ * exp_aggr.adb: Apply the renaming. * exp_ch3.adb: Same. * exp_ch4.adb: Same. * exp_ch6.adb: Same. * exp_ch7.adb: Same. * exp_util.adb: Same. * freeze.adb: Same. * sem_aggr.adb: Same. * sem_attr.adb: Same. * sem_aux.adb: Alphabetize Is_Limited_Type. Rename. * sem_aux.ads: Same. * sem_ch3.adb: Apply the renaming. * sem_ch6.adb: Same. * sem_ch8.adb: Same. * sem_prag.adb: Same. * sem_res.adb: Same. * sem_util.adb: Same.
2023-11-07ada: New Local_Restrictions and User_Aspect aspects.Steve Baird1-0/+8
A GNAT-defined aspect, Local_Restrictions, is defined. This provides a way of enforcing a given restriction for an individual subprogram (and its call-closure) without requiring that the entire program satisfy the restriction. A GNAT-defined aspect, User_Aspect, is defined. This (along with the new User_Aspect_Definition configuration pragma) provides a way of naming a set of aspect specifications which can then be applied to multiple declarations without textual repetition of the set. gcc/ada/ * local_restrict.ads: A new package. Declares Local_Restriction enumeration type and provides operations to check for local restriction violations. * local_restrict.adb: Corresponding package body. Replace "not Present (X)" calls with "No (X)" calls. * aspects.ads: Add a new enumeration elements, Aspect_Local_Restrictions and Aspect_User_Aspect, to the Aspect_Id enumeration type. Update Aspect_Id-indexed aggregates. Add nested package User_Aspect_Support to manage two pieces of state. One is a map from identifiers to User_Aspect_Definition pragmas (updated when such a pragma is encountered). The other is an access-to-subprogram variable that is introduced in order to keep the bulk of semantics out of the closure of package Aspects while allowing a call from aspects.adb to the sem_ch13 procedure that analyzes a User_Aspect aspect specification. * aspects.adb (Find_Aspect): Cope with a case of a block statement with an empty parent. It is not clear whether this is papering over a compiler bug. Add indirect call through the aforementioned access-to-subprogram variable when Find_Aspect enounters an unanalyzed User_Aspect aspect specification. If Find_Aspect is called looking for aspect Foo, then a User_Aspect specification might generate (during analysis) a Foo aspect specification. So the Find_Aspect call needs to trigger that analysis if it has not already taken place. Provide a body for package User_Aspect_Support. Replace "not Present (X)" call with "No (X)" call. * freeze.adb (Freeze_Subprogram): Check local restriction compatibility when a dispatching operation is overridden. * par-prag.adb: Add support for parsing a User_Aspect_Definition pragma. * restrict.ads: We'd like to have the body of package Restrict include a call to a procedure declared in package Local_Restrict. Doing that in the obvious way pulls most of semantics into the closure of package Restrict, and that turns out to cause problems. So we introduce a level of indirection and instead call through an access-to-subprogram value. In this unit, we declare the access-to-subprogram type and object. * restrict.adb (Check Restriction): When a construct is encountered that could violate a global restriction (depending on whether the given restriction is in effect), Check_Restriction is called. At this point, we also check for a violation of any corresponding local restriction that is in effect. For reasons described above, this check is performed via an indirect call. * sem_ch13.ads (Parse_Aspect_Local_Restrictions): A new function, similar to the existing Parse_Aspect_Xxx subprograms. * sem_ch13.adb: Perform semantic analysis of Local_Restrictions and User_Aspect aspect specifications. Declare and call new Validate_Aspect_Local_Restrictions and Analyze_User_Aspect_Aspect_Specification procedures (a reference to the latter is registered during package elaboration). In Analyze_Aspect_Specifications, do not set the Analyzed flag of a User_Aspect aspect specification. Replace "not Present (X)" call with "No (X)" call. Replace 'Image with 'Img in a case where the prefix of the attribute reference is an object; this is done to accomodate older compilers. * sem_ch6.adb (Check_Subtype_Conformant): Include in subtype conformance check a check for overriding-related compatibility of local restrictions. * sem_ch8.adb (Analyze_Subprogram_Renaming): In the case of an instance of a generic that takes a formal subprogram, check that formal and actual are compatible with respect to local restrictions. * sem_prag.adb: Add support for User_Aspect_Definition pragma. * sem_res.adb (Resolve_Call): Check caller/callee compatibility with respect to local restrictions. * snames.ads-tmpl: Add Name_Local_Restrictions, Name_User_Aspect, and Name_User_Aspect_Definition constants. * doc/gnat_rm/implementation_defined_aspects.rst: Document new aspects. * doc/gnat_rm/implementation_defined_pragmas.rst: Document new pragma. * doc/gnat_ugn/the_gnat_compilation_model.rst: Add User_Aspect_Definition to list of GNAT pragmas. * gcc-interface/Make-lang.in: Add local_restrict.o. * gnat-style.texi: Regenerate. * gnat_rm.texi: Regenerate. * gnat_ugn.texi: Regenerate.