aboutsummaryrefslogtreecommitdiff
AgeCommit message (Collapse)AuthorFilesLines
2023-09-27ada: Fix missing call to Finalize_Protection for simple protected objectsEric Botcazou2-11/+40
There is a glitch in Exp_Ch7.Build_Finalizer causing the finalizer to do nothing for simple protected objects. The change also removes redundant calls to the Is_Simple_Protected_Type predicate and fixes a minor inconsistency between Requires_Cleanup_Actions and Build_Finalizer for this case. gcc/ada/ * exp_ch7.adb (Build_Finalizer.Process_Declarations): Remove call to Is_Simple_Protected_Type as redundant. (Build_Finalizer.Process_Object_Declaration): Do not retrieve the corresponding record type for simple protected objects. Make the flow of control more explicit in their specific processing. * exp_util.adb (Requires_Cleanup_Actions): Return false for simple protected objects present in library-level package bodies for the sake of consistency with Build_Finalizer and remove call to Is_Simple_Protected_Type as redundant.
2023-09-27ada: Fix missing finalization of extended return object on abnormal completionEric Botcazou4-12/+12
This happens in the case of a nonlimited return type and is a fallout of the optimization recently implemented for them. gcc/ada/ * einfo.ads (Status_Flag_Or_Transient_Decl): Remove ??? comment. * exp_ch6.adb (Expand_N_Extended_Return_Statement): Extend the handling of finalizable return objects to the non-BIP case. * exp_ch7.adb (Build_Finalizer.Process_Declarations): Adjust the comment accordingly. * exp_util.adb (Requires_Cleanup_Actions): Likewise.
2023-09-27ada: Fix minor glitch in finish_record_typeEric Botcazou1-1/+1
The size needs to be rounded up to the storage unit in all cases. gcc/ada/ * gcc-interface/utils.cc (finish_record_type): Round the size in the padding case as well.
2023-09-27ada: Fix wrong optimization of extended return for discriminated record typeEric Botcazou1-0/+1
This happens when the discriminants of the record type have default values. gcc/ada/ChangeLog: * inline.adb (Expand_Inlined_Call): In the case of a function call that returns an unconstrained type and initializes an object, set the No_Initialization flag on the new declaration of the object.
2023-09-27ada: Fix internal error on aggregate nested in container aggregateEric Botcazou1-7/+9
This handles the case where a component association is present. gcc/ada/ * exp_aggr.adb (Convert_To_Assignments): In the case of a component association, call Is_Container_Aggregate on the parent's parent. (Expand_Array_Aggregate): Likewise.
2023-09-27ada: Fix internal error on expression function with Refined_Post aspectEric Botcazou1-0/+3
This occurs when the expression function calls a protected function and the -gnata switch is specified, because the compiler wrongly freezes the called function when analyzing the expression function, a fallout of the wrapping scheme used for the Post and Refined_Post aspects. gcc/ada/ * sem_res.adb (Resolve_Call): When the target is an entity, do not freeze it if the current scope is the inner wrapper function built for an expression function with a Post or Refined_Post aspect.
2023-09-27ada: Fix late finalization for function call in delta aggregateEric Botcazou1-2/+6
The problem occurs at library level because the temporary created for the function call lives in the elaboration routine but is finalized only when the package itself is. It turns out that there is no need for this temporary, since the expansion of delta aggregates already creates a (properly finalized) temporary. gcc/ada/ * exp_ch6.adb (Expand_Ctrl_Function_Call): Also do nothing for the expression of a delta aggregate.
2023-09-27ada: Fix premature finalization in loop over limited iterable containerEric Botcazou1-40/+48
This happens when the iterable container is obtained as the result of a call to a function that is a subprogram parameter of a generic construct. gcc/ada/ * exp_util.adb (Initialized_By_Aliased_BIP_Func_Call): Make the name matching more robust.
2023-09-27ada: Elide the copy in extended returns for nonlimited by-reference typesEric Botcazou1-1/+1
gcc/ada/ * gcc-interface/trans.cc (gnat_to_gnu): Really test Storage_Pool on the simple return statement.
2023-09-27ada: Fix assertion failure on very peculiar enumeration typeEric Botcazou1-0/+14
The compiler currently does not support the combination of a representation clause on an enumeration type with a size clause whose value is greater than the size of the largest machine scalar supported by the target. Given that such a type would have little practical value, this change causes the compiler to give a proper error message instead of aborting. gcc/ada/ * freeze.adb (Freeze_Enumeration_Type): Give an error on a type with both representation clause and too large size.
2023-09-27ada: Fix spurious error on 'Input of private type with Type_Invariant aspectEric Botcazou1-4/+19
The problem is that it is necessary to break the privacy during the expansion of the Input attribute, which may introduce a view mismatch with the parameter of the routine checking the invariant of the type. gcc/ada/ * exp_util.adb (Make_Invariant_Call): Convert the expression to the type of the formal parameter if need be.
2023-09-27ada: Elide the copy in extended returns for nonlimited by-reference typesEric Botcazou1-3/+4
gcc/ada/ * gcc-interface/trans.cc (gnat_to_gnu): Restrict previous change to the case where the simple return statement has got no storage pool.
2023-09-27ada: Fix memory explosion on aggregate of nested packed array typeEric Botcazou1-1/+3
It occurs at compile time on an aggregate of a 2-dimensional packed array type whose component type is itself a packed array, because the compiler is trying to pack the intermediate aggregate and ends up rewriting a bunch of subcomponents. This optimization was originally devised for the case of a scalar component type so the change adds this restriction. gcc/ada/ * exp_aggr.adb (Is_Two_Dim_Packed_Array): Return true only if the component type of the array is scalar.
2023-09-27ada: Improve error message for ambiguous subprogram callEric Botcazou3-8/+21
This restores the full listing of the types for the interpretations. gcc/ada/ * sem_util.ads (Wrong_Type): Add Multiple parameter defaulting to False and document it. * sem_util.adb (Wrong_Type): Do not return early if an error has already been posted on Expr and Multiple is True. * sem_ch4.adb (Analyze_One_Call): Pass All_Errors_Mode as the actual parameter for Multiple to Wrong_Type.
2023-09-27ada: Fix assertion failure introduced by latest changeEric Botcazou1-4/+5
The new processing is not properly guarded. gcc/ada/ * sem_ch13.adb (Replace_Type_References_Generic.Visible_Component): In the case of private discriminated types, explicitly check that we have a private declaration before examining its discriminant part.
2023-09-27ada: Fix Valid_Scalars attribute applied to types from limited withEric Botcazou2-2/+9
The attribute is wrongly computed as always True because, unlike for e.g. private types, Validated_View does not look through the limited view. gcc/ada/ * sem_util.ads (Validated_View): Document enhanced behavior. * sem_util.adb (Validated_View): Return the nonlimited view, if any, of types coming from a limited with.
2023-09-27ada: Fix wrong resolution for hidden discriminant in predicateEric Botcazou1-7/+42
The problem occurs for hidden discriminants of private discriminated types. gcc/ada/ * sem_ch13.adb (Replace_Type_References_Generic.Visible_Component): In the case of private discriminated types, return a discriminant only if it is listed in the discriminant part of the declaration.
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.