decl.c (gnat_to_gnu_field): Do not set the alignment of the enclosing record type...
authorEric Botcazou <ebotcazou@adacore.com>
Thu, 14 Dec 2017 17:03:16 +0000 (17:03 +0000)
committerEric Botcazou <ebotcazou@gcc.gnu.org>
Thu, 14 Dec 2017 17:03:16 +0000 (17:03 +0000)
* gcc-interface/decl.c (gnat_to_gnu_field): Do not set the alignment
of the enclosing record type if it is not already set.

From-SVN: r255645

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

index 3ac3bfba6e5371e1d8634c8484e5d6aec37df6ee..c87f4a226921114c068526c42a2ee9c3e830ade3 100644 (file)
@@ -1,3 +1,8 @@
+2017-12-14  Eric Botcazou  <ebotcazou@adacore.com>
+
+       * gcc-interface/decl.c (gnat_to_gnu_field): Do not set the alignment
+       of the enclosing record type if it is not already set.
+
 2017-12-14  Eric Botcazou  <ebotcazou@adacore.com>
 
        * gcc-interface/gigi.h (pad_type_has_rm_size): Declare.
index f2da070ab0fba652411a3edeaad60fb84718a0ce..b014e687f6def579853fdd9dbcc61a2d10241cd0 100644 (file)
@@ -6890,7 +6890,8 @@ gnat_to_gnu_field (Entity_Id gnat_field, tree gnu_record_type, int packed,
        {
          const unsigned int type_align = TYPE_ALIGN (gnu_field_type);
 
-         if (TYPE_ALIGN (gnu_record_type) < type_align)
+         if (TYPE_ALIGN (gnu_record_type)
+             && TYPE_ALIGN (gnu_record_type) < type_align)
            SET_TYPE_ALIGN (gnu_record_type, type_align);
 
          /* If the position is not a multiple of the alignment of the type,
index 4fac0015fd2a700f7ae8a6d752d0daa807798962..f87fb48189977baca09b2df9e48c671c107bd8b4 100644 (file)
@@ -1,3 +1,7 @@
+2017-12-14  Eric Botcazou  <ebotcazou@adacore.com>
+
+       * gnat.dg/alignment13.adb: New test.
+
 2017-12-14  Jakub Jelinek  <jakub@redhat.com>
 
        PR lto/81406
diff --git a/gcc/testsuite/gnat.dg/alignment13.adb b/gcc/testsuite/gnat.dg/alignment13.adb
new file mode 100644 (file)
index 0000000..dd0b254
--- /dev/null
@@ -0,0 +1,21 @@
+-- { dg-do run }
+-- { dg-options "-gnatws" }
+
+procedure Alignment13 is
+
+  type Rec is record
+    I1 : aliased Short_Integer;
+    I2 : Integer;
+  end record;
+
+  for Rec use record
+    I1 at 0 range 0 .. 15;
+  end record;
+
+  R : Rec;
+
+begin
+  if R.I2'Bit_Position /= 32 then
+    raise Program_Error;
+  end if;
+end;