From 7029d96f5a2e98500707ca9110e5ca569e062d13 Mon Sep 17 00:00:00 2001 From: Ed Schonberg Date: Mon, 1 Jul 2019 13:37:37 +0000 Subject: [PATCH] [Ada] More permissive use of GNAT attribute Enum_Rep This patch allows the prefix of the attribute Enum_Rep to be an attribute referece (such as Enum_Type'First). A recent patch had restricted the prefix to be an object of a discrete type, which is incompatible with orevious usage. 2019-07-01 Ed Schonberg gcc/ada/ * sem_attr.adb (Analyze_Attribute, case Enum_Rep): Allow prefix of attribute to be an attribute reference of a discrete type. gcc/testsuite/ * gnat.dg/enum_rep.adb, gnat.dg/enum_rep.ads: New testcase. From-SVN: r272881 --- gcc/ada/ChangeLog | 5 +++++ gcc/ada/sem_attr.adb | 8 +++++--- gcc/testsuite/ChangeLog | 4 ++++ gcc/testsuite/gnat.dg/enum_rep.adb | 5 +++++ gcc/testsuite/gnat.dg/enum_rep.ads | 22 ++++++++++++++++++++++ 5 files changed, 41 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/gnat.dg/enum_rep.adb create mode 100644 gcc/testsuite/gnat.dg/enum_rep.ads diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog index a342b9853a9..63ed0d8a0a4 100644 --- a/gcc/ada/ChangeLog +++ b/gcc/ada/ChangeLog @@ -1,3 +1,8 @@ +2019-07-01 Ed Schonberg + + * sem_attr.adb (Analyze_Attribute, case Enum_Rep): Allow prefix + of attribute to be an attribute reference of a discrete type. + 2019-07-01 Eric Botcazou * sem_ch12.adb (Analyze_Subprogram_Instantiation): Move up diff --git a/gcc/ada/sem_attr.adb b/gcc/ada/sem_attr.adb index e966bf1ebf6..bdc76c3b200 100644 --- a/gcc/ada/sem_attr.adb +++ b/gcc/ada/sem_attr.adb @@ -3833,14 +3833,16 @@ package body Sem_Attr is Check_Discrete_Type; Resolve (E1, P_Base_Type); - -- X'Enum_Rep case. X must be an object or enumeration literal, and - -- it must be of a discrete type. + -- X'Enum_Rep case. X must be an object or enumeration literal + -- (including an attribute reference), and it must be of a + -- discrete type. elsif not ((Is_Object_Reference (P) or else (Is_Entity_Name (P) - and then Ekind (Entity (P)) = E_Enumeration_Literal)) + and then Ekind (Entity (P)) = E_Enumeration_Literal) + or else Nkind (P) = N_Attribute_Reference) and then Is_Discrete_Type (Etype (P))) then Error_Attr_P ("prefix of % attribute must be discrete object"); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 6b2e98326fe..8af44998ba6 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2019-07-01 Ed Schonberg + + * gnat.dg/enum_rep.adb, gnat.dg/enum_rep.ads: New testcase. + 2019-07-01 Ed Schonberg * gnat.dg/derived_type6.adb, gnat.dg/derived_type6.ads: New diff --git a/gcc/testsuite/gnat.dg/enum_rep.adb b/gcc/testsuite/gnat.dg/enum_rep.adb new file mode 100644 index 00000000000..4b13078cd5a --- /dev/null +++ b/gcc/testsuite/gnat.dg/enum_rep.adb @@ -0,0 +1,5 @@ +-- { dg-do compile } + +package body Enum_Rep is + procedure Foo is null; +end; diff --git a/gcc/testsuite/gnat.dg/enum_rep.ads b/gcc/testsuite/gnat.dg/enum_rep.ads new file mode 100644 index 00000000000..acf282c2da9 --- /dev/null +++ b/gcc/testsuite/gnat.dg/enum_rep.ads @@ -0,0 +1,22 @@ +with Interfaces; + +package Enum_Rep is + + type My_Type is range 00 .. 100; + + subtype My_Subtype2 is Interfaces.Unsigned_32 + range My_Type'First'Enum_Rep .. My_Type'Last'Enum_Rep; + + My_Type_First : constant My_Type := My_Type'First; + My_Type_Last : constant My_Type := My_Type'Last; + + subtype My_Subtype is Interfaces.Unsigned_32 + range My_Type_First'Enum_Rep .. My_Type_Last'Enum_Rep; + + subtype My_Subtype1 is Interfaces.Unsigned_32 + range My_Type'Enum_Rep (My_Type'First) .. + My_Type'Enum_Rep (MY_Type'Last); + + procedure Foo; + +end; -- 2.30.2