[Ada] Improper extension of bounds of fixed-point type
If the given Delta of an ordinariy fixed-point type is not a machine
number and there is no specified 'Small for the type, the compiler
chooses the actual bounds of the type using the nearest model numbers
that include the given bounds, but it is free to exclude those bounds if
a size clause restricts the number of bits to use for the type. This
patch fixes an error in the case where the bounds of the type can be
chosen to be larger than the bounds specified in the type declaration:
prior to this patch the lower bounds could be chosen to be one delta
smaller that the given bound, when that given bound was smaller than the
nearest machine number,
Compiling rep2.adb must yield:
rep2.adb:7:24:
warning: value not in range of type "Test_Type" defined at line 4
rep2.adb:7:24:
warning: "Constraint_Error" will be raised at run time
----
with Ada.Text_IO; use Ada.Text_IO;
procedure Rep2 is
type Test_Type is delta 0.1 range 0.1 .. 100.0 with Size => 16;
subtype Next_Type is Test_Type range 0.1 .. 100.0;
Item : Test_Type := 0.0; -- Why is this allowed?
Next : Next_Type with Address => Item'Address;
begin
Put_Line (Item'Img & " - " & Item'Valid'Img); -- Returns "0.0 - TRUE"
Put_Line (Next'Img & " - " & Next'Valid'Img); -- Returns "0.0 - FALSE"
end Rep2;
2018-11-14 Ed Schonberg <schonberg@adacore.com>
gcc/ada/
* freeze.adb (Freeze_Fixed_Point_Type): If the given low bound
of the type is less than the nearest model number, do not expand
the range of the type to include the model number below the
bound. Similar adjustment if the upper bound is larger than the
nearest model number.
From-SVN: r266116