aboutsummaryrefslogtreecommitdiff
path: root/gcc/ada
AgeCommit message (Collapse)AuthorFilesLines
2025-06-09ada: Support fixed-lower-bound array types as generic actual parametersGary Dismukes2-1/+13
Attempting to use a fixed-lower-bound array type (or subtype) as an actual parameter for a formal unconstrained array type was being rejected by the compiler (complaining about the index type of the actual not matching the index type of the formal type). The compiler was improperly testing the actual's FLB range and finding that it didn't statically match the index type of the formal array type; it should instead test the underlying index type of the FLB type or subtype. gcc/ada/ChangeLog: * sem_ch3.adb (Constrain_Index): In the case of a fixed-lower-bound index, set Etype of the newly created itype's Scalar_Range from the index's Etype. * sem_ch12.adb (Validate_Array_Type_Instance): If the actual subtype is a fixed-lower-bound type, then check again the Etype of its Scalar_Range.
2025-06-09ada: Reject component-related aspects on formal non-array typesPiotr Trojanek1-7/+4
In Ada 2022 aspects Atomic_Components and Volatile_Components can be specified for a formal array type, but they were wrongly accepted on any formal type. Also, we don't need to check if the corresponding pragmas appear in Ada 2022 mode, because generic formal parameters can't have explicit representation pragmas in any Ada version and can only have aspects since Ada 2022. gcc/ada/ChangeLog: * sem_prag.adb (Analyze_Pragma): Fix conditions for legality checks on formal type declarations.
2025-06-09ada: Fix glitch in handling of Atomic_Components on generic formal typePiotr Trojanek1-1/+3
In Ada 2022 aspects Atomic_Components and Volatile_Components can be specified for a formal array type, but then they need to be set on the base type entity. Otherwise we get an assertion failure in debug build and wrong legality errors in production builds. gcc/ada/ChangeLog: * sem_prag.adb (Analyze_Pragma): If pragmas apply to a formal array type, then set the flags on the base type.
2025-06-09ada: Clarify code in Process_SubtypeRonan Desplanques1-47/+43
This patch factorizes two if statements together in the body of Process_Subtype, to improve readability. gcc/ada/ChangeLog: * sem_ch3.adb (Process_Subtype): Clarify code.
2025-06-09ada: Add null exclusion formal to Process_SubtypeRonan Desplanques3-52/+38
Before this patch, Process_Subtype looked at the parent of its argument to determine whether it was called in a context that excluded null. This patch replaces this lookup with a new formal parameter to Process_Subtype, and updates the calls to it accordingly. gcc/ada/ChangeLog: * sem_ch3.ads (Process_Subtype): Add formal. * sem_ch3.adb (Process_Subtype): Use new formal. (Analyze_Subtype_Declaration, Array_Type_Declaration, Build_Derived_Access_Type): Pass new actual. * sem_ch4.adb (Find_Type_Of_Object): Likewise.
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-09ada: Missing discriminant check on assignment of Bounded_Vector aggregateGary Dismukes1-1/+10
When a container aggregate for a Bounded_Vector type involves an iterated association that is assigned to a vector object whose capacity (as defined by the Capacity discriminant) is less than the number of elements of the aggregate, Constraint_Error should be raised due to failing a discriminant check on the assignment. But the compiler fails to do proper expansion, plus omits the check, and instead creates a temporary whose capacity is bounded by that of the target vector of the assignment. It attempts to assign all elements of the aggregate to the temporary, resulting in a failure on a call to the Replace_Element operation that assigns past the length of the temporary vector (which can result in a Storage_Error due to a segment violation). This is fixed by ensuring that the temporary object is declared with an unconstrained base subtype rather than the assignment target's constrained subtype. gcc/ada/ChangeLog: * exp_aggr.adb (Expand_Container_Aggregate): Use the Base_Type of the subtype provided by the context as the subtype of the temporary object initialized by the aggregate.
2025-06-09ada: Remove duplicated code in parser for Chapter 4 (continued)Eric Botcazou3-77/+4
P_Qualified_Simple_Name and P_Function_Name contain essentially the same code, except that P_Function_Name does not error out on an operator symbol that is followed by something else than a dot. This deletes P_Function_Name and changes P_Qualified_Simple_Name[_Resync] to not error out either in this case, with the only consequence that the error message given for: generic type T is private; function "&" (A, B : String) return String; procedure Proc is new "&" (Integer); is now identical to the one given for: generic type T is private; function "&" (A, B : String) return String; function Func is new "&" (Integer); namely: q.ads:7:12: error: operator symbol not allowed for generic subprogram gcc/ada/ChangeLog: * par-ch4.adb (P_Function_Name): Delete body. (P_Qualified_Simple_Name_Resync): Do not raise Error_Resync on an operator symbol followed by something else than a dot. * par-ch6.adb (P_Subprogram): Do not call P_Function_Name. * par.adb (P_Function_Name): Delete declaration.
2025-06-09ada: Set Ekind of components earlierRonan Desplanques2-6/+6
Before this patch, the calls to set the proper Ekind of component entities were delayed in order to catch "premature usage" type of errors. This patch moves those calls to the natural place, at the beginning of Analyze_Component_Declaration, and makes premature usage error dectection use the newer Is_Self_Hidden mechanism. The motivation for this patch is to accomodate future removals of operations on E_Void entities. gcc/ada/ChangeLog: * sem.adb (Analyze): Adapt to new Ekinds. * sem_ch3.adb (Analyze_Component_Declaration): Set Ekind early. (Is_Visible_Component, Record_Type_Definition): Adjust.
2025-06-09ada: Fix commentRonan Desplanques1-1/+1
gcc/ada/ChangeLog: * sem.adb (Analyze): Fix comment.
2025-06-09ada: Remove duplicated code in parser for Chapter 4Eric Botcazou1-61/+8
P_Qualified_Simple_Name and P_Qualified_Simple_Name_Resync contain exactly the same code, so this change makes the former call the latter. gcc/ada/ChangeLog: * par-ch4.adb (P_Name): Remove obsolete references in comments. (P_Qualified_Simple_Name): Call P_Qualified_Simple_Name_Resync. (P_Qualified_Simple_Name_Resync): Adjust a couple of comments.
2025-06-09ada: Fix SPARK test failures caused by new handling of inherited class-wide ↵Gary Dismukes1-9/+14
pre/post The revised handling of inherited class-wide pre/postconditions (for properly implementing the rules of RM 6.1.1(7/5)) broke two SPARK tests (N709-001__contracts and V516-041__private_ownership). This change fixes that, by refining the test for detecting formal parameters used as actuals in calls to primitive functions, as well as adding handling for 'Result attributes given as actuals in such calls. gcc/ada/ChangeLog: * exp_util.adb (Call_To_Parent_Dispatching_Op_Must_Be_Mapped): Replace test of Covers with test of Is_Controlling_Formal. Add handling for 'Result actuals. Remove Actual_Type and its uses.
2025-06-09ada: Simplify handling of selected components as name referencesPiotr Trojanek1-13/+1
The selector_name of a selected_component always points to an identifier than is an object name, i.e. specifically, name of a component or discriminant. There is no need to examine this. Code cleanup; behavior is unaffected. gcc/ada/ChangeLog: * sem_util.adb (Is_Name_Reference): Remove check for selector_name of a selected_component; reuse existing code for indexed components and slices. (Statically_Names_Object): Remove dead code.
2025-06-09ada: Restrict Overlays_Constant flag to selected entitiesEric Botcazou3-6/+7
Namely E_Constant and E_Variable entities. gcc/ada/ChangeLog: * einfo.ads (Overlays_Constant): Define in constants and variables. * gen_il-gen-gen_entities.adb (Entity_Kind): Move Overlays_Constant semantic flag to... (Constant_Or_Variable_Kind): ...here. * sem_util.adb (Note_Possible_Modification): Add guard.
2025-06-09ada: Back out removal of renaming tranformationBob Duff2-0/+29
A previous change (commit 33eebd96d27fa2b29cec79f55167a11aaf7f4802) removed code in Analyze_Object_Renaming that tranformed renamings into object declarations. This reinstates that code. Removing the code causes failures in gnatbugs-large/2023/gnat-435_deep_blue_capital. Ideally, we SHOULD remove that transformation at some point, but that will require further changes. gcc/ada/ChangeLog: * exp_ch6.adb: (Make_Build_In_Place_Call_In_Object_Declaration): Deal with renamings transformed into object declarations. * sem_ch8.adb (Analyze_Object_Renaming): Reinstate transformation of a renaming into an object declaration.
2025-06-09ada: Set Ekind early in object declarationsRonan Desplanques1-14/+6
Setting the proper Ekind on object entities was once needed to catch cases of premature usages. The introduction of Is_Self_Hidden changed that, so this patch replaces the Mutate_Ekind calls in the natural place. gcc/ada/ChangeLog: * sem_ch3.adb (Analyze_Object_Declaration): Call Mutate_Ekind earlier.
2025-06-09ada: Tweak error recovery pathRonan Desplanques1-1/+0
Before this patch, the constant mark of object declarations was stripped in some error situations. This behavior is currently not useful so this patch removes it. gcc/ada/ChangeLog: * sem_ch3.adb (Analyze_Object_Declaration): Tweak error handling.
2025-06-09ada: Specialize syntax error on malformed Abstract_State contractPiotr Trojanek4-10/+26
Syntax for the Abstract_State contract is the same as for extended aggregates, but conceptually they are completely different. This patch specializes error messages emitted on syntax errors for these constructs. gcc/ada/ChangeLog: * par-ch13.adb (Get_Aspect_Specifications): Save and restore flag while parsing aspect Abstract_State. * par-ch2.adb (P_Pragma): Same while parsing pragma Abstract_State. * par-ch4.adb (P_Aggregate_Or_Paren_Expr): Specialize error message for contract Abstract_State and extended aggregate. * par.adb (Inside_Abstract_State): Add new context flag.
2025-06-09ada: Do not build dispatch tables for genericsRonan Desplanques2-2/+10
Before this patch, Build_Static_Dispatch_Tables was called on generic package bodies. While this has not been proved to cause any actual bug, it was clearly inappropriate and also useless, so this patch removes those calls. gcc/ada/ChangeLog: * sem_ch10.adb (Analyze_Compilation_Unit): Check for generic bodies. * exp_disp.adb (Build_Dispatch_Tables): Likewise.
2025-06-09ada: Tune recent change for warning about unsupported overlaysPiotr Trojanek1-24/+6
Fix crash occurring when overlay applies to protected component and expansion is disabled, e.g. because of semantic checking mode (switch -gnatc) or because the compiler is running in GNATprove mode. Also, simply pick the type of overlaid object from the attribute prefix itself. gcc/ada/ChangeLog: * sem_util.adb (Find_Overlaid_Entity): Don't call Etype on empty Ent; tune style; move computation of Overl_Typ out of the loop.
2025-06-09ada: Pragma Ada_XX not propagated from library level spec to bodyJavier Miranda4-1/+59
Add documentation to pragmas Ada_83, Ada_95, Ada_05, Ada_12, and Ada_2022: when placed before a library level package specification they are not propagated to the corresponding package body; they must be added explicitly to the package body. gcc/ada/ChangeLog: * doc/gnat_rm/implementation_defined_pragmas.rst: Adding documentation. * doc/gnat_ugn/the_gnat_compilation_model.rst: ditto. * gnat_rm.texi: Regenerate. * gnat_ugn.texi: Regenerate.
2025-06-09ada: Remove redundant error checkingRonan Desplanques1-11/+7
This patch removes a test for a condition that can never be false. gcc/ada/ChangeLog: * sem_attr.adb (Analyze_Attribute): Remove test.
2025-06-09ada: Remove unnecessary special handlingRonan Desplanques1-11/+1
This patch removes a special exemption in Enter_Name. That exemption was preceded by a comment which described what situations it was supposed to be required for, but it was unnecessary even in those situations. gcc/ada/ChangeLog: * sem_util.adb (Enter_Name): Remove special handling.
2025-06-09ada: Remove misleading commentRonan Desplanques1-3/+0
This patch removes a comment that misleadingly presented a condition as being met only in rare situations, while it's in fact satisfied in very basic cases such as simple object declarations. gcc/ada/ChangeLog: * sem_util.adb (Enter_Name): Remove comment.
2025-06-09ada: Constraint check on tagged build-in-place object declsBob Duff3-39/+30
In the case of "X : T := F (...);", where T is a constrained discriminated tagged subtype, perform a constraint check after F returns. The result of F is allocated by the callee on the secondary stack in this case. Note that there are still missing checks for some build-in-place calls. gcc/ada/ChangeLog: * exp_ch6.adb: Remove a couple of "???" suggesting something that we will likely never do. (Make_Build_In_Place_Call_In_Object_Declaration): When a constraint check is needed, do the check. Do it at the call site for now. The check is still missing in the untagged case, because the caller allocates in that case. * sem_ch8.adb (Analyze_Object_Renaming): Remove obsolete transformation of a renaming into an object declaration. Given that we also (sometimes) tranform object declarations into renamings, this transformation was adding complexity; the new code in Make_Build_In_Place_Call_In_Object_Declaration above would need to explicitly avoid the run-time check in the case of renamings, because renamings are supposed to ignore the nominal subtype. Anyway, it is no longer needed. * exp_ch3.adb (Expand_N_Object_Declaration): Rewrite comment; it IS clear how to do it, but we haven't done it right yet.
2025-06-09ada: Remove incorrect bits in Copy_Node documentationRonan Desplanques1-9/+5
This patch removes a leftover reference to the concept of node extension and a note about aspect specification that's been incorrect since at least the latest rework of aspect specification representation. gcc/ada/ChangeLog: * atree.ads (Copy_Node): Fix comment.
2025-06-09ada: Check validity using signedness from the type and not its base typePiotr Trojanek1-3/+2
When attribute Valid is applied to a private type, we used the signedness of its implementation base type which wrongly included negative values. gcc/ada/ChangeLog: * exp_attr.adb (Expand_N_Attribute_Reference): When expanding attribute Valid, use signedness from the validated view, not from its base type.
2025-06-09ada: Emit more warnings on unsupported overlayMarc Poulhiès4-16/+48
In the case where the overlaid object is nested in a record or is an array element as in: for Foo'Address use Item.Nested_Item'Address; or for Foo'Address use Item (Bar)'Address; the compiler was not emitting a warning in case of differing Scalar_Storage_Order values. gcc/ada/ChangeLog: * sem_util.adb (Find_Overlaid_Entity): Add extra parameter to extract the type being overlaid. (Note_Possible_Modification): Adjust call to Find_Overlaid_Entity. (Ultimate_Overlaid_Entity): Likewise. * sem_ch13.adb (Analyze_Attribute_Definition_Clause): Likewise. * sem_util.ads (Find_Overlaid_Entity): Add extra parameter to extract the type being overlaid. * freeze.adb (Check_Address_Clause): Likewise.
2025-06-09ada: Incorrect creation of corresponding expression of class-wide contractsGary Dismukes2-95/+121
GNAT was incorrectly implementing the Ada rules for resolving calls to primitive functions within inherited class-wide pre- and postconditions, as specified in RM22 6.1.1 (relating to AI12-0113). Only function calls that involve formals of the associated primitive subprogram should be treated using the "(notional) formal derived type" rules. In particular, calls that are tag-indeterminate (for example, "F(G)") should not be mapped to call the corresponding primitives of the derived type (they should still call the primitives of the ancestor type). The fix for this involves a new predicate function that recursively traverses calls to determine the calls that satisfy the criteria for mapping. These changes also completely remove the mapping of formals that was done in Contracts.Merge_Class_Conditions (in Inherit_Condition), since the mapping will be done later anyway by Build_Class_Wide_Expression, and the earlier mapping interferes with that. Note: The utility function Sem_Util.Check_Parents is no longer called after removal of the single call to it from contracts.adb, but it's being retained (along with the generic subprograms in Atree that it depends on) for possible use in VAST. gcc/ada/ChangeLog: * contracts.adb (Inherit_Condition): Remove Assoc_List and its uses along with function Check_Condition, since mapping of formals will effectively be done in Build_Class_Wide_Expression (by Replace_Entity). * exp_util.adb (Replace_Entity): Only rewrite entity references in function calls that qualify according to the result of calling the new function Call_To_Parent_Dispatching_Op_Must_Be_Mapped. (Call_To_Parent_Dispatching_Op_Must_Be_Mapped): New function that determines whether a function call to a primitive of Par_Subp associated tagged type needs to be mapped (according to whether it has any actuals that reference controlling formals of the primitive).
2025-06-09ada: Remove outdated commentRonan Desplanques1-3/+1
This patch removes a comment that was made incorrect by the introduction of Is_Self_Hidden. gcc/ada/ChangeLog: * sem_ch3.adb (Analyze_Object_Declaration): Remove comment.
2025-06-09ada: Add example in Current_Entity_In_Scope commentRonan Desplanques1-1/+15
gcc/ada/ChangeLog: * sem_util.ads (Current_Entity_In_Scope): Add example in comment.
2025-06-09ada: Clarify warning in Atree.Rewrite documentationRonan Desplanques1-7/+6
The documentation of Atree.Rewrite warns about a potential misuse of that subprogram. This patch makes the text of that warning more specific. The documentation of Atree.Replace had the same note but this patch replaces it with a mention of the one in Rewrite's documentation. gcc/ada/ChangeLog: * atree.ads (Rewrite, Replace): Clarify comments.
2025-06-09ada: Remove incorrect commentRonan Desplanques1-5/+1
This patchs removes a comment that was incorrect, as noted by a ??? comment that was right after and that this patch also removes. gcc/ada/ChangeLog: * atree.ads (Rewrite): Remove comment.
2025-06-09ada: Improve readability in Atree.Rewrite bodyRonan Desplanques1-1/+1
This patch visually packs together the statements that implement the exceptions in Rewrite that a few fields are not actually overwritten, in order to improve the readability of the code. gcc/ada/ChangeLog: * atree.adb (Rewrite): Improve readability.
2025-06-09ada: Tweak Kill_Current_ValuesRonan Desplanques1-1/+1
Is_Object returns True for "record field" entities, which might make sense in some contexts but not when Kill_Current_Values is called in a default expression of a record component. This patch refines the choice of considered entities in Kill_Current_Values accordingly. gcc/ada/ChangeLog: * sem_util.adb (Kill_Current_Values): Tweak condition.
2025-06-09ada: Fix spurious error on anonymous array initialized by conditional expressionEric Botcazou1-22/+21
Even though the actual subtype of the anonymous array is not yet set on the object itself by the time Insert_Conditional_Object_Declaration is called, it is set on its initialization expression, so it can simply be forwarded to Insert_Conditional_Object_Declaration from there, which avoids creating a new one for each new object and triggering a subtype mismatch later. gcc/ada/ChangeLog: * exp_ch4.adb (Insert_Conditional_Object_Declaration): Remove Decl formal parameter, add Typ and Const formal parameters. (Expand_N_Case_Expression): Fix pasto in comment. Adjust call to Insert_Conditional_Object_Declaration and tidy up surrounding code. (Expand_N_If_Expression): Adjust couple of calls to Insert_Conditional_Object_Declaration.
2025-06-09ada: Fix assertion failure on error pathRonan Desplanques1-0/+1
gcc/ada/ChangeLog: * sem_ch8.adb (Find_Selected_Component): Fix error path.
2025-06-09ada: Rename Is_Infinity to Is_Infinity_Or_NaN in System.Double_RealEric Botcazou3-12/+12
The predicate is used to detect corner cases in multiplicative operations and also returns True for NaNs. gcc/ada/ChangeLog: * libgnat/s-dourea.adb (Is_Infinity): Rename to... (Is_Infinity_Or_NaN): ...this. ("*"): Adjust accordingly. ("/"): Likewise. (Sqr): Likewise. * libgnat/s-dorepr.adb (Two_Prod): Likewise. (Two_Sqr): Likewise. * libgnat/s-dorepr__fma.adb (Two_Prod): Likewise.
2025-06-09ada: Fix bindings for CHERI Set_Bounds and Set_Exact_Bounds intrinsics.Daniel King2-4/+26
gcc/ada/ChangeLog: * libgnat/i-cheri.ads (Set_Bounds, Set_Exact_Bounds): Remove wrong intrinsic binding. * libgnat/i-cheri.adb (Set_Bounds, Set_Exact_Bounds): New subprogram bodies.
2025-06-09ada: Add Ada RM clause mentionRonan Desplanques1-1/+2
This patch adds a mention of the relevant Ada RM clause to a comment about a part of Find_Selected_Component, to make it easier to find. gcc/ada/ChangeLog: * sem_ch8.adb (Find_Selected_Component): Add mention.
2025-06-07Daily bump.GCC Administrator1-0/+476
2025-06-06ada: Avoid repeated range checks when negating a rational numberPiotr Trojanek1-4/+5
Use local constant to avoid repeated range checks (at least in the debug builds), but also to make the code easier to read and consistent in style with similar routines in the same package. gcc/ada/ChangeLog: * urealp.adb (UR_Negate): Capture array element in a local constant.
2025-06-06ada: Remove repeated call in exponentiation of rational numbersPiotr Trojanek1-1/+1
Code cleanup. gcc/ada/ChangeLog: * urealp.adb (UR_Exponentiate): Use local variable.
2025-06-06ada: Simplify tests for positive rational numbersPiotr Trojanek2-2/+2
Checking a rational number for being positive takes a shorter code path than a general comparison with zero. Code cleanup; semantics is unaffected. gcc/ada/ChangeLog: * sem_ch13.adb (Analyze_Attribute_Definition_Clause): Tune code for attribute Small. * sem_prag.adb (Analyze_Attribute): Tune code for pragma Time_Slice.
2025-06-06ada: Tune style in code for floating-point numbersPiotr Trojanek7-36/+41
Cleanup whitespace and comments. gcc/ada/ChangeLog: * ada_get_targ.adb, cstand.ads, cstand.adb, sem_eval.adb, sem_eval.ads, urealp.adb, urealp.ads: Tune style.
2025-06-06ada: Add null exclusion to registration of floating-point typesPiotr Trojanek1-1/+1
Null exclusion both clarifies the intention of the code and allows GNAT to eliminate runtime checks where possible (or make them fail where violated), at least in developer builds. Code cleanup. gcc/ada/ChangeLog: * get_targ.ads (Register_Proc_Type): Add null exclusion.
2025-06-06ada: Refine subtypes in routines for building floating-point numbersPiotr Trojanek2-6/+6
Propagate strict subtypes from callees to the caller; code cleanup. gcc/ada/ChangeLog: * cstand.adb (Build_Float_Type, Register_Float_Type): Refine parameter subtypes. * set_targ.ads (FPT_Mode_Entry): Refine component subtype.
2025-06-06ada: Check references to subprogram outputs with Program_Exit expressionPiotr Trojanek1-0/+51
Add check for references to subprogram outputs occurring within the Program_Exit expression. This check is necessarily partial, as it misses objects referenced by subprograms called from the Program_Exit expression, but this is consistent with other checks. gcc/ada/ChangeLog: * sem_prag.adb (Analyze_Pragma): Add dependency of Program_Exit on Global and Depends contracts. (Analyze_Program_Exit_In_Decl_Part): Check references to subprogram outputs.
2025-06-06ada: Add case for Program_Exit in Exit_CasesClaire Dross4-4/+9
Extend the syntax for Exit_Cases to support exiting the program. gcc/ada/ChangeLog: * doc/gnat_rm/implementation_defined_pragmas.rst (Pragma Exit_Cases): Update the documentation for Exit_Cases. * sem_prag.adb (Anlayze_Pragma): Accept Program_Exit as an exit kind. * gnat_rm.texi: Regenerate. * gnat_ugn.texi: Regenerate.
2025-06-06ada: Support aspect Program_Exit with no expressionPiotr Trojanek5-43/+48
New aspect Program_Exit for SPARK was originally designed to require an expression, but now we want this expression to be optional. gcc/ada/ChangeLog: * aspects.ads (Aspect_Argument): Argument for Program_Exit is now optional. * doc/gnat_rm/implementation_defined_pragmas.rst (Pragma Program_Exit): Change documentation for pragma syntax. * sem_prag.adb (Analyze_Pragma): Argument for Program_Exit is now optional. (Analyze_Program_Exit_In_Decl_Part): Likewise. * gnat_rm.texi: Regenerate. * gnat_ugn.texi: Regenerate.