* [Ada] Crash on subtype of fixed-point type
@ 2020-10-15 9:40 Pierre-Marie de Rodat
0 siblings, 0 replies; only message in thread
From: Pierre-Marie de Rodat @ 2020-10-15 9:40 UTC (permalink / raw)
To: gcc-patches; +Cc: Ed Schonberg
[-- Attachment #1: Type: text/plain, Size: 679 bytes --]
This patch fixes a compiler abort on a subtype of a fixed-point type
with a 'Small smaller than one. The bounds of a declared subtype of a
fixed-point type where rescaled twice, leading to meaningless values
(constraint-violating) for those bounds.
Tested on x86_64-pc-linux-gnu, committed on trunk
gcc/ada/
* freeze.adb (Freeze_Fixed_Point_Type): Do not scale the bounds
of a declared subtype using the 'Small of the type; this is
done during resolution of the bound itself, unlike what is done
for the bounds of the base type, which are used to determine its
required size. Previous code performed this scaling twice,
leading to meaningless values for such a subtype.
[-- Attachment #2: patch.diff --]
[-- Type: text/x-diff, Size: 1760 bytes --]
diff --git a/gcc/ada/freeze.adb b/gcc/ada/freeze.adb
--- a/gcc/ada/freeze.adb
+++ b/gcc/ada/freeze.adb
@@ -8494,21 +8494,21 @@ package body Freeze is
Set_Analyzed (Lo, False);
Analyze (Lo);
- -- Resolve with universal fixed if the base type, and the base type if
- -- it is a subtype. Note we can't resolve the base type with itself,
- -- that would be a reference before definition.
+ -- Resolve with universal fixed if the base type, and with the base
+ -- type if we are freezing a subtype. Note we can't resolve the base
+ -- type with itself, that would be a reference before definition.
+ -- The resolution of the bounds of a subtype, if they are given by real
+ -- literals, includes the setting of the Corresponding_Integer_Value,
+ -- as for other literals of a fixed-point type.
if Typ = Btyp then
Resolve (Lo, Universal_Fixed);
+ Set_Corresponding_Integer_Value
+ (Lo, UR_To_Uint (Realval (Lo) / Small));
else
Resolve (Lo, Btyp);
end if;
- -- Set corresponding integer value for bound
-
- Set_Corresponding_Integer_Value
- (Lo, UR_To_Uint (Realval (Lo) / Small));
-
-- Similar processing for high bound
Set_Etype (Hi, Empty);
@@ -8517,13 +8517,12 @@ package body Freeze is
if Typ = Btyp then
Resolve (Hi, Universal_Fixed);
+ Set_Corresponding_Integer_Value
+ (Hi, UR_To_Uint (Realval (Hi) / Small));
else
Resolve (Hi, Btyp);
end if;
- Set_Corresponding_Integer_Value
- (Hi, UR_To_Uint (Realval (Hi) / Small));
-
-- Set type of range to correspond to bounds
Set_Etype (Rng, Etype (Lo));
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2020-10-15 9:40 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-15 9:40 [Ada] Crash on subtype of fixed-point type Pierre-Marie de Rodat
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).