aboutsummaryrefslogtreecommitdiff
path: root/gcc
AgeCommit message (Collapse)AuthorFilesLines
2023-09-27ada: Fix small inaccuracy in implementation of B.3.3(20/2)Eric Botcazou1-21/+14
This is the clause about inferable discriminants in unchecked unions. gcc/ada/ * sem_util.adb (Has_Inferable_Discriminants): In the case of a component with a per-object constraint, also return true if the enclosing object is not of an unchecked union type. In the default case, remove a useless call to Base_Type.
2023-09-27ada: Fix bad interaction between inlining and thunk generationEric Botcazou1-3/+6
This may cause the type of the RESULT_DECL of a function which returns by invisible reference to be turned into a reference type twice. gcc/ada/ * gcc-interface/trans.cc (Subprogram_Body_to_gnu): Add guard to the code turning the type of the RESULT_DECL into a reference type. (maybe_make_gnu_thunk): Use a more precise guard in the same case.
2023-09-27ada: Fix wrong finalization for double subtype of bounded vectorEric Botcazou1-4/+10
The special handling of temporaries created for return values and subject to a renaming needs to be restricted to the top level, where it is needed to prevent dangling references to the frame of the elaboration routine from being created, because, at a lower level, the front-end may create implicit renamings of objects as these temporaries, so a copy is not allowed. gcc/ada/ * gcc-interface/decl.cc (gnat_to_gnu_entity) <E_Variable>: Restrict the special handling of temporaries created for return values and subject to a renaming to the top level.
2023-09-27Minor tweakEric Botcazou1-3/+3
gcc/ada/ * gcc-interface/decl.cc (gnat_to_gnu_entity) <E_Variable>: Tweak.
2023-09-27ada: Fix too small secondary stack allocation for returned conversionEric Botcazou2-30/+63
The previous fix did not address a latent issue whereby the allocation would be made using the (static) subtype of the conversion instead of the (dynamic) subtype of the return object, so this change rewrites the code responsible for determining the type used for the allocation, and also contains a small improvement to the Has_Tag_Of_Type predicate. gcc/ada/ * exp_ch3.adb (Make_Allocator_For_Return): Rewrite the logic that determines the type used for the allocation and add assertions. * exp_util.adb (Has_Tag_Of_Type): Also return true for extension aggregates.
2023-09-27ada: Fix too small secondary stack allocation for returned aggregateEric Botcazou1-3/+14
This restores the specific treatment of aggregates that are returned through an extended return statement in a function returning a class-wide type, and which was incorrectly dropped in an earlier change. gcc/ada/ * exp_ch3.adb (Make_Allocator_For_Return): Deal again specifically with an aggregate returned through an object of a class-wide type.
2023-09-27ada: Fix missing error on function call returning incomplete viewEric Botcazou1-0/+6
Testing for the presence of Non_Limited_View is not sufficient to detect whether the nonlimited view has been analyzed because Build_Limited_Views always sets the field on the limited view. Instead the discriminant is whether this nonlimited view is itself an incomplete type. gcc/ada/ * sem_ch4.adb (Analyze_Call): Adjust the test to detect the presence of an incomplete view of a type on a function call.
2023-09-27ada: Fix inverted implementation of RM 8.4(10) clause for operatorsEric Botcazou1-1/+1
The comment is correct but the code implements the opposite outcome. gcc/ada/ * sem_type.adb (Disambiguate): Fix pasto in the implementation of the RM 8.4(10) clause for operators.
2023-09-27ada: Fix aspect Linker_Section ignored on subprogram bodyEric Botcazou1-12/+19
The compiler is waiting for the freeze node of the body, but it is never generated since the freezing of the body is not delayed. The change also removes an obsolete piece of code. gcc/ada/ * sem_ch13.adb (Analyze_Aspect_Specifications): Add missing items in the list of aspects handled by means of Insert_Pragma. <Aspect_Linker_Section>: Remove obsolete code. Do not delay the processing of the aspect if the entity is already frozen.
2023-09-27ada: Fix exception raised on invalid contract in generic packageEric Botcazou1-10/+21
This lets the compiler give a proper error message instead. gcc/ada/ * contracts.adb (Contract_Error): New exception. (Add_Contract_Item): Raise Contract_Error instead of Program_Error. (Add_Generic_Contract_Pragma): Deal with Contract_Error.
2023-09-27ada: Fix internal error on imported function with post-conditionEric Botcazou1-0/+16
The problem, which is also present for an expression function, is that the function is invoked in the initializing expression of a variable declared in the same declarative part as the function, which causes the freezing of its artificial body before the post-condition is analyzed on its spec. gcc/ada/ * contracts.adb (Analyze_Entry_Or_Subprogram_Body_Contract): For a subprogram body that has no contracts and does not come from source, make sure that contracts on its corresponding spec are analyzed, if any, before expanding them.
2023-09-27ada: Fix wrong expansion of array aggregate with noncontiguous choicesEric Botcazou1-20/+18
This extends an earlier fix done for the others choice of an array aggregate to all the choices of the aggregate, since the same sharing issue may happen when the choices are not contiguous. gcc/ada/ * exp_aggr.adb (Build_Array_Aggr_Code.Get_Assoc_Expr): Duplicate the expression here instead of... (Build_Array_Aggr_Code): ...here.
2023-09-27ada: Fix internal error on array constant in expression functionEric Botcazou1-4/+21
This happens when the peculiar check emitted by Check_Large_Modular_Array is applied to an object whose actual subtype is an itype with dynamic size, because the first reference to the itype in the expanded code may turn out to be within the raise statement, which is problematic for the eloboration of this itype by the code generator at library level. gcc/ada/ * freeze.adb (Check_Large_Modular_Array): Fix head comment, use Standard_Long_Long_Integer_Size directly and generate a reference just before the raise statement if the Etype of the object is an itype declared in an open scope.
2023-09-27ada: Fix fallout of recent fix for missing finalizationEric Botcazou1-10/+26
The original fix makes it possible to create transient scopes around return statements in more cases, but it overlooks that transient scopes are reused and, in particular, that they can be promoted to secondary stack management. gcc/ada/ * exp_ch7.adb (Find_Enclosing_Transient_Scope): Return the index in the scope table instead of the scope's entity. (Establish_Transient_Scope): If an enclosing scope already exists, do not set the Uses_Sec_Stack flag on it if the node to be wrapped is a return statement which requires secondary stack management.
2023-09-27ada: Fix regression of secondary stack management in return statementsEric Botcazou1-38/+31
This happens when the expression of the return statement is a call that does not return on the same stack as the enclosing function. gcc/ada/ * sem_res.adb (Resolve_Call): Restrict previous change to calls that return on the same stack as the enclosing function. Tidy up.
2023-09-27ada: Fix visibility error with DIC or Type_Invariant aspect on generic typeEric Botcazou1-2/+17
The compiler fails to capture global references during the analysis of the aspect on the generic type because it analyzes a copy of the expression. gcc/ada/ * exp_util.adb (Build_DIC_Procedure_Body.Add_Own_DIC): When inside a generic unit, preanalyze the expression directly. (Build_Invariant_Procedure_Body.Add_Own_Invariants): Likewise.
2023-09-27ada: Fix spurious error on imported generic function with preconditionEric Botcazou1-7/+1
It occurs during the instantiation because the compiler forgets the context of the generic declaration. gcc/ada/ * freeze.adb (Wrap_Imported_Subprogram): Use Copy_Subprogram_Spec in both cases to copy the spec of the subprogram.
2023-09-27ada: Fix memory leak in expression function returning Big_IntegerEric Botcazou2-16/+28
We fail to establish a transient scope around the return statement because the function returns a controlled type, but this is no longer problematic because controlled types are no longer returned on the secondary stack. gcc/ada/ * exp_ch7.adb (Establish_Transient_Scope.Find_Transient_Context): Bail out for a simple return statement only if the transient scope and the function both require secondary stack management, or else if the function is a thunk. * sem_res.adb (Resolve_Call): Do not create a transient scope when the call is the expression of a simple return statement.
2023-09-27ada: Call idiomatic routine in Expand_Simple_Function_ReturnEric Botcazou1-1/+1
In the primary stack case, Insert_Actions is invoked when the expression is being rewritten, whereas Insert_List_Before_And_Analyze is invoked in the secondary stack case. The former is idiomatic, the latter is not. gcc/ada/ * exp_ch6.adb (Expand_Simple_Function_Return): Call Insert_Actions consistently when rewriting the expression.
2023-09-27ada: Fix wrong finalization for loop on indexed containerEric Botcazou1-3/+99
The problem is that a transient temporary created for the constant indexing of the container is finalized almost immediately after its creation. gcc/ada/ * exp_util.adb (Is_Finalizable_Transient.Is_Indexed_Container): New predicate to detect a temporary created to hold the result of a constant indexing on a container. (Is_Finalizable_Transient.Is_Iterated_Container): Adjust a couple of obsolete comments. (Is_Finalizable_Transient): Return False if Is_Indexed_Container returns True on the object.
2023-09-27ada: Fix bogus error on conditional expression with only user-defined literalsEric Botcazou1-29/+98
This implements the recursive resolution of conditional expressions whose dependent expressions are (all) user-defined literals the same way it is implemented for operators. gcc/ada/ * sem_res.adb (Has_Applicable_User_Defined_Literal): Make it clear that the predicate also checks the node itself. (Try_User_Defined_Literal): Move current implementation to... Deal only with literals, named numbers and conditional expressions whose dependent expressions are literals or named numbers. (Try_User_Defined_Literal_For_Operator): ...this. Remove multiple return False statements and put a single one at the end. (Resolve): Call Try_User_Defined_Literal instead of directly Has_Applicable_User_Defined_Literal for all nodes. Call Try_User_Defined_Literal_For_Operator for operator nodes.
2023-09-27ada: Fix wrong finalization for case expression in expression functionEric Botcazou1-2/+6
This happens when the case expression contains a single alternative. gcc/ada/ * exp_ch5.adb (Expand_N_Case_Statement): Do not remove the statement if it is the node to be wrapped by a transient scope.
2023-09-27ada: Fix internal error with pragma Compile_Time_{Warning,Error}Eric Botcazou1-2/+7
This happens when the pragmas are deferred to the back-end from an external unit to the main unit that is generic, because the back-end does not compile a main unit that is generic. gcc/ada/ * sem_prag.adb (Process_Compile_Time_Warning_Or_Error): Do not defer anything to the back-end when the main unit is generic.
2023-09-27ada: Fix small fallout of previous changeEric Botcazou1-4/+6
It may lead to an infinite recursion if no interpretation exists. gcc/ada/ * sem_res.adb (Try_User_Defined_Literal): Restrict previous change to non-leaf nodes.
2023-09-27ada: Fix remaining failures in Roman Numbers testEric Botcazou1-2/+6
The test is inspired from the example of user-defined literals given in the Ada 2022 RM. Mixed Arabic numbers/Roman numbers computations are rejected because the second resolution pass would try to resolve Arabic numbers only as user-defined literals. gcc/ada/ * sem_res.adb (Try_User_Defined_Literal): For arithmetic operators, also accept operands whose type is covered by the resolution type.
2023-09-27ada: Fix wrong result for membership test of null in null-excluding access typeEric Botcazou1-3/+5
The result must be False as per the RM 4.5.2 (30.2/4) clause. gcc/ada/ * exp_ch4.adb (Expand_N_In): Deal specifically with a null operand.
2023-09-27ada: Fix small fallout of previous changeEric Botcazou1-0/+7
The same guard must be added to Expand_Simple_Function_Return as the one that was added to Analyze_Function_Return. gcc/ada/ * exp_ch6.adb (Expand_Simple_Function_Return): Deal with a rewriting of the simple return during the adjustment of its expression.
2023-09-27ada: Fix wrong finalization for call to BIP function in conditional expressionEric Botcazou3-55/+138
This happens when the call is a dependent expression of the conditional expression, and the conditional expression is either the expression of a simple return statement or the return expression of an expression function. The reason is that the special processing of "tail calls" for BIP functions, i.e. calls that are the expression of simple return statements or the return expression of expression functions, is not applied. This change makes sure that it is applied by distributing the simple return statements enclosing conditional expressions into the dependent expressions of the conditional expressions in almost all cases. As a side effect, this elides a temporary in the nonlimited by-reference case, as well as a pair of calls to Adjust/Finalize in the nonlimited controlled case. gcc/ada/ * exp_ch4.adb (Expand_N_Case_Expression): Distribute simple return statements enclosing the conditional expression into the dependent expressions in almost all cases. (Expand_N_If_Expression): Likewise. (Process_Transient_In_Expression): Adjust to the above distribution. * exp_ch6.adb (Expand_Ctrl_Function_Call): Deal with calls in the dependent expressions of a conditional expression. * sem_ch6.adb (Analyze_Function_Return): Deal with the rewriting of a simple return statement during the resolution of its expression.
2023-09-27ada: Repair support for user-defined literals in arithmetic operatorsEric Botcazou3-155/+156
It was partially broken to fix a regression in error reporting, because the fix was applied to the first pass of resolution instead of the second pass, as needs to be done for user-defined literals. gcc/ada/ * sem_ch4.ads (Unresolved_Operator): New procedure. * sem_ch4.adb (Has_Possible_Literal_Aspects): Rename into... (Has_Possible_User_Defined_Literal): ...this. Tidy up. (Operator_Check): Accept again unresolved operators if they have a possible user-defined literal as operand. Factor out the handling of the general error message into... (Unresolved_Operator): ...this new procedure. * sem_res.adb (Resolve): Be prepared for unresolved operators on entry in Ada 2022 or later. If they are still unresolved on exit, call Unresolved_Operator to give the error message. (Try_User_Defined_Literal): Tidy up.
2023-09-27ada: Fix spurious error on nested instantiations with generic renamingEric Botcazou1-9/+18
The problem is that the renaming slightly changes the form of a global reference that was saved during the analysis of a generic package, and that is sufficient to fool the code adjusting global references during the instantiation. gcc/ada/ * sem_ch12.adb (Copy_Generic_Node): Test the original node kind for the sake of consistency. For identifiers and other entity names and operators, accept an expanded name as associated node. Replace "or" with "or else" in condtion and fix its formatting.
2023-09-27ada: Fix internal error on Big_Integer conversion ghost instanceEric Botcazou1-12/+12
The problem is that the ghost mode of the instance is used to analyze the parent of the generic body, whose own ghost mode has nothing to do with it. gcc/ada/ * sem_ch12.adb (Instantiate_Package_Body): Set the ghost mode to that of the instance only after loading the generic's parent. (Instantiate_Subprogram_Body): Likewise.
2023-09-27ada: Reject thin 'Unrestricted_Access value to aliased constrained arrayEric Botcazou1-23/+51
This rejects the Unrestricted_Access attribute applied to an aliased array with a constrained nominal subtype when its type is resolved to be a thin pointer. The reason is that supporting this case would require the aliased array to contain its bounds, and this is the case only for aliased arrays whose nominal subtype is unconstrained. gcc/ada/ * sem_attr.adb (Is_Thin_Pointer_To_Unc_Array): New predicate. (Resolve_Attribute): Apply the static matching legality rule to an Unrestricted_Access attribute applied to an aliased prefix if the type is a thin pointer. Call Is_Thin_Pointer_To_Unc_Array for the aliasing legality rule as well.
2023-09-27ada: Add missing guards in Selected_Range_ChecksEric Botcazou1-0/+2
gcc/ada/ * checks.adb (Selected_Range_Checks): Add guards to protect calls to Expr_Value on bounds.
2023-09-27ada: Fix internal error on declare-expression in post-conditionEric Botcazou1-5/+7
It comes from an incorrect node sharing in the expanded tree. gcc/ada/ * sem_ch3.adb (Find_Type_Of_Object): Copy the object definition when building the subtype declaration in the case of a spec expression.
2023-09-27ada: Rework fix for internal error on quantified expression with predicated typeEric Botcazou3-35/+21
It turns out that skipping compiler-generated block scopes is problematic when computing the public status of a subprogram, because this subprogram may end up being nested in the elaboration procedure of a package spec or body, in which case it may not be public. This replaces the original fix with a pair of Push_Scope/Pop_Scope in the Build_Predicate_Function procedure, as done elsewhere in similar cases. gcc/ada/ * sem_ch13.adb (Build_Predicate_Functions): If the current scope is not that of the type, push this scope and pop it at the end. * sem_util.ads (Current_Scope_No_Loops_No_Blocks): Delete. * sem_util.adb (Current_Scope_No_Loops_No_Blocks): Likewise. (Set_Public_Status): Call again Current_Scope.
2023-09-27ada: Fix internal error on quantified expression with predicated typeEric Botcazou3-14/+40
The problem is that the special function created by the compiler to check the predicate does not inherit the public status of the type, because it is generated as part of the freezing of the quantified expression, which occurs from within a couple of intermediate internal scopes. gcc/ada/ * sem_ch13.adb (Build_Predicate_Function_Declaration): Adjust the commentary to the current implementation. * sem_util.ads (Current_Scope_No_Loops): Move around. (Current_Scope_No_Loops_No_Blocks): New declaration. (Add_Block_Identifier): Fix formatting. * sem_util.adb (Add_Block_Identifier): Likewise. (Current_Scope_No_Loops_No_Blocks): New function. (Set_Public_Status): Call Current_Scope_No_Loops_No_Blocks instead of Current_Scope to get the current scope.
2023-09-27ada: Fix bogus error on predicated limited record declared in protected typeEric Botcazou2-22/+10
This happens when the limited record is initialized with a function call because of a couple of issues: incorrect tree sharing when building the predicate check and too late freezing for a compiler-generated subtype. It turns out that building the predicate check manually is redundant here, since predicate checks are automatically generated during the expansion of assignment statements, and the late freezing can be easily fixed. gcc/ada/ * exp_ch3.adb (Build_Record_Init_Proc.Build_Assignment): Do not manually generate a predicate check. Call Unqualify before doing pattern matching on the expression. * sem_ch3.adb (Analyze_Object_Declaration): Also freeze the actual subtype when it is built in the definite case.
2023-09-27ada: Small code cleanupEric Botcazou1-13/+8
This just merges two conditional blocks depending on the same condition. gcc/ada/ * frontend.adb (Frontend): Merge two conditional blocks and adjust.
2023-09-27ada: Use idiomatic construct in Expand_N_Package_BodyEric Botcazou1-10/+1
gcc/ada/ * exp_ch7.adb (Expand_N_Package_Body): Call Defining_Entity to get the entity of the body.
2023-09-27ada: Fix spurious freezing error on nonabstract null extensionEric Botcazou1-3/+5
This prevents the wrapper function created for each nonoverridden inherited function with a controlling result of nonabstract null extensions of tagged types from causing premature freezing of types referenced in its profile. gcc/ada/ * exp_ch3.adb (Make_Controlling_Function_Wrappers): Create the body as the expanded body of an expression function.
2023-09-27ada: Fix crash on Ada.Containers with No_Dispatching_Calls restrictionEric Botcazou1-1/+5
This makes it so that the compiler does not crash and flags the underlying violation of the restriction instead. gcc/ada/ * exp_ch3.adb (Freeze_Type): Do not associate the Finalize_Address routine for a class-wide type if restriction No_Dispatching_Calls is in effect.
2023-09-27ada: Fix error and crash on imported function with precondition and 'BaseEric Botcazou1-3/+4
This fixes a spurious error on an imported function with a precondition and a parameter declared with a 'Base formal type, and even a crash in the case where this function is declared in a generic package. gcc/ada/ * freeze.adb (Wrap_Imported_Subprogram): Use Copy_Subprogram_Spec to copy the spec from the subprogram to the generated subprogram body. (Freeze_Entity): Do not wrap imported subprograms inside generics.
2023-09-27ada: Fix double finalization in conditional exit statementEric Botcazou1-2/+5
The temporary is first finalized through its enclosing block. gcc/ada/ * exp_ch4.adb (Expand_N_Expression_With_Actions.Process_Action): Do not look into nested blocks.
2023-09-27ada: Fix handling of constrained array declarations in declare-expressionEric Botcazou1-2/+2
They need to go through Constrain_Array or else they do not really work. gcc/ada/ * sem_ch3.adb (Find_Type_Of_Object): In a spec expression, also set the Scope of the type, and call Constrain_Array for array subtypes.
2023-09-27ada: Use accumulator type in expansion of 'Reduce attributeEric Botcazou1-10/+62
The current expansion of the 'Reduce attribute uses the resolution type of the expression for the accumulator. Now this type can be unresolved or set to a universal type, for example if it is itself the prefix of the 'Image attribute, and this may yield a spurious type mismatch error in that case. This changes the expansion to use the accumulator type instead as defined by the RM 4.5.10 clause, albeit only in the prefixed case for now. gcc/ada/ * exp_attr.adb (Expand_N_Attribute_Reference) <Attribute_Reduce>: Use the canonical accumulator type as the type of the accumulator in the prefixed case.
2023-09-27ada: Fix crash on iterated component in expression functionEric Botcazou1-6/+8
The problem is that the freeze node generated for the type of a static subexpression present in the expression function is incorrectly placed inside instead of outside the function. gcc/ada/ * freeze.adb (Freeze_Expression): When the freezing is to be done outside the current scope, skip any scope that is an internal loop.
2023-09-27ada: Fix internal error on 'Image applied to array componentEric Botcazou1-2/+21
This happens because the array component depends on a discriminant. gcc/ada/ * exp_imgv.adb (Rewrite_Object_Image): If the prefix is a component that depends on a discriminant, create an actual subtype for it.
2023-09-27ada: Fix internal error on chain of predicated record typesEric Botcazou1-6/+21
The preanalysis of a predicate set on one of the record types was causing premature freezing of another record type. gcc/ada/ * sem_ch13.adb: Add with and use clauses for Expander. (Resolve_Aspect_Expressions) <Aspect_Predicate>: Emulate a bona-fide preanalysis setup before calling Resolve_Aspect_Expression.
2023-09-27ada: Implement inheritance of user-defined literal aspects for untagged typesEric Botcazou3-8/+38
In Ada 2022, user-defined literal aspects are nonoverridable but the named subprograms present in them can be overridden, including for untagged types. gcc/ada/ * sem_res.adb (Has_Applicable_User_Defined_Literal): Apply the same processing for derived untagged types as for tagged types. * sem_util.ads (Corresponding_Primitive_Op): Adjust description. * sem_util.adb (Corresponding_Primitive_Op): Handle untagged types.
2023-09-27ada: Fix internal error on instance in package body with -gnatnEric Botcazou1-0/+4
This plugs a small loophole in the procedure responsible for attempting to hide entities that have been previously made public by the semantic analyzer in package bodies. gcc/ada/ * sem_ch7.adb (Hide_Public_Entities): Use the same condition for subprogram bodies without specification as for those with one.