]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
[Ada] Cope with scalar subtypes that have a non-scalar basetype.
authorSteve Baird <baird@adacore.com>
Wed, 10 Aug 2022 21:04:29 +0000 (14:04 -0700)
committerMarc Poulhiès <poulhies@adacore.com>
Tue, 6 Sep 2022 07:14:21 +0000 (09:14 +0200)
In some cases, the compiler builds a subtype entity Typ such that
Is_Scalar (Typ) is True and Is_Scalar (Base_Type (Typ)) is False.
This comes up in some cases involving a subtype of a private type,
where the full view of the private type is a scalar type. In such a
situation, it may also be the case that Is_Enumeration_Type (Typ) is True
and Is_Enumeration_Type (Base_Type (Typ)) is False. Some code incorrectly
assumed that if a subtype is known to be a scalar (respectively, enumeration)
type, then the same must be true of the base type of that subtype. Fix that
code to handle the case where that assumption does not hold.

gcc/ada/

* exp_attr.adb
(Attribute_Valid): Ensure that PBtyp is initialized to a value for
which Is_Scalar_Type is True.
* checks.adb
(Determine_Range): Call Implemention_Base_Type instead of
Base_Type in order to ensure that result is suitable for passing
to Enum_Pos_To_Rep.

gcc/ada/checks.adb
gcc/ada/exp_attr.adb

index 22577c8fe583170445d89c2865574152e1674573..26d5a4e220e31b050a3198e7086c82e52c8db205 100644 (file)
@@ -5094,7 +5094,8 @@ package body Checks is
         --  Don't deal with enumerated types with non-standard representation
 
         or else (Is_Enumeration_Type (Typ)
-                   and then Present (Enum_Pos_To_Rep (Base_Type (Typ))))
+                   and then Present (Enum_Pos_To_Rep
+                                       (Implementation_Base_Type (Typ))))
 
         --  Ignore type for which an error has been posted, since range in
         --  this case may well be a bogosity deriving from the error. Also
index 33eec37e3b77d87d9f6e937d0838e5701430d753..c4187c9f5d6318839647f6b1397890d46b09cc6a 100644 (file)
@@ -7103,7 +7103,10 @@ package body Exp_Attr is
       --  See separate sections below for the generated code in each case.
 
       when Attribute_Valid => Valid : declare
-         PBtyp : Entity_Id := Base_Type (Validated_View (Ptyp));
+         PBtyp : Entity_Id := Implementation_Base_Type (Validated_View (Ptyp));
+         pragma Assert (Is_Scalar_Type (PBtyp)
+                          or else Serious_Errors_Detected > 0);
+
          --  The scalar base type, looking through private types
 
          Save_Validity_Checks_On : constant Boolean := Validity_Checks_On;