]> gcc.gnu.org Git - gcc.git/commitdiff
decl.c (gnat_to_gnu_entity): Do not pack the field of the record type made for a...
authorEric Botcazou <ebotcazou@gcc.gnu.org>
Sun, 6 Jan 2013 11:58:36 +0000 (11:58 +0000)
committerEric Botcazou <ebotcazou@gcc.gnu.org>
Sun, 6 Jan 2013 11:58:36 +0000 (11:58 +0000)
* gcc-interface/decl.c (gnat_to_gnu_entity) <discrete_type>: Do not
pack the field of the record type made for a misaligned type.

From-SVN: r194942

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

index 1ade2a0baea706380e5ab4cb616ed18724dfcdfe..1d3dcd3b0f1a253caa4e140eec45ca2ab987c2c1 100644 (file)
@@ -1,3 +1,8 @@
+2013-01-06  Eric Botcazou  <ebotcazou@adacore.com>
+
+       * gcc-interface/decl.c (gnat_to_gnu_entity) <discrete_type>: Do not
+       pack the field of the record type made for a misaligned type.
+
 2013-01-06  Eric Botcazou  <ebotcazou@adacore.com>
 
        * gcc-interface/decl.c (annotate_value) <COMPONENT_REF>: Be prepared
@@ -12,7 +17,7 @@
        * einfo.adb, atree.adb: Enlarge entities to make 63 more flags, 6 more
        fields.
 
-2013-01-04  Joel Brobecker  <brobecker@adacore.com brobecker>
+2013-01-04  Joel Brobecker  <brobecker@adacore.com>
 
        * gnat_ugn.texi: Fix typo.
 
index f7db364c641105350aa688a8faeef843845a83a6..f312c7d4cbea2f0c49d0d45bb833a2ddaf73c10b 100644 (file)
@@ -1887,8 +1887,10 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, int definition)
        }
 
       /* If the type we are dealing with has got a smaller alignment than the
-        natural one, we need to wrap it up in a record type and under-align
-        the latter.  We reuse the padding machinery for this purpose.  */
+        natural one, we need to wrap it up in a record type and misalign the
+        latter; we reuse the padding machinery for this purpose.  Note that,
+        even if the record type is marked as packed because of misalignment,
+        we don't pack the field so as to give it the size of the type.  */
       else if (align > 0)
        {
          tree gnu_field_type, gnu_field;
@@ -1918,7 +1920,8 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, int definition)
             a bitfield.  */
          gnu_field
            = create_field_decl (get_identifier ("F"), gnu_field_type,
-                                gnu_type, NULL_TREE, bitsize_zero_node, 1, 0);
+                                gnu_type, TYPE_SIZE (gnu_field_type),
+                                bitsize_zero_node, 0, 0);
 
          finish_record_type (gnu_type, gnu_field, 2, debug_info_p);
          compute_record_mode (gnu_type);
index f16dc1929a45e085cec1db1c948b1bcec968fd78..1c91f462e3727103bb779d84a087551e97c83da5 100644 (file)
@@ -1,3 +1,7 @@
+2013-01-06  Eric Botcazou  <ebotcazou@adacore.com>
+
+       * gnat.dg/alignment10.adb: New test.
+
 2013-01-05  Steven G. Kargl  <kargl@gcc.gnu.org>
            Mikael Morin  <mikael@gcc.gnu.org>
 
diff --git a/gcc/testsuite/gnat.dg/alignment10.adb b/gcc/testsuite/gnat.dg/alignment10.adb
new file mode 100644 (file)
index 0000000..61779f1
--- /dev/null
@@ -0,0 +1,20 @@
+-- { dg-do run }\r
+\r
+procedure Alignment10 is\r
+\r
+   type Short_T is mod 2 ** 16;\r
+   for Short_T'Size use 16;\r
+   for Short_T'Alignment use 1;\r
+\r
+   subtype Short_Sub_T is Short_T range 1000 .. 1005;\r
+\r
+   A : aliased Short_T := 1000;\r
+   B : Short_Sub_T;\r
+   for B'Address use A'Address;\r
+   pragma Import (Ada, B);\r
+\r
+begin\r
+  if B /= 1000 then\r
+    raise Program_Error;\r
+  end if;\r
+end;\r
This page took 0.079114 seconds and 5 git commands to generate.