]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR java/10145 (java and c++ disagree about class layout)
authorJason Merrill <jason@redhat.com>
Mon, 31 Mar 2003 20:25:11 +0000 (15:25 -0500)
committerJason Merrill <jason@gcc.gnu.org>
Mon, 31 Mar 2003 20:25:11 +0000 (15:25 -0500)
        PR java/10145
        * stor-layout.c (update_alignment_for_field): Respect
        DECL_USER_ALIGN for zero-length bitfields, too.
        * c-decl.c (finish_struct): Don't set DECL_ALIGN for normal
        fields.
        * cp/class.c (check_field_decl): Don't set DECL_ALIGN.

From-SVN: r65103

gcc/ChangeLog
gcc/c-decl.c
gcc/cp/ChangeLog
gcc/cp/class.c
gcc/stor-layout.c
gcc/testsuite/gcc.dg/align-1.c [new file with mode: 0644]

index 076192bc5d30ad11049b5006647fe55ba73a1526..545b048b9331a38e31f31b06231f0f7933b16488 100644 (file)
@@ -1,3 +1,11 @@
+2003-03-31  Jason Merrill  <jason@redhat.com>
+
+       PR java/10145
+       * stor-layout.c (update_alignment_for_field): Respect
+       DECL_USER_ALIGN for zero-length bitfields, too.
+       * c-decl.c (finish_struct): Don't set DECL_ALIGN for normal
+       fields.
+
 2003-03-31  Matt Austern  <austern@apple.com>
 
        * cpppch.c (struct cpp_savedstate): Add defs and n_defs members.
index d52823bde97b3e74eeb71bbc04f13d20ffd2f67c..c9dd711f162bd8427693fb6b607d3a0f775abba8 100644 (file)
@@ -5257,18 +5257,6 @@ finish_struct (t, fieldlist, attributes)
            }
        }
 
-      else if (TREE_TYPE (x) != error_mark_node)
-       {
-         unsigned int min_align = (DECL_PACKED (x) ? BITS_PER_UNIT
-                                   : TYPE_ALIGN (TREE_TYPE (x)));
-
-         /* Non-bit-fields are aligned for their type, except packed
-            fields which require only BITS_PER_UNIT alignment.  */
-         DECL_ALIGN (x) = MAX (DECL_ALIGN (x), min_align);
-         if (! DECL_PACKED (x))
-           DECL_USER_ALIGN (x) |= TYPE_USER_ALIGN (TREE_TYPE (x));
-       }
-
       DECL_INITIAL (x) = 0;
 
       /* Detect flexible array member in an invalid context.  */
index 93df69d34a70fa7632f924828f84deb563d5f320..6eb6d818305e2e7c2cc362ec56d36ebf5a539969 100644 (file)
@@ -1,3 +1,8 @@
+2003-03-31  Jason Merrill  <jason@redhat.com>
+
+       PR java/10145
+       * class.c (check_field_decl): Don't set DECL_ALIGN.
+
 2003-03-30  Mark Mitchell  <mark@codesourcery.com>
 
        PR c++/7647
index e899c5714068dc3fd0de2bd584ff4f20cc0db42e..01d4dd215ed6ac0085b7a9688c75d93722db7be1 100644 (file)
@@ -3057,15 +3057,6 @@ check_field_decl (tree field,
        cp_error_at ("multiple fields in union `%T' initialized");
       *any_default_members = 1;
     }
-
-  /* Non-bit-fields are aligned for their type, except packed fields
-     which require only BITS_PER_UNIT alignment.  */
-  DECL_ALIGN (field) = MAX (DECL_ALIGN (field), 
-                           (DECL_PACKED (field) 
-                            ? BITS_PER_UNIT
-                            : TYPE_ALIGN (TREE_TYPE (field))));
-  if (! DECL_PACKED (field))
-    DECL_USER_ALIGN (field) |= TYPE_USER_ALIGN (TREE_TYPE (field));
 }
 
 /* Check the data members (both static and non-static), class-scoped
index 6caaf5f70deb12a97a82a389253ab86bc313b3e2..af02cad7c28e7bfc18cf0bd08bc19aa3e5ec6a70 100644 (file)
@@ -746,7 +746,8 @@ update_alignment_for_field (rli, field, known_align)
     {
       /* A zero-length bit-field affects the alignment of the next
         field.  */
-      if (!DECL_PACKED (field) && integer_zerop (DECL_SIZE (field)))
+      if (!DECL_PACKED (field) && !user_align
+         && integer_zerop (DECL_SIZE (field)))
        {
          desired_align = TYPE_ALIGN (type);
 #ifdef ADJUST_FIELD_ALIGN
diff --git a/gcc/testsuite/gcc.dg/align-1.c b/gcc/testsuite/gcc.dg/align-1.c
new file mode 100644 (file)
index 0000000..cb6dcab
--- /dev/null
@@ -0,0 +1,24 @@
+// PR java/10145
+// Test that requesting an alignment of 1 does not increase the alignment
+// of a long long field.
+
+// { dg-do run }
+
+struct A
+{
+  char c;
+  long long i;
+};
+
+struct B
+{
+  char c;
+  long long i __attribute ((__aligned__ (1)));
+};
+
+int main ()
+{
+  if (sizeof (struct A) != sizeof (struct B))
+    abort ();
+  return 0;
+}