ada: Fix wrong size value output with -gnatR -gnatc This happens when a parameter is involved in the computation. gcc/ada/ * gcc-interface/decl.cc (annotate_value): Apply the same processing for parameters as for variables.
ada: Errors on instance of Multiway_Trees with discriminated type The compiler may report various type conflicts on an instantiation of the generic package Ada.Containers.Multiway_Trees with an actual for Element_Type that is a nonprivate actual type with discriminants that has a discriminant-dependent component of a private type (such as a Bounded_Vector type). The type errors occur on an aggregate of the implementation type Tree_Node_Type within the body of Multiway_Trees, where the aggregate has a box-defaulted association for the Element component. (Such type errors could of course arise in other cases of generic instantiations that follow a similar type model.) In the case where the discriminant-dependent component type has a default-initialization procedure (init proc), the compiler was handling box associations for such components by expanding the topmost box association into subaggregates that themselves have box associations, and didn't properly account for discriminant-dependent subcomponents of private types. This could be fixed internally in Propagate_Discriminants, but it seems that the entire machinery for dealing with such subcomponent associations is unnecessary, and the topmost component association can be handled directly as a default-initialized box association. gcc/ada/ * sem_aggr.adb (Add_Discriminant_Values): Remove this procedure. (Propagate_Discriminants): Remove this procedure. (Resolve_Record_Aggregate): Remove code (the Capture_Discriminants block statement) related to propagating discriminants and generating initializations for subcomponents of a discriminant-dependent box-defaulted subcomponent of a nonprivate record type with discriminants, and handle all top-level components that have a non-null base init proc directly, by calling Add_Association with "Is_Box_Present => True". Also, combine that elsif clause with the immediately preceding elsif clause, since they now both contain the same statement (calls to Add_Association with the same actuals).
ada: Error compiling reduction expression with overloaded reducer subprogram In some cases involving a reduction expression with an overloaded reducer subprogram, the accumulator type is not determined correctly. This can lead to spurious compile-time errors. gcc/ada/ * exp_attr.adb (Expand_N_Attribute_Reference): In the case of a Reduce attribute reference, fix bugs in initializing Accum_Typ. The previous version was incorrect in the case where E1 refers to the first of multiple possible overload resolution candidates and that candidate does not turn out to be the right one. The previous version also had code to compute Accum_Typ via a different method if the initial computation turned out to yield a universal numeric type. Delete that initial computation and use the second method in all cases.
ada: Further cleanup in finalization machinery When transient scopes are being materialized, they can give rise to a block created around the construct being wrapped or not, depending on the kind of construct. In both cases finalization actions for the transient objects of the scope are generated the same way, with normal finalization done manually immediately after the construct and exceptional finalization deferred to the enclosing scope by means of a hooking mechanism. Now when the block is generated, it becomes this enclosing scope, so the normal finalization that comes with it would also be done immediately after the construct, even without normal finalization generated manually. Therefore this change gets rid of the manual finalization as well as of the hooking in the cases where the block is generated, leading to a significant streamlining of the expanded code in these cases. This requires fixing a small inaccuracy of the Within_Case_Or_If_Expression predicate, which must only be concerned with the dependent expressions, since those are the only ones to be treated specially by the finalization machinery. It also contains a small cleanup for the description of the transient scope management present at the beginning of the exp_ch7.adb file. gcc/ada/ * exp_ch7.ads (Expand_Cleanup_Actions): Move declaration to the Finalization Management section. * exp_ch7.adb (Transient Scope Management): Move description down to after that of the general finalization and make a few changes. (Insert_Actions_In_Scope_Around): Call Process_Transients_In_Scope only if cleanups are being handled. (Process_Transients_In_Scope): Remove redundant test on Clean. * exp_util.ads (Within_Case_Or_If_Expression): Adjust description. * exp_util.adb (Within_Case_Or_If_Expression): Only return true if within the dependent expressions of the conditional expressions.
ada: Fix premature finalization for nested return within extended one The return object is incorrectly finalized when the nested return is taken, because the special flag attached to the return object is not updated. gcc/ada/ * exp_ch6.adb (Build_Flag_For_Function): New function made up of the code building the special flag for return object present... (Expand_N_Extended_Return_Statement): ...in there. Replace the code with a call to Build_Flag_For_Function. Add assertion for the flag. (Expand_Non_Function_Return): For a nested return, if the return object needs finalization actions, update the special flag.
ada: Type error on container aggregate with loop_parameter_specification The compiler incorrectly reported a type error on a container aggregate for a Vector type with a loop_parameter_specification specifying a nonstatic upper bound, complaining that it expected the Vector index type, but instead found type Count_Type. The expansion of the aggregate was incorrectly passing a size temporary of type Count_Type to the function associated with the New_Indexed part of the container type's Aggregate aspect (New_Vector in the case of Vectors), which has two formals of the container index type. The fix is to convert the size temporary to the expected index type. gcc/ada/ * exp_aggr.adb (Expand_Container_Aggregate): Apply a conversion to the size temp object passed as the second actual parameter on the call to the New_Indexed_Subp function, to convert it to the index type of the container type (taken from the first formal parameter of the function).
ada: Add new predicate Is_Address_Compatible_Type When emitting code for architectures with tagged pointers, it is useful to be able to recognize values representing addresses because they require special handling. This commits adds the predicate Is_Address_Compatible_Type, which differs from the node attribute Is_Descendant_Of_Address by also taking Standard_Address into account. gcc/ada/ * einfo-utils.ads, einfo-utils.adb (Is_Address_Compatible_Type): New function.
ada: Fix internal error on declare expression in expression function When the expression function is not a completion, its (return) expression does not cause freezing so analyzing the declare expression in this context must not freeze the type of the object. The change also contains another fix, which makes it so that the compiler does not evaluate a nonstatic representation attribute of a scalar subtype in the same context if the subtype is not already frozen. gcc/ada/ * sem_attr.adb (Eval_Attribute): Do not proceed in a spec expression for nonstatic representation attributes of a scalar subtype when the subtype is not frozen. * sem_ch3.adb (Analyze_Object_Declaration): Do not freeze the type of the object in a spec expression.
ada: Fix predicate failure that occurred in a test case The CodePeer test case illustrating a problem where a "high" precondition failure was expected, died in the GNAT FE on input_reading.adb. The problem was in Check_SCIL, where it didn't properly handle a discriminant_specification. gcc/ada/ * sem_scil.adb: Handle discriminant specification.
ada: Remove dependency on System.Val_Bool in System.Img_Bool In order to facilitate the certification of System.Img_Bool, remove its dependency on unit System.Val_Bool. Modify the definition of ghost function Is_Boolean_Image_Ghost to take the expected boolean value and move it to System.Val_Spec. gcc/ada/ * libgnat/s-imgboo.adb: Remove with_clause now in spec file. * libgnat/s-imgboo.ads: Remove dependency on System.Val_Bool. (Image_Boolean): Replace call to Value_Boolean by passing value V to updated ghost function Is_Boolean_Image_Ghost. * libgnat/s-valboo.ads (Is_Boolean_Image_Ghost): Move to other unit. (Value_Boolean.): Update precondition. * libgnat/s-valspe.ads (Is_Boolean_Image_Ghost): Move here. Add new parameter for expected boolean value.
ada: Compiler crash on container aggregate with loop_parameter_specifications The compiler crashes on a container aggregate with more than one iterated_element_association given by a loop_parameter_specification. In such a case, the tree contains N_Iterated_Component_Association nodes rather than N_Iterated_Element_Association nodes, and the code for handling those needs to obtain the bounds from the Discrete_Choices field of each N_Iterated_Component_Association rather than assuming that the association has a normal list of choices. gcc/ada/ * sem_aggr.adb (Resolve_Container_Aggregate): In the case where Comp is an N_Iterated_Component_Association, pick up Discrete_Choices rather than Choices.
ada: Another couple of cleanups in the finalization machinery For package specs and bodies that need finalizers, Build_Finalizer is invoked from the Standard scope so it needs to adjust the scope stack before creating new objects; this changes it to do so only once. For other kinds of scopes, it is invoked from Expand_Cleanup_Actions, which assumes that the correct scope is already on the stack; that's why Cleanup_Scopes adjusts the scope stack explicitly, but it should use Pop_Scope instead of End_Scope to do it. gcc/ada/ * exp_ch7.adb (Build_Finalizer): For package specs and bodies, push and pop the specs onto the scope stack only once. * inline.adb (Cleanup_Scopes): Call Pop_Scope instead of End_Scope.
ada: Deep delta aggregates in postconditions Fix a bug in handling array-valued deep delta aggregates occurring in postconditions. The bug could result in a spurious compilation failure. gcc/ada/ * sem_aggr.adb (Resolve_Delta_Array_Aggregate): In the case of a deep delta choice, the expected type for the expression will typically not be the component type of the array type, so a call to Analyze_And_Resolve that assumes otherwise would be an error. It turns out that such a call, while wrong, is usually harmless because the expression has already been marked as analyzed. This doesn't work if the aggregate occurs in a postcondition and, in any case, we don't want to rely on this. So do not perform the call in the deep case.