]> gcc.gnu.org Git - gcc.git/commitdiff
decl.c (gnat_to_gnu_entity): For a subtype with discriminant constraints...
authorOlivier Hainque <hainque@adacore.com>
Wed, 12 Sep 2007 10:49:56 +0000 (10:49 +0000)
committerOlivier Hainque <hainque@gcc.gnu.org>
Wed, 12 Sep 2007 10:49:56 +0000 (10:49 +0000)
2007-09-12  Olivier Hainque  <hainque@adacore.com>

ada/
* decl.c (gnat_to_gnu_entity) <E_Record_Subtype>: For a subtype
with discriminant constraints, generalize the code for BIT_FIELDs
to PACKED fields of constant size and propagate DECL_PACKED.

testsuite/
* gnat.dg/packed_subtype.adb: New test.

From-SVN: r128425

gcc/ada/ChangeLog
gcc/ada/decl.c
gcc/testsuite/ChangeLog
gcc/testsuite/gnat.dg/packed_subtype.adb [new file with mode: 0644]

index 6951351c64f0add8c87318f6a721c54c70f5018a..fca0cd0b9af5563455cf08bf564755a530ab997b 100644 (file)
@@ -1,3 +1,9 @@
+2007-09-12  Olivier Hainque  <hainque@adacore.com>
+
+       * decl.c (gnat_to_gnu_entity) <E_Record_Subtype>: For a subtype
+       with discriminant constraints, generalize the code for BIT_FIELDs
+       to PACKED fields of constant size and propagate DECL_PACKED.
+
 2007-09-11  Eric Botcazou  <ebotcazou@adacore.com>
 
        * decl.c (array_type_has_nonaliased_component): New predicate.
index 3d7c849fa713b0ff1315ad3538ceb74704397327..4b3edce40a9504119e12dcb181c5786779d4af54 100644 (file)
@@ -2762,9 +2762,14 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, int definition)
                        gnu_field_type = TREE_TYPE (gnu_old_field);
                      }
 
-                   /* If this was a bitfield, get the size from the old field.
-                      Also ensure the type can be placed into a bitfield.  */
-                   else if (DECL_BIT_FIELD (gnu_old_field))
+                   /* If the old field was packed and of constant size, we
+                      have to get the old size here, as it might differ from
+                      what the Etype conveys and the latter might overlap
+                      onto the following field.  Try to arrange the type for
+                      possible better packing along the way.  */
+                   else if (DECL_PACKED (gnu_old_field)
+                            && TREE_CODE (DECL_SIZE (gnu_old_field))
+                               == INTEGER_CST)
                      {
                        gnu_size = DECL_SIZE (gnu_old_field);
                        if (TYPE_MODE (gnu_field_type) == BLKmode
@@ -2789,7 +2794,7 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, int definition)
                    gnu_field
                      = create_field_decl
                        (DECL_NAME (gnu_old_field), gnu_field_type, gnu_type,
-                        0, gnu_size, gnu_new_pos,
+                        DECL_PACKED (gnu_old_field), gnu_size, gnu_new_pos,
                         !DECL_NONADDRESSABLE_P (gnu_old_field));
 
                    if (!TREE_CONSTANT (gnu_pos))
index ddddf5987cbee31d473c82563f07dde3880b634b..f87c6a95ff7ed23050a108cfe16ecad422d3e21b 100644 (file)
@@ -1,3 +1,7 @@
+2007-09-12  Olivier Hainque  <hainque@adacore.com>
+
+       * gnat.dg/packed_subtype.adb: New test.
+
 2007-09-12  Tobias Burnus  <burnus@net-b.de>
 
        PR fortran/33297
diff --git a/gcc/testsuite/gnat.dg/packed_subtype.adb b/gcc/testsuite/gnat.dg/packed_subtype.adb
new file mode 100644 (file)
index 0000000..925440a
--- /dev/null
@@ -0,0 +1,24 @@
+-- { dg-do run }
+
+procedure Packed_Subtype is
+
+   subtype Ubyte is Integer range 0 .. 255;
+   type Packet (Id : Ubyte) is record
+      A, B : Ubyte;
+   end record;
+   pragma Pack (Packet);
+
+   subtype My_Packet is Packet (Id => 1);
+
+   MP : My_Packet;
+begin
+   MP.A := 1;
+   MP.B := 2;
+
+   if MP.A /= 1 or else MP.B /= 2 then
+      raise Program_Error;
+   end if;
+end;
+
+
+
This page took 0.167946 seconds and 5 git commands to generate.