stor-layout.c (layout_decl): Don't misalign field of variable size for packed record.
authorRichard Kenner <kenner@vlsi1.ultra.nyu.edu>
Sat, 29 Dec 2001 21:00:51 +0000 (21:00 +0000)
committerRichard Kenner <kenner@gcc.gnu.org>
Sat, 29 Dec 2001 21:00:51 +0000 (16:00 -0500)
* stor-layout.c (layout_decl): Don't misalign field of variable size
for packed record.

From-SVN: r48384

gcc/ChangeLog
gcc/stor-layout.c

index e4f8b813a9ca371a1d1ed9d7fda519a2a3ce2d83..5ba989d534f718aeee600636d5f5e99ab5563266 100644 (file)
@@ -1,5 +1,8 @@
 Sat Dec 29 15:48:54 2001  Richard Kenner  <kenner@vlsi1.ultra.nyu.edu>
 
+       * stor-layout.c (layout_decl): Don't misalign field of variable size
+       for packed record.
+
        * dwarf2out.c (compute_section_prefix): Avoid cast warning.
        (gen_decl_die): Only check DECL_IGNORED_P on decls.
        (dwarf2out_decl): Check for DECL_IGNORED_P only when needed.
index f657463bfd010d36bdad14368cceb62a505c6fc6..fe9ed2c9ca8537a159c278e39b34792ba7fd0092 100644 (file)
@@ -389,7 +389,15 @@ layout_decl (decl, known_align)
       DECL_BIT_FIELD_TYPE (decl) = DECL_BIT_FIELD (decl) ? type : 0;
       if (maximum_field_alignment != 0)
        DECL_ALIGN (decl) = MIN (DECL_ALIGN (decl), maximum_field_alignment);
-      else if (DECL_PACKED (decl))
+
+      /* If the field is of variable size, we can't misalign it since we
+        have no way to make a temporary to align the result.  But this
+        isn't an issue if the decl is not addressable.  Likewise if it
+        is of unknown size.  */
+      else if (DECL_PACKED (decl)
+              && (DECL_NONADDRESSABLE_P (decl)
+                  || DECL_SIZE_UNIT (decl) == 0
+                  || TREE_CODE (DECL_SIZE_UNIT (decl)) == INTEGER_CST))
        {
          DECL_ALIGN (decl) = MIN (DECL_ALIGN (decl), BITS_PER_UNIT);
          DECL_USER_ALIGN (decl) = 0;