re PR ada/35186 (implicit assumption about alignment of DImode)
authorEric Botcazou <ebotcazou@adacore.com>
Thu, 6 Mar 2008 00:44:11 +0000 (00:44 +0000)
committerEric Botcazou <ebotcazou@gcc.gnu.org>
Thu, 6 Mar 2008 00:44:11 +0000 (00:44 +0000)
PR ada/35186
* decl.c (maybe_pad_type): Avoid padding an integral type when
bumping its alignment is sufficient.

From-SVN: r132963

gcc/ada/ChangeLog
gcc/ada/decl.c
gcc/testsuite/ChangeLog
gcc/testsuite/gnat.dg/specs/pack33.ads [new file with mode: 0644]

index d990e1005e835183b6f476a952736a98cf792c46..a67aae4019fc3c511891e5e07a957be5f4ab1779 100644 (file)
@@ -1,3 +1,9 @@
+2008-03-05  Eric Botcazou  <ebotcazou@adacore.com>
+
+       PR ada/35186
+       * decl.c (maybe_pad_type): Avoid padding an integral type when
+       bumping its alignment is sufficient.
+
 2008-03-02  Ralf Wildenhues  <Ralf.Wildenhues@gmx.de>
 
        * gnatfind.adb, gnatxref.adb: Fix argument parsing typos.
index 9945e4ed3e114aa7542bc7cbe35227d92dc38f83..237d1a4a282c400ae84da751dbc63c919659bd64 100644 (file)
@@ -5301,7 +5301,6 @@ maybe_pad_type (tree type, tree size, unsigned int align,
      off the padding, since we will either be returning the inner type
      or repadding it.  If no size or alignment is specified, use that of
      the original padded type.  */
-
   if (TREE_CODE (type) == RECORD_TYPE && TYPE_IS_PADDING_P (type))
     {
       if ((!size
@@ -5326,7 +5325,6 @@ maybe_pad_type (tree type, tree size, unsigned int align,
      is not done here (and is only valid for bitfields anyway), show the size
      isn't changing.  Likewise, clear the alignment if it isn't being
      changed.  Then return if we aren't doing anything.  */
-
   if (size
       && (operand_equal_p (size, orig_size, 0)
          || (TREE_CODE (orig_size) == INTEGER_CST
@@ -5339,6 +5337,19 @@ maybe_pad_type (tree type, tree size, unsigned int align,
   if (align == 0 && !size)
     return type;
 
+  /* If no size is specified and we have an integral type, and changing
+     the alignment won't change its size, return a copy of the type
+     with the specified alignment.  */
+  if (!size
+      && INTEGRAL_TYPE_P (type)
+      && host_integerp (orig_size, 1)
+      && (TREE_INT_CST_LOW (orig_size) % align) == 0)
+    {
+      type = copy_type (type);
+      TYPE_ALIGN (type) = align;
+      return type;
+    }
+
   /* We used to modify the record in place in some cases, but that could
      generate incorrect debugging information.  So make a new record
      type and name.  */
index 98246904330bf9daf1237b715e71a9a4a1fff0bb..cad174bba28f622518d184a3524ede93005f1eca 100644 (file)
@@ -1,3 +1,7 @@
+2008-03-05  Eric Botcazou  <ebotcazou@adacore.com>
+
+       * gnat.dg/specs/pack33.ads: New test.
+
 2008-03-05  Richard Guenther  <rguenther@suse.de>
 
        PR tree-optimization/35472
diff --git a/gcc/testsuite/gnat.dg/specs/pack33.ads b/gcc/testsuite/gnat.dg/specs/pack33.ads
new file mode 100644 (file)
index 0000000..d5255aa
--- /dev/null
@@ -0,0 +1,27 @@
+-- { dg-do compile }
+
+package Pack33 is
+
+   Bits : constant := 33;
+
+   type Bits_33 is mod 2 ** Bits;
+   for Bits_33'Size use Bits;
+
+   type Cluster is record
+      E0, E1, E2, E3, E4, E5, E6, E7 : Bits_33;
+   end record;
+
+   for Cluster use record
+      E0 at 0 range 0 * Bits .. 0 * Bits + Bits - 1;
+      E1 at 0 range 1 * Bits .. 1 * Bits + Bits - 1;
+      E2 at 0 range 2 * Bits .. 2 * Bits + Bits - 1;
+      E3 at 0 range 3 * Bits .. 3 * Bits + Bits - 1;
+      E4 at 0 range 4 * Bits .. 4 * Bits + Bits - 1;
+      E5 at 0 range 5 * Bits .. 5 * Bits + Bits - 1;
+      E6 at 0 range 6 * Bits .. 6 * Bits + Bits - 1;
+      E7 at 0 range 7 * Bits .. 7 * Bits + Bits - 1;
+   end record;
+
+   for Cluster'Size use Bits * 8;
+
+end Pack33;