aboutsummaryrefslogtreecommitdiff
path: root/gcc/ada
AgeCommit message (Collapse)AuthorFilesLines
2019-08-12[Ada] SPARK: disable expansion of Enum_RepYannick Moy2-1/+30
Disable expansion of Enum_Rep into a type conversion as it is incorrect in SPARK. 2019-08-12 Yannick Moy <moy@adacore.com> gcc/ada/ * exp_spark.adb (Expand_SPARK_N_Attribute_Reference): Only expand Enum_Rep attribute when its parameter is a literal. From-SVN: r274289
2019-08-12[Ada] Inconsistent compile time Constraint_Error warningJustin Squirek2-7/+32
This patch corrects several bugs within the compiler which led to inconsistent handling of compile time Constraint_Errors. Notibly, subtype out of range checks which are only out of range of the subtype must be warnings while out of range checks where the value is out of range of the base type must be an error. Also, type conversions and qualified expressions on literals constitute errors on any out of range value. The compiler needed many of these cases clarified. ------------ -- Source -- ------------ -- main.ads with System; package Main is type T_Enum is (Enum_1, Enum_2, Unknown) with Default_Value => Unknown; subtype T_Valid_Enum is T_Enum range Enum_1 .. Enum_2; Value : T_Valid_Enum; -- WARNING generic type T_Element is (<>); Init : T_Element; package Generic_Test is Value : T_Element := Init; end; package titi is new Generic_Test (T_Valid_Enum, Unknown); -- WARNING type My_Float is digits System.Max_Base_Digits; My_Float_Last : constant := My_Float'Last; Out_Of_Range : constant := My_Float_Last + 1.0; Flt1 : My_Float := Out_Of_Range; -- ERROR A : Positive := Positive (16#9999_9999_9999#); -- ERROR B : Positive := 16#9999_9999_9999#; -- ERROR C : Positive := 0; -- WARNING D : Positive := Positive (0); -- ERROR E : Positive := Positive'(16#9999_9999_9999#); -- ERROR F : Positive := Positive'(0); -- ERROR end; ----------------- -- Compilation -- ----------------- $ gnatmake -q -gnatw_a main.adb main.ads:9:12: warning: value not in range of type "T_Valid_Enum" defined at line 7 main.ads:9:12: warning: "Constraint_Error" will be raised at run time main.ads:18:52: warning: value not in range of type "T_Element" defined at line 12, instance at line 18 main.ads:18:52: warning: "Constraint_Error" will be raised at run time main.ads:25:23: value not in range of type "My_Float" defined at line 20 main.ads:25:23: static expression fails Constraint_Check main.ads:27:19: value not in range of type "Standard.Positive" main.ads:27:19: static expression fails Constraint_Check main.ads:28:19: value not in range of type "Standard.Positive" main.ads:28:19: static expression fails Constraint_Check main.ads:29:19: warning: value not in range of type "Standard.Positive" main.ads:29:19: warning: "Constraint_Error" will be raised at run time main.ads:30:19: value not in range of type "Standard.Positive" main.ads:30:19: static expression fails Constraint_Check main.ads:31:27: value not in range of type "Standard.Positive" main.ads:31:27: static expression fails Constraint_Check main.ads:32:27: value not in range of type "Standard.Positive" main.ads:32:27: static expression fails Constraint_Check gnatmake: "main.ads" compilation error 2019-08-12 Justin Squirek <squirek@adacore.com> gcc/ada/ * sem_eval.adb (Check_Non_Static_Context): Add a condition to determine if a range violation constitues a warning or an error. (Out_Of_Range): Add a condition to determine if a range violation constitues a warning or an error. From-SVN: r274288
2019-08-12[Ada] Eliminate redundant range checks on conversionsEric Botcazou2-44/+62
This gets rid of redundant range checks generated in 5 out of the 9 cases of scalar conversions, i.e. (integer, fixed-point, floating-point) converted to (integer, fixed-point, floating-point). The problem is that the Real_Range_Check routine rewrites the conversion node into a conversion to the base type so, when its parent node is analyzed, a new conversion to the subtype may be introduced, depending on the context, giving rise to a second range check against the subtype bounds. This change makes Real_Range_Check rewrite the expression of the conversion node instead of the node, so that the type of the node is preserved and no new conversion is introduced. As a matter of fact, this is exactly what happens in the float-to-float case which goes to the Generate_Range_Check circuit instead and does not suffer from the duplication of range checks. For the following procedure, the compiler must now generate exactly one range check per nested function: procedure P is type I1 is new Integer range -100 .. 100; type I2 is new Integer range -200 .. 200; type D1 is delta 0.5 range -100.0 .. 100.0; type D2 is delta 0.5 range -200.0 .. 200.0; type F1 is new Long_Float range -100.0 .. 100.0; type F2 is new Long_Float range -200.0 .. 200.0; function Conv (A : I2) return I1 is begin return I1 (A); end; function Conv (A : D2) return I1 is begin return I1 (A); end; function Conv (A : F2) return I1 is begin return I1 (A); end; function Conv (A : I2) return D1 is begin return D1 (A); end; function Conv (A : D2) return D1 is begin return D1 (A); end; function Conv (A : F2) return D1 is begin return D1 (A); end; function Conv (A : I2) return F1 is begin return F1 (A); end; function Conv (A : D2) return F1 is begin return F1 (A); end; function Conv (A : F2) return F1 is begin return F1 (A); end; begin null; end; 2019-08-12 Eric Botcazou <ebotcazou@adacore.com> gcc/ada/ * exp_ch4.adb (Real_Range_Check): Do not rewrite the conversion node but its expression instead, after having fetched its current value. Clear the Do_Range_Check flag on entry. Return early for a rewritten float-to-float conversion. Remove redundant local variable. Suppress all checks when inserting the temporary and do not reanalyze the node. From-SVN: r274287
2019-08-12[Ada] Sprint: minor comment tweakEric Botcazou2-1/+5
2019-08-12 Eric Botcazou <ebotcazou@adacore.com> gcc/ada/ * sprint.ads: Minor comment tweak. From-SVN: r274286
2019-08-12[Ada] Fix leak of Do_Range_Check flag in -gnatVa modeEric Botcazou2-8/+12
This fixes a small glitch in Insert_Valid_Check, which needs to propagate the Do_Range_Check flag onto the rewritten expression, but uses its Original_Node as the source of the copy. Now Original_Node does not necessarily point to the node that was just rewritten, but to the ultimately original node, which is not the same node if the expression was rewritten multiple times. The end result is that a stalled Do_Range_Check flag can be wrongly resintated and leak to the code generator. 2019-08-12 Eric Botcazou <ebotcazou@adacore.com> gcc/ada/ * checks.adb (Insert_Valid_Check): Do not retrieve the Do_Range_Check flag from the Original_Node but from the Validated_Object. Remove useless bypass for floating-point types. gcc/testsuite/ * gnat.dg/range_check7.adb: New testcase. From-SVN: r274285
2019-08-12[Ada] Extended traversal subprograms for GNATproveYannick Moy3-1/+221
GNATprove needs traversal subprograms that do not simply traverse syntactic nodes like Atree.Traverse_Func and Atree.Traverse_Proc, but also traverse semantic nodes which are logically children of the nodes. Now available through Sem_Util.Traverse_More_Func and Sem_Util.Traverse_More_Proc. There is no impact on compilation. 2019-08-12 Yannick Moy <moy@adacore.com> gcc/ada/ * sem_util.adb, sem_util.ads (Traverse_More_Func, Traverse_More_Proc): New traversal subprograms. From-SVN: r274284
2019-08-12[Ada] VxWorks: call s-tpopsp.Self only when neededJerome Lambourg2-1/+11
2019-08-12 Jerome Lambourg <lambourg@adacore.com> gcc/ada/ * libgnarl/s-taprop__vxworks.adb (Abort_Handler): Only call s-tpopsp.Self when actually needed. From-SVN: r274283
2019-08-12[Ada] Plug small loophole in Discrete_Range_CheckEric Botcazou2-1/+23
This routine would not return if range checks are suppressed. 2019-08-12 Eric Botcazou <ebotcazou@adacore.com> gcc/ada/ * exp_ch4.adb (Discrete_Range_Check): Return if checks are suppressed. From-SVN: r274282
2019-08-12[Ada] Add special bypass for obsolete code patternEric Botcazou2-7/+27
This change prevents the analysis phase of the front-end from setting the Do_Range_Check flag in the very peculiar case of the source of a conversion whose result is passed by reference to a "valued procedure", because the expansion phase would not be able to generate the check. This pattern appears in the ancient DEC Starlet package and it doesn't seem to be useful at this point to change the expander to deal with it, so instead the analysis phase is adjusted. Morever the compiler already issues a warning in this case so this is probably good enough. 2019-08-12 Eric Botcazou <ebotcazou@adacore.com> gcc/ada/ * sem_res.adb: Add with & use clause for Sem_Mech and alphabetize. (Resolve_Actuals): Do not apply a scalar range check for the source of a conversion whose result is passed by reference to a valued procedure. From-SVN: r274281
2019-08-12[Ada] Fix missing range check for In/Out parameter with -gnatVaEric Botcazou4-36/+62
This plugs another small loophole in the front-end which fails to generate a range check for a scalar In/Out parameter when -gnatVa is specified. This also fixes a few more leaks of the Do_Range_Check flag on actual parameters, both in regular and -gnatVa modes, as well as a leak specific to expression function in -gnatp mode. 2019-08-12 Eric Botcazou <ebotcazou@adacore.com> gcc/ada/ * checks.adb (Insert_Valid_Check): Reset the Do_Range_Check flag on the validated object. * exp_ch6.adb (Add_Call_By_Copy_Code): Reset the Do_Range_Check flag on the actual here, as well as on the Expression if the actual is a N_Type_Conversion node. (Add_Validation_Call_By_Copy_Code): Generate the incoming range check if needed and reset the Do_Range_Check flag on the Expression if the actual is a N_Type_Conversion node. (Expand_Actuals): Do not reset the Do_Range_Check flag here. Generate the incoming range check for In parameters here instead of... (Expand_Call_Helper): ...here. Remove redudant condition. * sem_res.adb (Resolve_Actuals): Use local variable A_Typ and remove obsolete comments. (Resolve_Type_Conversion): Do not force the Do_Range_Check flag on the operand if range checks are suppressed. gcc/testsuite/ * gnat.dg/range_check6.adb: New testcase. From-SVN: r274280
2019-08-12[Ada] Fix incorrect Do_Range_Check on type conversionEric Botcazou2-3/+15
This gets rid of another leak of the Do_Range_Check flag to the back-end which is specific to expression functions. No functional changes. 2019-08-12 Eric Botcazou <ebotcazou@adacore.com> gcc/ada/ * checks.adb (Activate_Range_Check): Remove redundant argument. (Generate_Range_Check): Likewise. (Apply_Float_Conversion_Check): Reset the Do_Range_Check flag on entry and remove redundant condition. From-SVN: r274279
2019-08-10Assorted ChangeLog cleanups.Jakub Jelinek1-4/+4
From-SVN: r274250
2019-08-02rework Ada EH Machine_Occurrence deallocationAlexandre Oliva3-47/+316
Introduce exception handler ABI #1 to ensure single release, no access after release of reraised Machine_Occurrences, and no failure to re-reraise a Machine_Occurrence. Unlike Ada exceptions, foreign exceptions do not get a new Machine_Occurrence upon reraise, but each handler would delete the exception upon completion, normal or exceptional, save for the case of a 'raise;' statement within the handler, that avoided the delete by clearing the exception pointer that the cleanup would use to release it. The cleared exception pointer might then be used by a subsequent reraise within the same handler. Get_Current_Excep.all would also expose the Machine_Occurrence to reuse by Reraise_Occurrence, even for native exceptions. Under ABI #1, Begin_Handler_v1 claims responsibility for releasing an exception by saving its cleanup and setting it to Claimed_Cleanup. End_Handler_v1 restores the cleanup and runs it, as long as it isn't still Claimed_Cleanup (which indicates an enclosing handler has already claimed responsibility for releasing it), and as long as the same exception is not being propagated up (the next handler of the propagating exception will then claim responsibility for releasing it), so reraise no longer needs to clear the exception pointer, and it can just propagate the exception, just like Reraise_Occurrence. ABI #1 is fully interoperable with ABI #0, i.e., exception handlers that call the #0 primitives can be linked together with ones that call the #1 primitives, and they will not misbehave. When a #1 handler claims responsibility for releasing an exception, even #0 reraises dynamically nested within it will refrain from releasing it. However, when a #0 handler is a handler of a foreign exception that would have been responsible for releasing it with #1, a Reraise_Occurrence of that foreign or other Machine_Occurrence-carrying exception may still cause the exception to be released multiple times, and to be used after it is first released, even if other handlers of the foreign exception use #1. for gcc/ada/ChangeLog * libgnat/a-exexpr.adb (Begin_Handler_v1, End_Handler_v1): New. (Claimed_Cleanup): New. (Begin_Handler, End_Handler): Document. * gcc-interface/trans.c (gigi): Switch to exception handler ABI #1. (Exception_Handler_to_gnu_gcc): Save the original cleanup returned by begin handler, pass it to end handler, and use EH_ELSE_EXPR to pass a propagating exception to end handler. (gnat_to_gnu): Leave the exception pointer alone for reraise. (add_cleanup): Handle EH_ELSE_EXPR, require it by itself. From-SVN: r274029
2019-07-23[Ada] Aspect CPU may depend on a discriminant of a task typeEd Schonberg2-0/+9
2019-07-23 Ed Schonberg <schonberg@adacore.com> gcc/ada/ * sem_ch13.adb (Check_Aspect_At_End_Of_Declarations, Freeze_Entity_Checks): Include Aspect_CPU with other aspects whose expresssion may depend on a discriminant, and thus require that components of the type be made visible. gcc/testsuite/ * gnat.dg/task4.adb: New testcase. From-SVN: r273726
2019-07-23[Ada] Plug small loophole in Generate_Range_CheckEric Botcazou3-35/+50
The Generate_Range_Check routine is responsible for generating range checks in the scalar case. It automatically deals with possible overflow in the process when the source and the target base types are different. However there is one case where overflow is not dealt with correctly, namely when the target base type is narrower than the source base type and both are floating-point types. In this case, the routine will convert the source type to the target base type without checking for overflow. In practice this does not matter much because the conversion would yield an infinity on overflow, which would then fail the subsequent range check. However it's more correct to have a proper overflow check with -gnateF than relying on the infinity. 2019-07-23 Eric Botcazou <ebotcazou@adacore.com> gcc/ada/ * checks.adb (Convert_And_Check_Range): Add Suppress parameter and pass it in the call to Insert_Actions. Rename local variable. (Generate_Range_Check): Minor comment fixes. Pass Range_Check in the first call to Convert_And_Check_Range and All_Checks in the second call. * exp_ch4.adb (Expand_N_Type_Conversion): Reset the Do_Overflow_Check flag in the float-to-float case too if there is also a range check. gcc/testsuite/ * gnat.dg/range_check5.adb: New testcase. From-SVN: r273725
2019-07-23[Ada] Eliminate redundant overflow checks for conversions from fixed-pointEric Botcazou3-6/+13
This eliminates redundant overflow checks that are generated for conversions from fixed-point to integer types when range checks are also enabled (which is the default), as the former checks are subsumed into the latter checks. No functional changes. 2019-07-23 Eric Botcazou <ebotcazou@adacore.com> gcc/ada/ * checks.adb (Activate_Overflow_Check): Remove redundant argument. * exp_ch4.adb (Discrete_Range_Check): Reset the overflow flag. (Expand_N_Type_Conversion): Do not reset it here. From-SVN: r273724
2019-07-23[Ada] Minor tweak to -gnatR outputEric Botcazou2-6/+11
This makes sure that the numbers present in the -gnatR output are printed in decimal format in all cases, since the hexadecimal format is not compatible with the JSON syntax. 2019-07-23 Eric Botcazou <ebotcazou@adacore.com> gcc/ada/ * repinfo.adb (List_Component_Layout): Pass Decimal to UI_Write. (Write_Val): Likewise. From-SVN: r273723
2019-07-23[Ada] Iterators are view-specificEd Schonberg4-2/+41
Operational aspects, such as Default_Iterator, are view-specific, and if such an aspect appears on the full view of a private type, an object of the type cannot be iterated upon if it is not in the scope of the full view, This patch diagnoses properly an attempt to iterate over such an object. 2019-07-23 Ed Schonberg <schonberg@adacore.com> gcc/ada/ * aspects.ads: New table Operational_Aspect, used to distinguish between aspects that are view-specific, such as those related to iterators, and representation aspects that apply to all views of a type. * aspects.adb (Find_Aspect): If the aspect being sought is operational, do not ecamine the full view of a private type to retrieve it. * sem_ch5.adb (Analyze_Iterator_Specification): Improve error message when the intended domain of iteration does not implement the required iterator aspects. gcc/testsuite/ * gnat.dg/iter5.adb: Add an expected error. * gnat.dg/iter6.adb: New testcase. From-SVN: r273722
2019-07-23[Ada] Issue error on SPARK ownership rule violationYannick Moy3-13/+62
A modified rule in SPARK RM specifies that object declarations of anonymous access type should only occur immediately in subprogram, entry or block. Now checked. There is no impact on compilation. 2019-07-23 Yannick Moy <moy@adacore.com> gcc/ada/ * sem_spark.ads (Is_Local_Context): New function. * sem_spark.adb (Check_Declaration): Issue errors on violations of SPARK RM 3.10(4) (Process_Path): Do not issue error on borrow/observe during elaboration, as these are caught by the new rule. From-SVN: r273721
2019-07-23[Ada] Fix binding of ghost units with finalizerYannick Moy3-0/+22
Linking of an enabled ghost unit which requires a finalizer lead to an error, as the name generated by the binder for calling the finalizer was not the same as the name chosen by the compiler. Now fixed. 2019-07-23 Yannick Moy <moy@adacore.com> gcc/ada/ * exp_ch7.adb (Create_Finalizer): Force finalizer not to be Ghost enabled. * exp_dbug.adb (Get_External_Name): Explain special case of Ghost finalizer. gcc/testsuite/ * gnat.dg/ghost6.adb, gnat.dg/ghost6_pkg.ads: New testcase. From-SVN: r273720
2019-07-22[Ada] More complete information level for -gnatR4 outputEric Botcazou2-0/+12
This instructs -gnatR4 to also list the Etype of user-declared objects if it is compiler-generated, for example in: package P2 is Arr_V : array (1 .. 5) of Integer; end P2; 2019-07-22 Eric Botcazou <ebotcazou@adacore.com> gcc/ada/ * repinfo.adb (List_Entities): Also list compiled-generated types present as Etype of objects. From-SVN: r273697
2019-07-22[Ada] Sinfo: update doc about Do_Division/Overlflow/Range_CheckEric Botcazou2-26/+22
2019-07-22 Eric Botcazou <ebotcazou@adacore.com> gcc/ada/ * sinfo.ads: Update the documentation about the Do_Division_Check, Do_Overflow_Check and Do_Range_Check flags. From-SVN: r273696
2019-07-22[Ada] Fix missing check for no-op conversion to fixed-point typeEric Botcazou2-3/+12
This plugs a small loophole in the compiler for the case of a multiplication or a division in a fixed-point type wrapped in a no-op conversion, e.g. to the same fixed-point type. The front-end fails to generate a range check for the operation. This used to be caught by the back-end, which would generate the range check, but this is no longer the case because we now make sure to reset the Do_Range_Check flag in all cases before invoking the back-end. 2019-07-22 Eric Botcazou <ebotcazou@adacore.com> gcc/ada/ * exp_ch4.adb (Expand_N_Type_Conversion): Beef up comment. (Fixup_Universal_Fixed_Operation): Set the base type instead of the type of the enclosing type conversion on the operation. gcc/testsuite/ * gnat.dg/fixedpnt6.adb: New testcase. From-SVN: r273695
2019-07-22[Ada] Remove misleading warning/suggestion in membership testEd Schonberg2-0/+17
This patch removes a warning on a membership test whose right operand is given by a range. In many cases the check can be replaced by the use of attribute 'Valid, but if the bounds of range are type conversion this replacement would be invorrect and the warning and suggestion are misleading. 2019-07-22 Ed Schonberg <schonberg@adacore.com> gcc/ada/ * exp_ch4.adb (Expand_N_In): Do not suggest the use of attribute 'Valid as a replacement for a range check on a discrete type when the bounds of the range are given by type conversions, because in such a case there are distinct types involved and the subbested attribute replacement would be misplaced. gcc/testsuite/ * gnat.dg/warn26.adb: New testcase. From-SVN: r273694
2019-07-22[Ada] Adapt ownership checking in SPARK to traversal functionsYannick Moy2-18/+217
A traversal function, especially when implemented as an expression function, may need to return an if-expression or case-expression, while still respecting Legality Rule SPARK RM 3.10(5). This case is now allowed in GNATprove. There is no impact on compilation. 2019-07-22 Yannick Moy <moy@adacore.com> gcc/ada/ * sem_spark.adb (Get_Root_Object, Is_Path_Expression, Is_Subpath_Expression): Add parameter Is_Traversal to adapt these functions to the case of paths returned from a traversal function. (Read_Indexes): Handle the case of an if-expression or case-expression. (Check_Statement): Check Emit_Messages only when issuing an error message. This is important as Emit_Messages may store the information that an error was detected. From-SVN: r273693
2019-07-22[Ada] Overhaul code implementing conversions involving fixed-point typesEric Botcazou4-210/+142
This ovehauls the code implementing conversions involving fixed-point types in the front-end because it leaks the Do_Range_Check flag in several places to the back-end, which is a violation of the documented interface between front-end and back-end. This also does a bit of housekeeping work throughout it in the process. There should be essentially no functional changes. 2019-07-22 Eric Botcazou <ebotcazou@adacore.com> gcc/ada/ * checks.adb (Apply_Type_Conversion_Checks): Do not set Do_Range_Check flag on conversions from fixed-point types either. * exp_attr.adb: Add use and with clause for Expander. (Expand_N_Attribute_Reference) <Fixed_Value, Integer_Value>: Set the Conversion_OK flag and do not generate overflow/range checks manually. * exp_ch4.adb (Expand_N_Qualified_Expression): Remove superfluous clearing of Do_Range_Check flag. (Discrete_Range_Check): New procedure to generate a range check for discrete types. (Real_Range_Check): Remove redundant local variable and adjust. Remove useless shortcut. Clear Do_Range_Check flag on all paths. (Expand_N_Type_Conversion): Remove redundant test on Conversion_OK. Call Discrete_Range_Check to generate range checks on discrete types. Remove obsolete code for float-to-integer conversions. Add code to generate range checks for conversions involving fixed-point types. From-SVN: r273692
2019-07-22[Ada] Sprint: fix pasto in commentEric Botcazou2-1/+5
2019-07-22 Eric Botcazou <ebotcazou@adacore.com> gcc/ada/ * sprint.ads: Fix pasto in comment. From-SVN: r273691
2019-07-22[Ada] Spurious error passing access to class-wide interface typeJavier Miranda2-7/+13
The compiler reports an spurious error when the formal parameter of a subprogram is an access to a class wide interface type and the actual parameter is an allocator of an object covering such interface type. 2019-07-22 Javier Miranda <miranda@adacore.com> gcc/ada/ * sem_res.adb (Resolve_Actuals): Replace code that displaces the pointer to an allocated object to reference its secondary dispatch table by a type conversion (which takes care of handling all cases). gcc/testsuite/ * gnat.dg/class_wide5.adb: New testcase. From-SVN: r273690
2019-07-22[Ada] Small enhancement to the -gnatD/-gnatG output for fixed-point typesEric Botcazou2-32/+67
This is a small enhancement to the -gnatD/-gnatG output: the base type of fixed-point types, which is usually an itype, used to be printed as ??? in this case. It is now printed in a similar fashion as the first subtype. For the following package: package P is type D is delta 128.0 / (2 ** 15) range 0.0 .. 256.0; end P; the -gnatD/-gnatG must now be: Source recreated from tree for P (spec) --------------------------------------- p_E : short_integer := 0; package p is type p__d is delta [1.0/256.0] range 0.0 .. 256.0; [type p__TdB is delta [1.0/256.0] range -[2147483648.0*2**(-8)] .. [2147483647.0*2**(-8)]] freeze p__TdB [] end p; 2019-07-22 Eric Botcazou <ebotcazou@adacore.com> gcc/ada/ * sprint.adb (Sprint_Node_Actual) <N_Decimal_Fixed_Point_Definition>: Swap a couple of spaces. (Write_Itype): Minor consistency fixes throughout. Add support for printing ordinary and decimal fixed-point types and subtypes. From-SVN: r273689
2019-07-22[Ada] Beef up comment in exp_attr.adbEric Botcazou2-2/+7
2019-07-22 Eric Botcazou <ebotcazou@adacore.com> gcc/ada/ * exp_attr.adb (Expand_Loop_Entry_Attribute): Beef up comment. From-SVN: r273688
2019-07-22[Ada] Optimization loses exception in improper use of 'ValueEd Schonberg12-11/+24
This patch prevents an improper removal of an evaluation of attribute 'Value on an illegal input that will raise Constraint_Error, when a subsequent use of this evaluation might be optimized away by the back-end. 2019-07-22 Ed Schonberg <schonberg@adacore.com> gcc/ada/ * libgnat/s-valboo.ads, libgnat/s-valcha.ads, libgnat/s-valdec.ads, libgnat/s-valenu.ads, libgnat/s-valint.ads, libgnat/s-vallld.ads, libgnat/s-vallli.ads, libgnat/s-valllu.ads, libgnat/s-valrea.ads, libgnat/s-valuns.ads, libgnat/s-valwch.ads: Change categorization of packages that implement attribute 'Value from Pure to Preelaborate, to prevent undesirable optimizations when the evaluation of the attribute raises Constraint_Error, but subsequent use of the result of this evsaluation is removed by a subsequent optimization. gcc/testsuite/ * gnat.dg/opt80.adb: New testcase. From-SVN: r273687
2019-07-22[Ada] Misleading warning on variable not assignedEd Schonberg2-2/+13
This patch removes a warning on a referenced entity with no explicit prior assignment, if the type of the entity has Preelaborable_Initialixation, such as Exception_Occurrence. 2019-07-22 Ed Schonberg <schonberg@adacore.com> gcc/ada/ * sem_warn.adb (Check_References): Do not emit s warning on a referenced entity with no explicit assignment if the type of the entity has Preelaborable_Initialixation, such as Exception_Occurrence. gcc/testsuite/ * gnat.dg/warn25.adb: New testcase. From-SVN: r273686
2019-07-22[Ada] Usage of signed type in array bounds in CCGJavier Miranda3-20/+173
2019-07-22 Javier Miranda <miranda@adacore.com> gcc/ada/ * exp_ch4.adb (Size_In_Storage_Elements): Improve the expansion to handle array indexes that are modular type. (Expand_N_Allocator): For 32-bit targets improve the generation of the runtime check associated with large arrays supporting arrays initialized with a qualified expression. * libgnat/s-imenne.adb (Image_Enumeration_8, Image_Enumeration_16, Image_Enumeration_32): Define the index of Index_Table with range Natural'First .. Names'Length since in the worst case all the literals of the enumeration type would be single letter literals and the Table built by the frontend would have as many components as the length of the names string. As a result of this enhancement, the internal tables declared using Index_Table have a length closer to the real needs, thus avoiding the declaration of large arrays on 32-bit CCG targets. From-SVN: r273685
2019-07-22[Ada] Issue warning or error message on ignored typing constraintYannick Moy2-0/+9
GNAT ignores the discriminant constraint on a component when it applies to the type of the record being analyzed. Now issue a warning on Ada code when ignoring this constraint, or an error on SPARK code. 2019-07-22 Yannick Moy <moy@adacore.com> gcc/ada/ * sem_ch3.adb (Constrain_Access): Issue a message about ignored constraint. gcc/testsuite/ * gnat.dg/warn24.adb: New testcase. From-SVN: r273684
2019-07-22[Ada] Fix spurious visibility error for tagged type with inliningEric Botcazou2-1/+18
This fixes a spurious visibility error for the very peculiar case where an operator that operates on the class-wide type of a tagged type is declared in a package, the operator is renamed in another package where a subtype of the tagged type is declared, and both packages end up in the transititive closure of a unit compiled with optimization and inter-inlining (-gnatn). 2019-07-22 Eric Botcazou <ebotcazou@adacore.com> gcc/ada/ * sem_ch8.adb (End_Use_Type): Reset the In_Use flag on the class-wide type if the type is tagged. (Use_One_Type): Add commentary on the handling of the class-wide type. gcc/testsuite/ * gnat.dg/inline17.adb, gnat.dg/inline17_pkg1.adb, gnat.dg/inline17_pkg1.ads, gnat.dg/inline17_pkg2.ads, gnat.dg/inline17_pkg3.adb, gnat.dg/inline17_pkg3.ads: New testcase. From-SVN: r273683
2019-07-22[Ada] Remove obsolete Is_For_Access_Subtype machineryEric Botcazou7-58/+19
This change removes the Is_For_Access_Subtype machinery from the compiler. This machinery was devised a long time ago to deal with a peculiarity of the freezing for access-to-record subtypes but has been degenerate for quite some time now and does not seem to serve any useful purpose at this point. Morever it has an annoying side effect whereby it causes Underlying_Type to return the (unconstrained) base record type when invoked on the designated record subtype, which is very problematic for GNATprove. There should be no functional changes. 2019-07-22 Eric Botcazou <ebotcazou@adacore.com> gcc/ada/ * einfo.ads (Is_For_Access_Subtype): Delete. (Set_Is_For_Access_Subtype): Likewise. * einfo.adb (Is_For_Access_Subtype): Likewise. (Set_Is_For_Access_Subtype): Likewise. (Write_Entity_Flags): Do not write Is_For_Access_Subtype. * exp_ch4.adb (Expand_N_Selected_Component): Do not deal with it. * exp_spark.adb (Expand_SPARK_N_Selected_Component): Likewise. * sem_ch4.adb (Analyze_Explicit_Dereference): Likewise. * sem_ch3.adb (Build_Discriminated_Subtype): Do not build a special private subtype for access-to-record subtypes. From-SVN: r273682
2019-07-22[Ada] Spurious error on private subtype of derived access typeEric Botcazou2-57/+68
This patch fixes a spurious type error on a dynamic predicate on a subtype of a private type whose full view is a derived access type. Prior to it, the base type of the subtype would appear to be the parent type of the derived type instead of the derived type itself, leading to problems downstream. The following package must now compile quietly: with S; package T is type B_Pointer is private; Null_B_Pointer : constant B_Pointer; function OK (B : B_Pointer) return Boolean is (B /= Null_B_Pointer); subtype Valid_B_Pointer is B_Pointer with Dynamic_Predicate => OK (Valid_B_Pointer); private type B_Pointer is new S.A_Pointer; Null_B_Pointer : constant B_Pointer := B_Pointer (S.Null_A_Pointer); end; package S is type A_Type is new Integer; type A_Pointer is access A_Type; Null_A_Pointer : constant A_Pointer := null; end; Moreover, it also plugs a loophole in the compiler whereby an instantiation of a generic with a formal subprogram declaration nested in an enclosing generic package would be done even if there was a mismatch between an original and a derived types involved in the instantiation. The compiler must now gives the following error: p.adb:11:43: no visible subprogram matches the specification for "Action" on with Q; with R; with G; procedure P is package My_G is new G (Q.T); procedure Proc (Value : R.T) is null; procedure Iter is new My_G.Iteration_G (Proc); begin null; end; with R; package Q is type T is new R.T; end Q; package R is type T is private; private type T is access Integer; end R; generic type Value_T is private; package G is generic with procedure Action (Value : Value_T); procedure Iteration_G; end G; package body G is procedure Iteration_G is null; end G; 2019-07-22 Eric Botcazou <ebotcazou@adacore.com> gcc/ada/ * sem_ch3.adb (Complete_Private_Subtype): Rework the setting of the Etype of the full view for full base types that cannot contain any discriminant. Remove code and comment about it in the main path. From-SVN: r273681
2019-07-22[Ada] Type inconsistency in floating_point type declarationsEd Schonberg2-19/+36
This patch fixes an inconsistency in the typing of the bounds of a floting point type declaration, when some bound is given by a dtatic constant of an explicit type, instead of a real literal, Previous to this patch the bound of the type retained the given type, leading to spurious errors in Codepeer. 2019-07-22 Ed Schonberg <schonberg@adacore.com> gcc/ada/ * sem_ch3.adb (Convert_Bound): Subsidiary of Floating_Point_Type_Declaration, to handle properly range specifications with bounds that may include static constants of a given type rather than real literals. From-SVN: r273680
2019-07-22[Ada] Further fix non-stored discriminant in aggregate for GNATproveEric Botcazou2-11/+41
GNATprove expects discriminants appearing in aggregates and their types to be resolved to stored discriminants. This extends the machinery that makes sure this is the case for default initialization expressions so as to also handle component associations in these expressions. 2019-07-22 Eric Botcazou <ebotcazou@adacore.com> gcc/ada/ * sem_aggr.adb (Rewrite_Bound): Be prepared for discriminals too. (Rewrite_Range;): Minor tweak. (Resolve_Record_Aggregate): For a component with default initialization whose expression is an array aggregate, also rewrite the bounds of the component associations, if any. From-SVN: r273679
2019-07-22[Ada] Premature finalization of controlled temporaries in case expressionsGary Dismukes2-7/+23
The compiler was generating finalization of temporary objects used in evaluating case expressions for controlled types in cases where the case statement created by Expand_N_Expression_With_Actions is rewritten as an if statement. This is fixed by inheriting the From_Condition_Expression flag from the rewritten case statement. The test below must generate the following output when executed: $ main Xs(1): 1 ---- package Test is type E is (E1, E2); procedure Test (A : in E); end Test; ---- with Ada.Text_IO; with Ada.Finalization; package body Test is type T is new Ada.Finalization.Controlled with record N : Natural := 0; end record; overriding procedure Finalize (X : in out T) is begin X.N := 42; end Finalize; type T_Array is array (Positive range <>) of T; function Make_T (N : Natural) return T is begin return (Ada.Finalization.Controlled with N => N); end Make_T; X1 : constant T := Make_T (1); X2 : constant T := Make_T (2); procedure Test (A : in E) is Xs : constant T_Array := (case A is when E1 => (1 => X1), when E2 => (1 => X2)); begin Ada.Text_IO.Put_Line ("Xs(1):" & Natural'Image (Xs (1).N)); end Test; end Test; ---- with Test; procedure Main is begin Test.Test (Test.E1); end Main; 2019-07-22 Gary Dismukes <dismukes@adacore.com> gcc/ada/ * exp_ch5.adb (Expand_N_Case_Statement): In the case where a case statement is rewritten as an equivalent if statement, inherit the From_Condition_Expression flag from the case statement. From-SVN: r273678
2019-07-22[Ada] Internal error on iterator for limited private discriminated typeEric Botcazou2-8/+7
This patch further extends the short-circuit, aka optimization, present in the Check_Constrained_Object procedure used for renaming declarations to all limited types, so as to prevent type mismatches downstream in more cases. 2019-07-22 Eric Botcazou <ebotcazou@adacore.com> gcc/ada/ * sem_ch8.adb (Check_Constrained_Object): Further extend the special optimization to all limited types. gcc/testsuite/ * gnat.dg/iter5.adb, gnat.dg/iter5_pkg.ads: New testcase. From-SVN: r273677
2019-07-22[Ada] Fix missing Constraint_Error for Enum_Val attributeEric Botcazou2-0/+14
This fixes an old issue involving the Enum_Val attribute: it does not always raise a Constraint_Error exception when the specified value is not valid for the enumeration type (instead a modulo computation is applied to the value). 2019-07-22 Eric Botcazou <ebotcazou@adacore.com> gcc/ada/ * exp_attr.adb (Expand_N_Attribute_Reference) <Attribute_Enum_Val>: Set No_Truncation on the N_Unchecked_Type_Conversion built around the argument passed to the attribute. gcc/testsuite/ * gnat.dg/enum_val1.adb: New testcase. From-SVN: r273676
2019-07-22[Ada] Ensure meaningless digits in a string are discardedNicolas Roche2-52/+51
2019-07-22 Nicolas Roche <roche@adacore.com> gcc/ada/ * libgnat/s-valrea.adb (Scan_Real): Ignore non significative digits to avoid converging to infinity in some cases. gcc/testsuite/ * gnat.dg/float_value1.adb: New testcase. From-SVN: r273675
2019-07-22[Ada] Fix wrong assumption on bounds in GNAT.Encode_StringEric Botcazou2-4/+9
This fixes a couple of oversights in the GNAT.Encode_String package, whose effect is to assume that all the strings have a lower bound of 1. 2019-07-22 Eric Botcazou <ebotcazou@adacore.com> gcc/ada/ * libgnat/g-encstr.adb (Encode_Wide_String): Fix oversight. (Encode_Wide_Wide_String): Likewise. gcc/testsuite/ * gnat.dg/encode_string1.adb, gnat.dg/encode_string1_pkg.adb, gnat.dg/encode_string1_pkg.ads: New testcase. From-SVN: r273674
2019-07-22[Ada] Fix spurious loop warning for function with Out parameterEric Botcazou2-0/+10
The compiler gives a spurious warning about a possible infinite while loop whose condition contains a call to a function that takes an Out or In/Out parameter and whose actual is a variable that is not modified in the loop, because it still thinks that functions can only have In parameters. 2019-07-22 Eric Botcazou <ebotcazou@adacore.com> gcc/ada/ * sem_warn.adb (Find_Var): Bail out for a function call with an Out or In/Out parameter. gcc/testsuite/ * gnat.dg/warn23.adb: New testcase. From-SVN: r273673
2019-07-22[Ada] Ensure Ctrl-C is not emited on terminated processesNicolas Roche4-25/+93
Due to the reuse policy of PID on Windows. Sending a Ctrl-C to a dead process might result in a Ctrl-C sent to the wrong process. The check is also implemented on Unix platforms and avoid unecessary waits. 2019-07-22 Nicolas Roche <roche@adacore.com> gcc/ada/ * terminals.c (__gnat_tty_waitpid): Support both blocking and not blocking mode. * libgnat/g-exptty.ads (Is_Process_Running): New function. * libgnat/g-exptty.adb (Close): Don't try to interrupt/terminate a process if it is already dead. From-SVN: r273672
2019-07-22[Ada] Incorrect values in conversion from fixed-point subtype with 'SmallEd Schonberg2-0/+18
This patch fixes incorrect computations involving a fixed-point subtype whose parent type has an aspect specification for 'Small. Executing the following: gnatmake -q conv ./conv must yield: 9000.000000 9.00000000000000E+03 9000.000000 9.00000000000000E+03 9.00000000000000E+03 9.00000000000000E+03 9.00000000000000E+03 9.00000000000000E+03 ---- with Text_IO; use Text_IO; procedure Conv is V_P : constant := 10.0 ** (-6); M_V : constant := 9000.0; N_V : constant := -9000.0; type V_T is delta V_P range N_V .. M_V with Small => V_P; subtype S_T is V_T range 0.0 .. M_V; function Convert (Input : in S_T) return Long_Float is begin Put_Line (Input'Img); Put_Line (Long_Float'Image (Long_Float (Input))); return Long_Float (Input); end Convert; begin declare Var_S : constant S_T := S_T'Last; Output : constant Long_Float := Convert (Var_S); begin Put_Line (Long_Float'Image (Convert (Var_S))); Put_Line (Long_Float'Image (Long_Float (Var_S))); Put_Line (Output'Img); end; Put_Line (Long_Float'Image (Long_Float (S_T'Last))); end Conv; 2019-07-22 Ed Schonberg <schonberg@adacore.com> gcc/ada/ * freeze.adb (Freeze_Fixed_Point_Type): When freezing a fixed-point subtype, check whether the parent type declarastion includes an aspect specification for the 'Small type attribute, and inherit the specified value. From-SVN: r273671
2019-07-22[Ada] Crash in C++ constructor without external and link nameJavier Miranda2-0/+20
The compiler blows up processing the declaration of a tagged type variable that has a C++ constructor without external or link name. After this patch the frontend reports an error. 2019-07-22 Javier Miranda <miranda@adacore.com> gcc/ada/ * freeze.adb (Freeze_Subprogram): Check that C++ constructors must have external or link name. gcc/testsuite/ * gnat.dg/cpp_constructor2.adb: New testcase. From-SVN: r273670
2019-07-22[Ada] Spurious warning about a useless assignmentEd Schonberg2-0/+27
This patch removes a spurious warning about a useless assignment, when a composite object is the target of an assignment and is an actual for an out parameter in a subsewuent call, and there is an intervening use of the object as the prefix of a selected component in an intervening operation. 2019-07-22 Ed Schonberg <schonberg@adacore.com> gcc/ada/ * sem_res.adb (Resolve_Selected_Component): If the prefix has a deferred reference, generate the correct reference now, to indicate that the previous assignment is used. This prevents spurious warnings on useless assignments when compiling with all warnings enabled. when there is a subsequent call in the same stqtement list, in which the prefix of the selected component is the actual for an out parameter. gcc/testsuite/ * gnat.dg/warn22.adb: New testcase. From-SVN: r273669
2019-07-22[Ada] Fix internal error on array slice in loop and Loop_InvariantEric Botcazou2-2/+10
This fixes an internal error caused by the presence of an Itype in a wrong scope. This Itype is created for an array slice present in the condition of a while loop whose body also contains a pragma Loop_Invariant, initially in the correct scope but then relocated into a function created for the pragma. 2019-07-22 Eric Botcazou <ebotcazou@adacore.com> gcc/ada/ * exp_attr.adb (Expand_Loop_Entry_Attribute): Copy the condition of a while loop instead of simply relocating it. gcc/testsuite/ * gnat.dg/loop_invariant1.adb, gnat.dg/loop_invariant1.ads: New testcase. From-SVN: r273668