aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEd Schonberg <schonberg@adacore.com>2008-05-20 14:46:54 +0200
committerArnaud Charlet <charlet@gcc.gnu.org>2008-05-20 14:46:54 +0200
commitd677afa9583e31ef0eae98998b29f884fd409d72 (patch)
treeb91e40169240cbd8a69c0da15f7565e995ff88c7
parent7052f54e6286b1e9e87e0f2eaf827dec15f3f2c2 (diff)
downloadgcc-d677afa9583e31ef0eae98998b29f884fd409d72.zip
gcc-d677afa9583e31ef0eae98998b29f884fd409d72.tar.gz
gcc-d677afa9583e31ef0eae98998b29f884fd409d72.tar.bz2
2008-05-20 Ed Schonberg <schonberg@adacore.com>
* freeze.adb (Freeze_Enumeration_Type): For a subtype that inherits a foreign convention from its base type, do not set the type to that of integer, because it may inherit a size clause. Warn on a size clause with a size different from that of Integer, if the type has convention C. From-SVN: r135628
-rw-r--r--gcc/ada/freeze.adb24
1 files changed, 24 insertions, 0 deletions
diff --git a/gcc/ada/freeze.adb b/gcc/ada/freeze.adb
index f2bd7b1..21b1ad5 100644
--- a/gcc/ada/freeze.adb
+++ b/gcc/ada/freeze.adb
@@ -3828,12 +3828,36 @@ package body Freeze is
procedure Freeze_Enumeration_Type (Typ : Entity_Id) is
begin
+ -- By default, if no size clause is present, an enumeration type with
+ -- Convention C is assumed to interface to a C enum, and has integer
+ -- size. This applies to types. For subtypes, verify that its base
+ -- type has no size clause either.
+
if Has_Foreign_Convention (Typ)
and then not Has_Size_Clause (Typ)
+ and then not Has_Size_Clause (Base_Type (Typ))
and then Esize (Typ) < Standard_Integer_Size
then
Init_Esize (Typ, Standard_Integer_Size);
+
else
+ -- If the enumeration type interfaces to C, and it has a size clause
+ -- that specifies less than int size, it warrants a warning. The
+ -- user may intend the C type to be an enum or a char, so this is
+ -- not by itself an error that the Ada compiler can detect, but it
+ -- it is a worth a heads-up. For Boolean and Character types we
+ -- assume that the programmer has the proper C type in mind.
+
+ if Convention (Typ) = Convention_C
+ and then Has_Size_Clause (Typ)
+ and then Esize (Typ) /= Esize (Standard_Integer)
+ and then not Is_Boolean_Type (Typ)
+ and then not Is_Character_Type (Typ)
+ then
+ Error_Msg_N
+ ("C enum types have the size of a C int?", Size_Clause (Typ));
+ end if;
+
Adjust_Esize_For_Alignment (Typ);
end if;
end Freeze_Enumeration_Type;