[Ada] Fix crash on type extensions with discriminants

2021-07-09 Thread Pierre-Marie de Rodat
In Ada 2022 mode, the compiler crashes when generating the Put_Image function for a tagged type if the parent subtype is constrained. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * exp_put_image.adb (Make_Component_Attributes): Use Implementation_Base_Type to get th

[Ada] par-ch6: do not mark subprogram as missing "is" if imported

2021-07-09 Thread Pierre-Marie de Rodat
Before this commit, the following piece of code: procedure Main is function F (X : access Integer) return Boolean with Import; begin null; end; Resulted in the following error messages: main.adb:2:59: error: ";" should be "is" main.adb:5:01: error: "end F;" expected main.adb:5:01: error: miss

[Ada] Fix style in expansion of attribute Put_Image

2021-07-09 Thread Pierre-Marie de Rodat
Style cleanup only. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * exp_put_image.adb (Make_Put_Image_Name): Fix style. (Image_Should_Call_Put_Image): Likewise. (Build_Image_Call): Likewise.diff --git a/gcc/ada/exp_put_image.adb b/gcc/ada/exp_put_image.adb --

[Ada] Duplicate Size/Value_Size clause

2021-07-12 Thread Pierre-Marie de Rodat
Give a warning if both Size and Value_Size attributes are specified for the same type. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * sem_ch13.adb (Duplicate_Clause): Add a helper routine Check_One_Attr, with a parameter for the attribute_designator we are l

[Ada] Add DWARF 5 support to System.Dwarf_Line

