aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEd Schonberg <schonberg@adacore.com>2019-07-01 13:37:37 +0000
committerPierre-Marie de Rodat <pmderodat@gcc.gnu.org>2019-07-01 13:37:37 +0000
commit7029d96f5a2e98500707ca9110e5ca569e062d13 (patch)
tree323960aced50decdff1836f6ea1433a9e077e220
parent8b9aa1a98fd194ab8fad3f54e232172fd857f077 (diff)
downloadgcc-7029d96f5a2e98500707ca9110e5ca569e062d13.zip
gcc-7029d96f5a2e98500707ca9110e5ca569e062d13.tar.gz
gcc-7029d96f5a2e98500707ca9110e5ca569e062d13.tar.bz2
[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 <schonberg@adacore.com> 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
-rw-r--r--gcc/ada/ChangeLog5
-rw-r--r--gcc/ada/sem_attr.adb8
-rw-r--r--gcc/testsuite/ChangeLog4
-rw-r--r--gcc/testsuite/gnat.dg/enum_rep.adb5
-rw-r--r--gcc/testsuite/gnat.dg/enum_rep.ads22
5 files changed, 41 insertions, 3 deletions
diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog
index a342b98..63ed0d8 100644
--- a/gcc/ada/ChangeLog
+++ b/gcc/ada/ChangeLog
@@ -1,3 +1,8 @@
+2019-07-01 Ed Schonberg <schonberg@adacore.com>
+
+ * 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 <ebotcazou@adacore.com>
* sem_ch12.adb (Analyze_Subprogram_Instantiation): Move up
diff --git a/gcc/ada/sem_attr.adb b/gcc/ada/sem_attr.adb
index e966bf1..bdc76c3 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 6b2e983..8af4499 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,5 +1,9 @@
2019-07-01 Ed Schonberg <schonberg@adacore.com>
+ * gnat.dg/enum_rep.adb, gnat.dg/enum_rep.ads: New testcase.
+
+2019-07-01 Ed Schonberg <schonberg@adacore.com>
+
* gnat.dg/derived_type6.adb, gnat.dg/derived_type6.ads: New
testcase.
diff --git a/gcc/testsuite/gnat.dg/enum_rep.adb b/gcc/testsuite/gnat.dg/enum_rep.adb
new file mode 100644
index 0000000..4b13078
--- /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 0000000..acf282c
--- /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;