aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorGary Dismukes <dismukes@adacore.com>2022-11-02 19:02:34 -0400
committerMarc Poulhiès <poulhies@adacore.com>2022-11-14 14:46:50 +0100
commit90b9052e0b5df49d6c298c4706978135d2af2a86 (patch)
tree3b84aec76240802c476f3ae5e78994ac1ea61762 /gcc
parent0a2304a04925e43a50a345fb6a0b0c8ba180a973 (diff)
downloadgcc-90b9052e0b5df49d6c298c4706978135d2af2a86.zip
gcc-90b9052e0b5df49d6c298c4706978135d2af2a86.tar.gz
gcc-90b9052e0b5df49d6c298c4706978135d2af2a86.tar.bz2
ada: Crash on applying 'Pos to expression of a type derived from a formal type
The compiler crashes when trying to do a static check for a range violation in a type conversion of a Pos attribute applied to a prefix of a type derived from a generic formal discrete type. This optimization was suppressed in the case of formal types, because the upper bound may not be known, but it also needs to be suppressed for types derived from formal types. gcc/ada/ * checks.adb (Apply_Type_Conversion_Checks): Apply Root_Type to the type of the prefix of a Pos attribute when checking whether the type is a formal discrete type.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ada/checks.adb7
1 files changed, 4 insertions, 3 deletions
diff --git a/gcc/ada/checks.adb b/gcc/ada/checks.adb
index 9687667..2a45f4d 100644
--- a/gcc/ada/checks.adb
+++ b/gcc/ada/checks.adb
@@ -3789,13 +3789,14 @@ package body Checks is
-- Universal_Integer. So in numeric conversions it is usually
-- within range of the target integer type. Use the static
-- bounds of the base types to check. Disable this optimization
- -- in case of a generic formal discrete type, because we don't
- -- necessarily know the upper bound yet.
+ -- in case of a descendant of a generic formal discrete type,
+ -- because we don't necessarily know the upper bound yet.
if Nkind (Expr) = N_Attribute_Reference
and then Attribute_Name (Expr) = Name_Pos
and then Is_Enumeration_Type (Etype (Prefix (Expr)))
- and then not Is_Generic_Type (Etype (Prefix (Expr)))
+ and then
+ not Is_Generic_Type (Root_Type (Etype (Prefix (Expr))))
and then Is_Integer_Type (Target_Type)
then
declare