[Ada] Prevent infinite recursion when there is no expected unit

2021-07-08 Thread Pierre-Marie de Rodat
The comment in Par.Load says "... or we are in big trouble, and abandon the compilation", but the code merely emitted errors and kept going. Now it emits errors, flags the problem in the unit table and gives up. Also, it was wrong for this routine to remove the unit, because the callers who add ent

[Ada] Replace low-level condition with a high-level call

2021-07-08 Thread Pierre-Marie de Rodat
Code cleanup; semantics is unaffected. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * lib-writ.adb (Ensure_System_Dependency): Simplify condition.diff --git a/gcc/ada/lib-writ.adb b/gcc/ada/lib-writ.adb --- a/gcc/ada/lib-writ.adb +++ b/gcc/ada/lib-writ.adb @@ -147,7 +147,7

[Ada] Restore context on failure in loading of renamed child unit

2021-07-08 Thread Pierre-Marie de Rodat
When loading of renamed child unit failed, we didn't properly restore the value of a global Parsing_Main_Extended_Source variable. This is primarily a cleanup change; behaviour is not affected (perhaps except for errors reported on complicated code that is illegal anyway). Tested on x86_64-pc-lin

[Ada] Remove redundant condition for listing compilation units

2021-07-08 Thread Pierre-Marie de Rodat
There is only one call to Unit_Display and it is guarded by the List_Units global variable. There is no need to retest this variable inside the Unit_Display routine. Code cleanup; semantics is unaffected. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * par-ch10.adb (Unit_Di

[Ada] Simplify redundant checks for non-empty lists

2021-07-08 Thread Pierre-Marie de Rodat
Simplify "Present (L) and then not Is_Empty_List (L)" into "not Is_Empty_List (L)", since Is_Empty_List can be called on No_List and returns True. Code cleanup; semantics is unaffected. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * sem_ch12.adb, sem_ch6.adb, sem_ch9.adb,

[Ada] Fix violation of No_Implicit_Loops restriction for enumeration type

2021-07-08 Thread Pierre-Marie de Rodat
The perfect hash function generated by the compiler to speed up the Value attribute of an enumeration type contains an implicit loop and, therefore, violates the No_Implicit_Loops restriction when it is active. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * exp_imgv.adb: Ad

[Ada] Spurious warning in generic instance

2021-07-08 Thread Pierre-Marie de Rodat
In the case of complex generic instantiations, the warning on component not being present can be spurious (corresponding to dead code for the given instance), so we disable it. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * sem_util.ads, sem_util.adb (Apply_Compile_

[Ada] AI12-0156 Use subtype indication in generalized iterators

2021-07-08 Thread Pierre-Marie de Rodat
Add syntax and semantic support for this new Ada 2022 feature. Support for proper accessibility levels to be investigated in a second step. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * par-ch5.adb (P_Iterator_Specification): Add support for access definition in lo

[Ada] Spurious style message on missing overriding indicator

2021-07-08 Thread Pierre-Marie de Rodat
In the presence of style switch -gnatyO, the compiler emits a spurious style violation message naming an inherited operation that does not come from an explicit subprogram declaration. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * style.adb (Missing_Overriding): Do not emi

[Ada] Duplicated D lines in ali files

2021-07-08 Thread Pierre-Marie de Rodat
GNATcoverage possibly relies on the presence of the duplicate D lines in ALI files for its Source Coverage Obligation tables among different instantiations of a same generic. Mention this in comments. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * lib-writ.ads: Mention SCOs

[Ada] Rename sigtramp-vxworks-target.inc to sigtramp-vxworks-target.h

2021-07-08 Thread Pierre-Marie de Rodat
The .inc extension isn't recognized by gprconfig. The original motivation for using this extension was to match the convention of putting code in .inc ala unwind.inc. However it's easier in this situation to just rename it to a .h file. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/

[Ada] Transient scope cleanup

2021-07-08 Thread Pierre-Marie de Rodat
Misc cleanups found while working on transient scopes. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * comperr.adb (Compiler_Abort): Call Sinput.Unlock, because if this is called late, then Source_Dump would crash otherwise. * debug.adb: Correct documentation

[Ada] Use encoded names only with -fgnat-encodings=all

2021-07-08 Thread Pierre-Marie de Rodat
This disables the last special encoding done in Get_Encoded_Name, except when -fgnat-encodings=all is passed on the command line. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * exp_dbug.adb (Get_Encoded_Name): Do not encode names of discrete types with custom bounds

[Ada] Diagnose properly illegal uses of Target_Name

2021-07-08 Thread Pierre-Marie de Rodat
Ada_2022 introduces the notion of Target_Name, written @, to be used in assignment statements, where it denotes the value of the left-hand side prior to the assignment. This patch diagnoses illegal uses of the target name outside of its legal context. Tested on x86_64-pc-linux-gnu, committed on tr

[Ada] Tune detection of illegal occurrences of target_name

2021-07-08 Thread Pierre-Marie de Rodat
Prevent AST climbing from going outside of the current program unit; tune style; add comments. Also, only set the Current_Assignment global variable when needed and clear it once the analysis of an assignment statement is done. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ *

[Ada] Remove Unknown_ functions

2021-07-08 Thread Pierre-Marie de Rodat
Remove the Unknown_ type representation attribute predicates from Einfo.Utils. "not Known_Alignment (...)" is at least as readable as "Unknown_Alignment (...)" -- we don't need a bunch of functions that just do a "not". Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * einfo-u

[Ada] Avoid unnecessary call in preanalysis without freezing

2021-07-09 Thread Pierre-Marie de Rodat
Cleanup related to preanalysis in GNATprove mode; behaviour is unaffected. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * sem_res.adb (Preanalyze_And_Resolve): Only call Set_Must_Not_Freeze when it is necessary to restore the previous value.diff --git a/gcc/

[Ada] Remove an unnecessary local constant

2021-07-09 Thread Pierre-Marie de Rodat
Code cleanup related to preanalysis in GNATprove mode; behaviour is unaffected. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * sem_ch6.adb (Analyze_Expression_Function): A local Expr constant was shadowing a global constant with the same name and the same va

[Ada] Refine types of local variables in analysis of expression functions

2021-07-09 Thread Pierre-Marie de Rodat
Code cleanup related to handing of static expression functions in GNATprove; behaviour is unaffected. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * sem_ch6.adb (Analyze_Expression_Function): Change types local variables from Entity_Id to Node_Id.diff --git a/gcc/ad

[Ada] Avoid repeated calls in analysis of expression functions

2021-07-09 Thread Pierre-Marie de Rodat
Code cleanup related to handing of static expression functions in GNATprove; behaviour is unaffected. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * sem_ch6.adb (Analyze_Expression_Function): Use Orig_N variable instead of repeated calls to Original_Node.diff --git

[Ada] Fix comment related to analysis of expression functions

2021-07-09 Thread Pierre-Marie de Rodat
Cleanup related to handing of static expression functions in GNATprove. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * sem_ch6.adb (Analyze_Expression_Function): Fix comment.diff --git a/gcc/ada/sem_ch6.adb b/gcc/ada/sem_ch6.adb --- a/gcc/ada/sem_ch6.adb +++ b/gcc/ada/sem_c

[Ada] Avoid repeated computing of type of expression functions

2021-07-09 Thread Pierre-Marie de Rodat
Cleanup related to handing of static expression functions in GNATprove. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * sem_ch6.adb (Analyze_Expression_Function): Add variable to avoid repeated calls to Etype.diff --git a/gcc/ada/sem_ch6.adb b/gcc/ada/sem_ch6.adb ---

[Ada] Decouple analysis of static expression functions from GNATprove

2021-07-09 Thread Pierre-Marie de Rodat
Analysis of static expression functions happened inside an IF branch guarded by GNATprove_Mode. Cleanup related to handling of static expression functions in GNATprove mode; behaviour is unaffected. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * sem_ch6.adb (Analyze_Express

[Ada] Reorder preanalysis of static expression functions

2021-07-09 Thread Pierre-Marie de Rodat
Group two variants of preanalysis of expression functions. Code cleanup related to handling of static expression functions in GNATprove. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * sem_ch6.adb (Analyze_Expression_Function): Reorder code.diff --git a/gcc/ada/sem_ch6.adb b

[Ada] Update internal documentation of debugging information

2021-07-09 Thread Pierre-Marie de Rodat
This updates the documentation of the debugging information generated by the compiler present in the spec of the Exp_Dbug unit. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * exp_dbug.ads: Update documentation of various items.diff --git a/gcc/ada/exp_dbug.ads b/gcc/ada/exp

[Ada] Incremental patch for restriction No_Dynamic_Accessibility_Checks

2021-07-09 Thread Pierre-Marie de Rodat
This patch corrects various issues discovered during testing of the No_Dynamic_Accessibility_Checks restriction leading to level miscalculation errors. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * sem_util.ads (Type_Access_Level): Add new optional parameter Assoc_

[Ada] Inconsistency between declaration and body of predicate functions

2021-07-09 Thread Pierre-Marie de Rodat
We need to declare a predicate function along with its type but can only generate the body at freeze point which may be in a separate scope, leading to inconsistencies. So fix this by deferring the generation of the predicate function declaration and fix latent bugs uncovered along the way. While

[Ada] Initialize local variables related to static expression functions

2021-07-09 Thread Pierre-Marie de Rodat
Explicitly initialize local variables related to analysis of expression functions to prevent spurious checks from static analysers. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * sem_ch6.adb (Analyze_Expression_Function): Initialize Orig_N and Typ variables.diff --g

[Ada] aarch64-rtems6: use wraplf variant for a-nallfl

2021-07-09 Thread Pierre-Marie de Rodat
Since newlib doesn't implement correctly long double, use the wraplf variant for a-nallfl. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * Makefile.rtl (LIBGNAT_TARGET_PAIRS) : Use the wraplf variant of Aux_Long_Long_Float.diff --git a/gcc/ada/Makefile.rtl b/gcc/ada/

[Ada] Add paragraph about representation changes and Scalar_Storage_Order

2021-07-09 Thread Pierre-Marie de Rodat
This in particular documents the new warning given on overlays. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * doc/gnat_rm/implementation_defined_attributes.rst (Scalar_Storage_Order): Add paragraph about representation changes. * gnat_rm.texi: Regen

[Ada] Fix typo in comment related to derived discriminated types

2021-07-09 Thread Pierre-Marie de Rodat
Minor typo; found while fixing handling of tagged types in GNATprove. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * exp_util.ads (Map_Types): Fix typo.diff --git a/gcc/ada/exp_util.ads b/gcc/ada/exp_util.ads --- a/gcc/ada/exp_util.ads +++ b/gcc/ada/exp_util.ads @@ -915,7 +

[Ada] Fix invalid JSON for derived variant record with -gnatRj

2021-07-09 Thread Pierre-Marie de Rodat
This prevents the output of -gnatRj from containing several "variant" fields for an extension with a variant part of a tagged type with a variant part. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * repinfo.ads (JSON output format): Document adjusted key name. * rep

[Ada] Fix layout of contracts

2021-07-09 Thread Pierre-Marie de Rodat
Fix layout of contracts in libgnat/a-strunb.ads and libgnat/a-strunb__shared.ads so that it is the same in both files. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * libgnat/a-strunb.ads, libgnat/a-strunb__shared.ads: Fix layout in contracts.diff --git a/gcc/ada/lib

[Ada] Add source file name to gnat bug box

2021-07-09 Thread Pierre-Marie de Rodat
...in case Current_Error_Node is Empty, which will cause it to print "No source file position information available". At least now we have the file name being compiled. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * comperr.adb (Compiler_Abort): Print source file name.diff

[Ada] Declare time_t uniformly based on a system parameter

2021-07-09 Thread Pierre-Marie de Rodat
The declaration of time_t is in flux based on it's overflow in Year 2038, so declare it uniformly based on System.Parameter.time_t_bits to ease this transition and also enable VxWorks targets which allow it to be parameterized, to be rebuilt more easily by one source change. Two changes of note: s

[Ada] Crash on inlined separate subprogram

2021-07-09 Thread Pierre-Marie de Rodat
This patch fixes an issue in the compiler whereby a pragma Inline appearing after a subprogram body stub to which it applies and where no specification is present causes a compile time crash. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * sem_ch6.adb (Check_Pragma_Inline):

[Ada] Add -gnatX support for casing on discriminated values

2021-07-09 Thread Pierre-Marie de Rodat
Improve existing support for the Ada extension feature of casing on composite values to handle casing on values that are discriminated or have discriminated subcomponents. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * exp_ch5.adb (Expand_General_Case_Statement): Add new fu

[Ada] Crash on expansion of BIP construct in -gnatf mode

2021-07-09 Thread Pierre-Marie de Rodat
This patch fixes an issue in the compiler whereby an assignment to a limited interface access type causes a crash when the right hand side has an unresolvable function call in prefix notation and verbose errors are enabled via (-gnatf). Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/

[Ada] Improve performance of Ada.Containers.Doubly_Linked_Lists.Generic_Sorting.Sort

2021-07-09 Thread Pierre-Marie de Rodat
The previous implementation could exhibit quadratic behavior in some cases (e.g., if the input was already sorted or almost sorted). The new implementation uses an N log N worst case algorithm. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * libgnat/a-cdlili.adb: Reimplement

[Ada] Add missed OS constant values

2021-07-09 Thread Pierre-Marie de Rodat
Add IPV6_FLOWINFO and IF_NAMESIZE values into generated package System.OS_Constants. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * gsocket.h: Include net/if.h to get IF_NAMESIZE constant. * s-oscons-tmplt.c: Define IPV6_FLOWINFO for Linux.diff --git a/gcc/ada/gsock

[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

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