[PATCH] ada: Warn if enumeration representation clause is not honored in record
Samuel Tardieu
sam@rfc1149.net
Wed Jun 11 13:45:00 GMT 2008
If an enumeration type E has a representation clause, GNAT will ignore
it silently if it is used as a component type in a record which has a
representation clause. This patch adds a warning in this case. The attached
test program gives:
12. A1 at 0 range 0 .. 0;
|
>>> warning: component representation will be biased
Bootstrapped and tested on i686-pc-linux-gnu.
Ok for trunk?
gcc/ada/
* sem_ch13.adb (Analyze_Record_Representation_Clause): Warn if
enumeration representation cannot be honored in record.
gcc/testsuite/
* gnat.dg/specs/biased_enum.ads: New.
---
gcc/ada/sem_ch13.adb | 8 ++++++++
gcc/testsuite/gnat.dg/specs/biased_enum.ads | 17 +++++++++++++++++
2 files changed, 25 insertions(+), 0 deletions(-)
create mode 100644 gcc/testsuite/gnat.dg/specs/biased_enum.ads
diff --git a/gcc/ada/sem_ch13.adb b/gcc/ada/sem_ch13.adb
index f72ffff..8b5e555 100644
--- a/gcc/ada/sem_ch13.adb
+++ b/gcc/ada/sem_ch13.adb
@@ -2491,6 +2491,14 @@ package body Sem_Ch13 is
Set_Has_Biased_Representation (Comp, Biased);
+ if Biased
+ and then Has_Enumeration_Rep_Clause (Etype (Comp))
+ then
+ Error_Msg_N
+ ("?component representation will be biased",
+ CC);
+ end if;
+
if Present (Ocomp) then
Set_Component_Clause (Ocomp, CC);
Set_Component_Bit_Offset (Ocomp, Fbit);
diff --git a/gcc/testsuite/gnat.dg/specs/biased_enum.ads b/gcc/testsuite/gnat.dg/specs/biased_enum.ads
new file mode 100644
index 0000000..2088336
--- /dev/null
+++ b/gcc/testsuite/gnat.dg/specs/biased_enum.ads
@@ -0,0 +1,17 @@
+-- { dg-do "compile" }
+package Biased_Enum is
+ type ENUM_T is (ONE, TWO);
+ for ENUM_T use (ONE => 1, TWO => 2);
+ for ENUM_T'Size use 2;
+
+ type RECORD_T is record
+ A1 : ENUM_T;
+ A2 : ENUM_T;
+ end record;
+ for RECORD_T use record
+ A1 at 0 range 0 .. 0; -- { dg-warning "will be biased" }
+ A2 at 1 range 0 .. 7;
+ end record;
+ for RECORD_T'Size use 2 * 8;
+
+end Biased_Enum;
--
1.5.6.rc2.304.ga7c8
More information about the Gcc-patches
mailing list