2021-07-12 Thread Pierre-Marie de Rodat
The encoding of the debugging line information has substantially changed in DWARF 5, so this adds the support for it alongside the existing code. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * libgnat/s-dwalin.ads: Adjust a few comments left and right. (Line_Info_Re

[Ada] Clean up Uint fields

2021-07-12 Thread Pierre-Marie de Rodat
We add new field types Valid_Uint, Unat, Upos, Nonzero_Uint, which have predicates that assert the value is a proper Uint value (i.e. not No_Uint), and that the value is appropriate. It is not clear that Nonzero_Uint is needed, but it is useful in testing; we can always remove it later. We use the

[Ada] Implement support for unconstrained array types with FLB

2021-07-12 Thread Pierre-Marie de Rodat
The fixed lower bound also makes it possible to simplify the formula of the upper bound used for unconstrained array types. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * gcc-interface/decl.c (gnat_to_gnu_entity) : Use a fixed lower bound if the index subtype is mar

[Ada] Extend compile-time evaluation in case statements to all objects

2021-04-28 Thread Pierre-Marie de Rodat
A comment in Analyze_Case_Statement describes an "interesting optimization" that was applied to all assignable objects. This patch extends it to all objects, in particular, to formal parameters of mode IN. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * sem_ch5.adb (Analyze_

[Ada] Incorrect error with Default_Value on private/modular type

2021-04-28 Thread Pierre-Marie de Rodat
This patch fixes a bug where if a private type has a full type that is a modular type with a Default_Value specified, then creating objects of that type causes the compiler to incorrectly say, "illegal operand for numeric conversion". Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/

[Ada] Bad handling of 'Valid_Scalars and arrays

2021-04-28 Thread Pierre-Marie de Rodat
When using 'Valid_Scalars on unconstrained arrays, the expanded code includes unchecked conversion to the unconstrained base type, which may lead to incorrect code being generated. Fixed by replacing Validated_View by Get_Fullest_View except for records where it is still needed. We also take this

[Ada] Update reference with description of type resolution

2021-04-28 Thread Pierre-Marie de Rodat
A reference in the comment about the type resolution described in Sem_Ch4 refers to description with a header "Handling of Overload Resolution", but this has been moved to Sem_Type. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * sem_res.ads: Update reference in comment.

[Ada] Remove unused subprograms

2021-04-28 Thread Pierre-Marie de Rodat
Remove dead code found by GNATcoverage: * Protected objects do not exist in Ada 83. * The whole last part of Scan_ALI is no longer used. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * sem_ch3.adb (Analyze_Object_Declaration): Remove dead code. * ali.ads, ali.adb (S

[Ada] Hashed container Cursor type predefined equality non-conformance

2021-04-28 Thread Pierre-Marie de Rodat
The RM states (A.18-4-18/2, A.18.7-17/2, et al) that "the predefined "=" operator for type Cursor returns True if both cursors are No_Element, or designate the same element in the same container." In some cases, GNAT's implementation violates this requirement. This was due to the component "Positi

[Ada] Improve error message for ghost in predicate

2021-04-28 Thread Pierre-Marie de Rodat
It may be surprising to users that a ghost entity is not allowed to appear in a predicate, which is a kind of assertion. Explain this in a continuation message, as well as the possible fixes. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * ghost.adb (Check_Ghost_Context): Ad

[Ada] Crash on inherited component in type extension in generic unit.

2021-04-28 Thread Pierre-Marie de Rodat
Compiler aborts on an instance body that has a reference to a selected component of a local type extension, when the component is inherited from an ancestor type declared outside of the generic being instantiated. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * exp_ch3.adb (

[Ada] Incorrect discriminant check on call to access to subprogram

2021-04-28 Thread Pierre-Marie de Rodat
When calling an access to a subprogram taking an unconstrained discriminated record as parameter, we fail to pass the extra constrained actual parameter, which would lead to spurious or missed discriminant checks. At the same time we noticed that GNAT sometimes generates trees of the form: (Fie

[Ada] Crash with declare expression used in a postcondition

2021-04-28 Thread Pierre-Marie de Rodat
This is preliminary work to properly handle a declare expression used in a postcondition. This first part is adding guards against missing types. The second part will be about setting the proper type when currently missing. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * sem

[Ada] Remove double initialization of interpretation tables

2021-04-28 Thread Pierre-Marie de Rodat
Global variable Sem_Type.Headers, which is used in type resolution, was initialized twice: by elaboration and by Init_Interp_Tables (called by Gnat1drv). Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * fmap.ads (Reset_Tables): Remove outdated references to GNSA/ASIS.

[Ada] Assert failure on complex code with private type and discriminant

2021-04-28 Thread Pierre-Marie de Rodat
Recent improvements in the handling of discriminants and discriminant checks made an assert failure appear on complex code. It appears that the assertions in einfo.adb (Discriminant_Constraint) is too strict. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * einfo.adb (Discri

[Ada] More precise error about aspects conflicting with Static

2021-04-28 Thread Pierre-Marie de Rodat
When a Pre/Post aspect is conflicting with Static aspect, the error message now says 'aspect "Pre"' or 'aspect "Post"' and not just "this aspect". Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * sem_ch13.adb (Analyze_Aspect_Static): Use aspect name in the error messa

[Ada] Use spans instead of locations for compiler diagnostics

2021-04-28 Thread Pierre-Marie de Rodat
Change the internal data structure that stores the compiler diagnostics to store spans instead of locations, where a span is a triplet of a main location, and a first-last pair of locations. Also change the main procedures for reporting an error in Errout to use spans instead of locations whenever

[Ada] AI12-0397: Default_Initial_Condition expressions for derived types

2021-04-28 Thread Pierre-Marie de Rodat
AI12-0397 specifies new rules for the resolution of expressions for the Default_Intial_Condition aspect, based on defining that a reference to the current instance of a type with DIC is a notional (nonabstract) formal derived type (making DIC similar to how Postcondition and Type_Invariant are defi

[Ada] Refactor repeated checks for the expression of aspect Static

2021-04-28 Thread Pierre-Marie de Rodat
Check for the expression of the aspect Static were done inside branches corresponding to inside-a-generic and outside-a-generic. Now this check occurs only once. Code cleanup; behaviour is unaffected. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * sem_ch13.adb (Analyze_Aspe

[Ada] Eliminate early roundoff error for Long_Long_Float on x86

2021-04-28 Thread Pierre-Marie de Rodat
This overcomes the lack of fused multiply-add instruction on the x87 FPU by doing an iterated addition with exact error handling for the last digit taken into account for the mantissa. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * libgnat/s-valrea.adb (Fast2Sum): New funct

[Ada] Consistent diagnostic on missing -gnat2020 switch for aspects

2021-04-28 Thread Pierre-Marie de Rodat
Reuse Error_Msg_Ada_2020_Feature for messages that reference the currently processed aspect using the '%' insertion character. Cleanup only; behaviour is not affected. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * sem_ch13.adb (Analyze_Aspect_Static): Reuse Error_M

[Ada] Remove redundant assignment in Formal_Is_Used_Once

2021-04-28 Thread Pierre-Marie de Rodat
The counter variable in routine Formal_Is_Used_Once is initialized with 0, then is possibly incremented to 1, and when incremented again, the traversal is abandoned. This second increment can only make the counter equal 2; there is no need to explicitly re-assign it. Code cleanup only; semantics i

[Ada] Install_Restricted_Handlers: define Prio parameter as Interrupt_Priority

2021-04-28 Thread Pierre-Marie de Rodat
System.Interrupt.Install_Restricted_Handlers takes a parameter Prio. It was defined as Any_Priority when it should be the more narrower Interrupt_Priority subtype as handlers can only have priorities in the Interrupt_Priority range. Using the more narrower subtype assists in unit testing. Tested o

[Ada] Simplify data structures for overloaded interpretations

2021-04-28 Thread Pierre-Marie de Rodat
The data structure for overloaded interpretations included a hash table with a subtle implementation. It is now replaced with a generic hash provided by the GNAT.HTable. This is only a code cleanup; behaviour of the compiler is not affected. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/

[Ada] Fix computation of Prec/Succ of zero without denormals

2021-04-28 Thread Pierre-Marie de Rodat
The result must be the Small instead of the Tiny in this case. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * libgnat/s-fatgen.adb: Add use clause for Interfaces.Unsigned_16 and Interfaces.Unsigned_32. (Small16): New constant. (Small32): Likewise.

[Ada] Fix recent optimization in evaluation of selected component for GNATprove

2021-04-28 Thread Pierre-Marie de Rodat
As GNATprove uses the AST after semantic analysis without expansion, the recent optimization in the evaluation of selected components for aggregates was leading to incorrect AST where possible run-time errors in the evaluation of the (aggregate) prefix were not taken into account. Fixed by only ena

[Ada] Adjust List_Length description

2021-04-28 Thread Pierre-Marie de Rodat
The comment for List_Length says "It is an error to call this function with No_List (No_List is not considered to be the same as an empty list).". It legitimately happens in practice, so adjust the comment to allow this. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * nlist

[Ada] Spurious error on 'Image

2021-04-29 Thread Pierre-Marie de Rodat
As part of recent improvements related to discriminant checks, a regression was introduced in complex cases of generics and use of 'Image on an expression partially rewritten as a [raise Constraint_Error] node. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * sem_attr.adb (Ch

[Ada] Warning for 'Class applied to untagged incomplete type

2021-04-29 Thread Pierre-Marie de Rodat
Applying Class to an untagged incomplete type is legal, but classified as obsolescent in Annex J (for Ada 2005 and later), so should be flagged with a warning when the -gnatwj switch applies, as well as being reported as a violation of No_Obsolescent_Features when that restriction is enabled. Both

[Ada] AI12-0407: Fixups on Big_Integers and Big_Reals

2021-04-29 Thread Pierre-Marie de Rodat
This AI updates among other things some declarations in big number packages. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * libgnat/a-nbnbin.ads (From_Universal_Image): New. (Big_Integer): Update definition. * libgnat/a-nbnbre.ads, libgnat/a-nbnbre.adb

[Ada] Fixes in the use of spans for error locations

2021-04-29 Thread Pierre-Marie de Rodat
Various fixes regarding the use of spans in error messages when using debug flag -gnatdF. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * errout.adb (Error_Msg_NEL): Extract span from node. (First_And_Last_Nodes): Use spans for subtype indications and attribu

[Ada] Reimplement Pred and Succ atttributes for floating-point types

2021-04-29 Thread Pierre-Marie de Rodat
The main reason is that the current implementation does not work if the type does not support denormalized numbers, because it is piggybacked on the Scaling attribute and Scaling will flush to zero in this case. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * libgnat/s-fatge

[Ada] Extend Find_Related_Context to deal with child instances

2021-04-29 Thread Pierre-Marie de Rodat
Aspect Part_Of is first translated into a corresponding pragma; then, we use Find_Related_Context to recover the node where the aspect was originally attached. However, this routine was only working for pragmas Part_Of coming from aspects applied to generic packages instantiated within other progr

[Ada] Crash on predicated constrained out_parameter

2021-04-29 Thread Pierre-Marie de Rodat
Compiler aborts on an aggregate for a discriminated out_parameter when the parent type has dynamic_predicates. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * sem_util.adb (Build_Constrained_Itype): Inhibit the generation of predicate functions for this Itype, which

[Ada] Fix static computation of 'Succ for floating point without denormals

2021-04-29 Thread Pierre-Marie de Rodat
The implementation computes an incorrect increment for normalized numbers with the smallest exponent when the floating-point type does not support denormalized numbers. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * eval_fat.adb (Succ): Add a special case for zero if the ty

[Ada] Fix handling of visibility when categorization from pragmas

2021-04-29 Thread Pierre-Marie de Rodat
Routine Set_Categorization_From_Pragmas processes pragmas listed after the compilation unit. It requires enclosing scopes to be visible, to support pragmas (and aspects that are translated to pragmas) like here: with Generic_Pkg; private package Parent.Child_Instance is new Generic_Pkg

[Ada] Makefile.rtl:ADA_EXCLUDE_SRCS update after some System.GCC unit renames

2021-04-29 Thread Pierre-Marie de Rodat
In a previous commit, some System.GCC units were renamed to be children of System.GCC.DI instead, so as to have System.GCC be free of symbols which are specific to 32bit platforms. This was needed in the context of a 64bit vx7r2cert platform (AArch64) where we needed to add equivalent routines spec

[Ada] SPARK needs DIC expressions within partial DIC procedures for abstract types

2021-04-29 Thread Pierre-Marie de Rodat
A recent change done as part of the implementation of AI12-0397 was to suppress generation of DIC check expressions within DIC procedures associated with abstract types (to avoid producing calls to abstract subprograms, which are legal to give in a DIC aspect, but would cause problems for gigi if t

[Ada] Couple of minor tweaks to Eval_Fat.Succ

2021-04-29 Thread Pierre-Marie de Rodat
This saves a few cycles by using Ureal_Half instead of Ureal_1. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * eval_fat.adb (Succ): Use Ureal_Half in a couple of places.diff --git a/gcc/ada/eval_fat.adb b/gcc/ada/eval_fat.adb --- a/gcc/ada/eval_fat.adb +++ b/gcc/ada/eval_fa

[Ada] Ada 2020 AI12-0401: Renaming of qualified expression of variable

2021-04-29 Thread Pierre-Marie de Rodat
A new version of this AI was published recently, refining the legality rules around renaming of a qualified expression. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * sem_ch8.adb (Analyze_Object_Renaming): Update check for AI12-0401.diff --git a/gcc/ada/sem_ch8.adb

[Ada] Bad handling of array sliding in aggregate

2021-04-29 Thread Pierre-Marie de Rodat
In the case of an aggregate containing controlled array components, if sliding of the indexes is involved, the components are prematurely finalized without a corresponding initialization. Also fix a latent bug in Exp_Aggr.Collect_Initialization_Statements which was not always inserting Initializat

[Ada] Fix internal consistency error with Duration and 32-bit target file

2021-04-29 Thread Pierre-Marie de Rodat
The Duration type of package Standard can be either a 32-bit or a 64-bit fixed-point type depending on a flag in the system.ads file, but it needs to be 32-bit when a target configuration file sets a 32-bit size for all the predefined integer types. Tested on x86_64-pc-linux-gnu, committed on trun

[Ada] Fix evaluation of expressions in inlined code

2021-04-29 Thread Pierre-Marie de Rodat
In GNATprove mode, inlining is used to make it easier to perform proof without forcing the user to annotate all local subprograms with contracts. But the compiled code will not be similarly inlined, thus the analysis should not assume that the compiler will have access to the same extended precisi

[Ada] Missing access-to-discriminated conversion check

2021-04-29 Thread Pierre-Marie de Rodat
The compiler was failing to generate a required constraint check in the case of a type conversion between access-to-discriminated types. This patch fixes this bug. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * checks.adb (Apply_Type_Conversion_Checks): Move out constraint

[Ada] Fix minor issue in Scan_Decimal_Digits

2021-04-29 Thread Pierre-Marie de Rodat
The Extra digit is not correctly set when the precision limit is reached by means of trailing zeros. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * libgnat/s-valuer.adb (Scan_Decimal_Digits): Set Extra to zero when the precision limit is reached by means of trailing

[Ada] Add colors to GNATprove messages output to a terminal

2021-04-29 Thread Pierre-Marie de Rodat
Add the possibility for a tool to enable colored output using SGR when outputting to a terminal. This is currently used only in GNATprove, but could be enabled for compiler messages in the future. Use the same colors (including bold) as gcc/g++ as much as possible. Tested on x86_64-pc-linux-gnu, c

[Ada] Error on T'Reduce of when T is not a container

2021-04-29 Thread Pierre-Marie de Rodat
This patch fixes a bug that caused the compiler to crash on T'Reduce, if T is something like Integer. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * sem_attr.adb (Analyze_Attribute): Change "$" to "&". Otherwise, Errout will trip over an uninitialized (invalid)

[Ada] Clean up Makefile.rtl

2021-04-29 Thread Pierre-Marie de Rodat
ADA_EXCLUDE_SRCS and ADA_INCLUDE_SRCS contain old references to non existing files. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * Makefile.rtl (ADA_EXCLUDE_SRCS): Remove unused files. (ADA_INCLUDE_SRCS): Remove libgnat/system.adsdiff --git a/gcc/ada/Makefile.rtl b/

[Ada] Change rounding mode of 'Machine for static floating point

2021-04-29 Thread Pierre-Marie de Rodat
This changes the rounding mode used for the static evaluation of the Machine attribute of floating-point types to the mode used for the static evaluation of real expressions, for the sake of consistency. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * sem_attr.adb (Eval_Attr

[Ada] Tree inconsistency between -O0 and -O1

2021-04-29 Thread Pierre-Marie de Rodat
The expansion performed in Expand_N_If_Statement only at -O1 and above can create inconsistencies in the tree that can cause trouble when compiling different files with different optimization levels. This is visible in particular in GNAT LLVM when generating C code on ACATS test cc50a01. Fixed by

[Ada] Fix interaction of 128-bit integer types and -gnato2 mode

2021-04-29 Thread Pierre-Marie de Rodat
The -gnato2 mode of overflow checking, aka Minimized overflow checking, cannot work for 128-bit integer types because it is implemented using 64-bit integer types. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * exp_ch4.adb (Expand_Compare_Minimize_Eliminate_Overflow): Remov

[Ada] Eliminate useless 128-bit overflow check for conversion

2021-04-29 Thread Pierre-Marie de Rodat
This gets rid of overflow checks done using a 128-bit integer type on 64-bit platforms and that can be done in a narrower type, by reusing the machinery already implemented to narrow the type of operations. This runs afoul of the processing for Max_Size_In_Storage_Elements in Expand_N_Attribute_Re

[Ada] Self reference access discriminant

2021-04-29 Thread Pierre-Marie de Rodat
GNAT does not accept a declaration of the form: type Rec (D : access Rec) is null record; To solve this, we factor out Check_Anonymous_Access_Components and reuse it from Process_Discriminants and adjust Freeze_Record_Type accordingly. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada

[Ada] Spurious accessibility error on call in return statement

2021-05-03 Thread Pierre-Marie de Rodat
This patch fixes an issue in the compiler whereby a spurious accessibility error regarding actuals for explicitly aliased formals in a function call within a return statement gets triggered during compilation when the return type of the function call in question has implicit dereference specified.

[Ada] Spurious warning on postcondition and result

2021-05-03 Thread Pierre-Marie de Rodat
When a function has "in out" parameters and a postcondition which does not reference 'Result, a potentially spurious warning is emitted. The necessary logic was actually already there in Sem_Util.Check_Result_And_Post_State but was using a local Has_In_Out_Parameter function instead of using simply

[Ada] Crash on aggregate in function call in object declaration

2021-05-03 Thread Pierre-Marie de Rodat
Compiler aborts on an aggregate with limited components, when the aggregate is a formal in a function call that is the right-hand side of an assignment, possibly coming from an object declaration. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * exp_aggr.adb (Expand_Array_Agg

[Ada] No_Implicit_Loops restriction and pragma Assert

2021-05-03 Thread Pierre-Marie de Rodat
When using e.g. pragma Assert (X'Initialized) combined with pragma Restrictions (No_Implicit_Loops), a violation is flagged when assertions are disabled, which is undesirable. Fixed by recognizing simple forms of dead paths used by pragma Assert when assertions are disabled. Tested on x86_64-pc-li

[Ada] Expansion in _postconditions confusing CodePeer

2021-05-03 Thread Pierre-Marie de Rodat
This patch fixes an issue in the compiler whereby extra flags and tests added to the internally generated _postconditions procedure confused and caused issues with CodePeer due to it treating the procedure as coming from source. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/

[Ada] Remove confusing warning on type export

2021-05-03 Thread Pierre-Marie de Rodat
"exporting" a type may seem useless but is actually useful to set its convention and sometimes its external name. So simply remove this warning. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * sem_prag.adb (Set_Exported): Do not warn on exporting a type.diff --git a/gcc/ada

[Ada] Spurious warning about premature use of selected component

2021-05-03 Thread Pierre-Marie de Rodat
Compiler emits a warning on a selected component that is an actual in a function call, when the enclosing object has no explicit initialization and no discriminants, but the component type itself has partial initialization. Such a warning should be suppressed. Tested on x86_64-pc-linux-gnu, commi

[Ada] Fix calls to Error_Msg_NE instead of Error_Msg_N

2021-05-03 Thread Pierre-Marie de Rodat
Replace calls to Error_Msg_NE whose Msg parameters have no insertion characters corresponding to the E parameter with equivalent but simpler calls to Error_Msg_N. Code cleanup; behaviour is unaffected. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * freeze.adb (Freeze_Profil

[Ada] Rename package instead of each routine

2021-05-03 Thread Pierre-Marie de Rodat
Package GNAT.Case_Util contained routines renamed from System.Case_Util. Few routines were missed. Renames entire package instead of renaming each routine separately. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * libgnat/g-casuti.adb: Replace with "pragma No_Body".

[Ada] Allow attributes Version and Body_Version prefixed by entries

2021-05-03 Thread Pierre-Marie de Rodat
Prefix of attributes Version and Body_Version denotes any program unit, including protected entries, which were wrongly rejected this context. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * sem_attr.adb (Check_Program_Unit): Replace tests for Task_Kind and Protected

[Ada] Fix attributes Version and Body_Version for concurrent units

2021-05-03 Thread Pierre-Marie de Rodat
Attributes Version and Body_Version can be prefixed by program units, which include protected units and task units. Those attributes were wrongly accepted when prefixed by protected subtype, task subtype and by any object of a concurrent type. Tested on x86_64-pc-linux-gnu, committed on trunk gcc

[Ada] Remove leading and trailing spaces in error messages

2021-05-03 Thread Pierre-Marie de Rodat
Remove trailing space in calls to Error_Msg_N routines. Cleanup only. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * exp_disp.adb, sem_aggr.adb, sem_cat.adb, sem_ch10.adb, sem_ch12.adb, sem_ch3.adb, sem_ch4.adb, sem_ch5.adb, sem_ch6.adb, sem_ch8.adb, sem_ch9

[Ada] Error message on invalid prefixed procedure call

2021-05-03 Thread Pierre-Marie de Rodat
When the prefix of a call denotes an overloaded primitive operation, all possible interpretations are analyzed to determine the intended one. If all of them fail, then if the All_Errors flag is on all interpretations are analyzed anew to indicate why each one is illegal. If All_Errors is not set th

[Ada] Remove unused initial values in expansion of distributed calls

2021-05-03 Thread Pierre-Marie de Rodat
Default initialization of a local Fname variable was never used. Code cleanup only; semantics is unaffected. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * exp_dist.adb (Build_From_Any_Call): Remove initial value for Fnam; fix style. (Build_To_Any_Call): Rem

[Ada] Ada.Strings.Unbounded.Aux.Set_String

2021-05-03 Thread Pierre-Marie de Rodat
The current version of Set_String is no longer used and not very useful and even unsafe with the introduction of a-stunau__shared.adb. Replace it with a more useful and safer version taking a callback to set the string. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * libgna

[Ada] Refine type of a counter object from Int to Nat

2021-05-03 Thread Pierre-Marie de Rodat
A local counter objects that are initialized with 0 and only incremented now have type Nat instead of Int. Code cleanup; semantics is unaffected. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * exp_ch7.adb (Build_Finalize_Statements): Refine type of a local counter v

[Ada] Replace calls to RTE with Is_RTE where possible

2021-05-03 Thread Pierre-Marie de Rodat
Replace expression of the form "X = RTE (...)" with "Is_RTE (X, ...)", which avoids loading of the unit where the ... entity is defined. In particular, a sequence of RTE_Available and RTE load the target unit where Is_RTE doesn't. This patch is primarily a code cleanup, but it also avoids unnecess

[Ada] Fix reference to SPARK RM rule in comment

2021-05-04 Thread Pierre-Marie de Rodat
Adding rule about a user-defined equality operation as SPARK RM 6.1.4(11) is changing the numeration of previous rules (11,12). Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * sem_prag.adb (Check_Mode_Restriction_In_Enclosing_Context): Fix reference to SPARK RM rule

[Ada] Guard against leading and trailing spaces reappearing in errors

2021-05-04 Thread Pierre-Marie de Rodat
The leading and trailing spaces in error message strings have been recently removed. This patch adds an assertion to prevent those spaces from appearing again. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * errout.adb (Error_Msg_Internal): Add assertion to prevent s

[Ada] Wrong membership test computation for interface type

2021-05-04 Thread Pierre-Marie de Rodat
When the left expression of a membership test is an object implementing an interface type, and the right operand of such membership test is a non-class wide interface type, the compiler generates code that, instead of comparing the actual tag of the left expression to the tag of the right operand,

[Ada] Preliminary cleanup in floating-point output implementation

2021-05-04 Thread Pierre-Marie de Rodat
This moves the low-level processing on characters to the package Img_Util, factors out common processing with fixed point, and overhauls the handling of negative zeros and rounding. This also removes the Is_Negative intrinsic function, which was only accessible from predefined units and is now unu

[Ada] Fix inconsistent handling of character set control switches

2021-05-04 Thread Pierre-Marie de Rodat
Switch -gnatic, where "c" denotes a character set, is described in the GNAT User's Guide sections 4.3.11 Character Set Control and 4.3.1 Alphabetical List of All Switches, but the latter section didn't mention '5' as an allowed value for "c". This is implemented in csets.adb, switch-c.adb (for the

[Ada] Check entries for formals of mode IN appearing as global outputs

2021-05-04 Thread Pierre-Marie de Rodat
Rule SPARK RM 6.1.4(13) only mentions "subprograms", but it is equally applicable to protected entries whose global inputs cannot appear as global outputs in nested subprograms. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * sem_prag.adb (Check_Mode_Restriction_In_Enclosing

[Ada] Reject constants of access-to-variable type as function globals

2021-05-04 Thread Pierre-Marie de Rodat
Constants of an access-to-variable type can only appear as global outputs in procedures, tasks and protected entries, not in functions. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * sem_prag.adb (Analyze_Global_Item): Take subprogram kind into account when acceptin

[Ada] Reject formals of mode IN appearing as global outputs

2021-05-04 Thread Pierre-Marie de Rodat
Fix implementation of SPARK RM 6.1.4(13), which says: "... if the global_specification of the outer subprogram has an entity denoted by a global_item with a mode_specification of Input or the entity is a formal parameter with a mode of in" but the rule was only enforced for outer subprogr

[Ada] Missing finalization on generic instantiation

2021-05-04 Thread Pierre-Marie de Rodat
If some objects are declared in the body of a generic package, these objects are not finalized when the package is instantiated at the library level. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * exp_ch7.adb (Build_Finalizer_Helper.New_Finalizer_Name): Unnest so th

[Ada] Use error marker for messages in GNATprove mode

2021-05-04 Thread Pierre-Marie de Rodat
Force the use of the "error:" marker for error messages in GNATprove. This helps distinguishing these messages from others like warnings, check messages and info messages, in particular when colored output is used. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * gnat1drv.adb

[Ada] Simplify use of a global name buffer for Global/Depends errors

2021-05-04 Thread Pierre-Marie de Rodat
Error messages about the Global/Depends contracts are constructed in the Global_Name_Buffer, but there is no need to store those messages as the Name_Id objects. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * sem_prag.adb (Role_Error, Usage_Error): Replace calls to

[Ada] Move match function for pragma Warnings to public spec

2021-05-04 Thread Pierre-Marie de Rodat
In order to use the same matching function in GNATprove for justifying messages through pragma Annotate as the matching function used for pragma Warnings, make that function publicly visible in Erroutc. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * erroutc.adb (Matches): M

[Ada] Ongoing work for AI12-0212: container aggregates

2021-05-04 Thread Pierre-Marie de Rodat
This patch refines the handling of container aggregates with non-static sizes given with iterated component associations and iterated element associations. When necessary we construct an expression to be evaluated dynamically to guide the allocation of the container, prior to inserting elements. T

[Ada] Simplify iteration over formal parameters for Global/Depends check

2021-05-04 Thread Pierre-Marie de Rodat
Replace low-level First_Entity/Next_Entity with a high-level First_Formal/Next_Formal. The new code is easier to debug, because we don't even see local subprograms, objects, etc. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * sem_prag.adb (Collect_Global_Item): Iterate dire

[Ada] Fix inconsistent iteration with First_Formal and Next_Entity

2021-05-04 Thread Pierre-Marie de Rodat
Iteration routines should come in pairs, i.e. First_Formal with Next_Formal and First_Entity with Next_Entity. This patch fixes two occurrences where First_Formal was used with Next_Entity. Cleanup only; semantics is unaffected. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/

[Ada] Reuse First_Formal for generic subprograms

2021-05-04 Thread Pierre-Marie de Rodat
Routine First_Formal works both for non-generic and generic subprograms, so patch removes a dubious special-casing for the latter. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * lib-xref.adb (Generate_Reference_To_Formals): Remove dedicated branch for generic subpro

[Ada] Fix handling of access-to-variable objects in Global and Depends

2021-05-04 Thread Pierre-Marie de Rodat
Objects that typically would be constant, but can actually be written because they are of access-to-variable type, can appear as outputs in the Global and Depends contracts of non-functions (i.e. functions, procedures, generic functions, generic procedures, protected entries, task types and single

[Ada] Assert_Failure vs Assertion_Error

2021-05-04 Thread Pierre-Marie de Rodat
When Ada introduced Ada.Assertions.Assertion_Error, we made it a renaming of the existing System.Assertions.Assert_Failure as provisioned by the ARM, but we should have done it the other way around, so that the reference/first class exception is the one from the ARM in e.g. exception messages. Thi

[Ada] Refine type of a counter variable from Integer to Natural

2021-05-04 Thread Pierre-Marie de Rodat
A List_Name_Count variable is initialized with zero, then incremented and decremented in a stack-like manner, so it should never become negative. This gives us extra confidence, but otherwise the behaviour is not affected. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * ppr

[Ada] Do not "optimize" by converting Positive to Unsigned

2021-05-04 Thread Pierre-Marie de Rodat
Back out the previous change that tried to "optimize" in Expand_Concatenate. It turns out that this is actually a pessimization, and it causes codepeer to trip over a bunch of extra checks. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * exp_ch4.adb (Expand_Concatenate): Rem

[Ada] Minor tweak in pretty-printing of expressions

2021-05-04 Thread Pierre-Marie de Rodat
Printing of expressions is used in GNATprove to display parts of an assertion which are not proved, Here the printing is improved slightly for an expression-with-actions, so that the underlying expression is printed, instead of the corresponding AST form of the expression with Expr_Name. Tested on

[Ada] Reuse existing To_Mixed routine in pretty-printer

2021-05-04 Thread Pierre-Marie de Rodat
Unit Pprint, which implements pretty-printing of the AST, defined routine To_Mixed_Case, which was identical to System.Case_Util.To_Mixed. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * pprint.adb (To_Mixed): Removed.diff --git a/gcc/ada/pprint.adb b/gcc/ada/pprint.adb ---

[Ada] Use function and not procedure UI_Image in pretty-printing

2021-05-04 Thread Pierre-Marie de Rodat
Code cleanup; semantics is unaffected. The code for pretty-printing integer, real and string literals now looks the same. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * pprint.adb (Expr_Name): Simplify with functional variant of UI_Image.diff --git a/gcc/ada/pprint.

[Ada] Remove arbitrary and redundant qualification with Sinfo

2021-05-04 Thread Pierre-Marie de Rodat
Code cleanup; semantics is unaffected. Perhaps the extra qualification used to be necessary to avoid ambiguities, but it is no longer needed. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * pprint.adb: Remove qualification of arbitrary calls to Sinfo.Expressions and

[Ada] Set constraint error on real division just like on integer division

2021-05-05 Thread Pierre-Marie de Rodat
In Eval_Arithmetic_Op we set Raises_Constraint_Error flag on integer division by zero, but we didn't set it for real division by zero. This only affects GNATprove, because GNAT sets this flag inside Apply_Compile_Time_Constraint_Error (which has an early return guarded by GNATprove_Mode). Possibly

[Ada] Ongoing work for AI12-0212: container aggregates

2021-05-05 Thread Pierre-Marie de Rodat
Add legality checks for indexed aggregates with component associations. RN 4.3.5 (28/5 - 30/5) specifies validity rules for indexed aggregates, intended to simplify implementation as well as the computation of the expected size of an indexed aggregate, such for an aggregaate of a vector type. Tes

<    1   2   3   4   5   6   7   8   9   10   >