.:
authornathan <nathan@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 8 Aug 2005 14:22:35 +0000 (14:22 +0000)
committernathan <nathan@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 8 Aug 2005 14:22:35 +0000 (14:22 +0000)
PR c++/21166
* stor-layout.c (finalize_type_size): Undo DECL_PACKED when possible.
testsuite:
PR c++/21166
* g++.dg/other/crash-4.C: Adjust
* g++/dg/ext/packed9.C: New.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@102858 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/ChangeLog
gcc/stor-layout.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/ext/packed9.C [new file with mode: 0644]
gcc/testsuite/g++.dg/other/crash-4.C

index f6b156f..0996ece 100644 (file)
@@ -1,3 +1,8 @@
+2005-08-08  Nathan Sidwell  <nathan@codesourcery.com>
+
+       PR c++/21166
+       * stor-layout.c (finalize_type_size): Undo DECL_PACKED when possible.
+
 2005-08-07  James A. Morrison  <phython@gcc.gnu.org>
 
        * tree-vrp.c (simplify_div_or_mod_using_range): Use build2.
index 77dfc19..321a4d2 100644 (file)
@@ -1477,6 +1477,8 @@ finalize_type_size (tree type)
 void
 finish_record_layout (record_layout_info rli, int free_p)
 {
+  tree field;
+  
   /* Compute the final size.  */
   finalize_record_size (rli);
 
@@ -1486,6 +1488,15 @@ finish_record_layout (record_layout_info rli, int free_p)
   /* Perform any last tweaks to the TYPE_SIZE, etc.  */
   finalize_type_size (rli->t);
 
+  /* We might be able to clear DECL_PACKED on any members that happen
+     to be suitably aligned (not forgetting the alignment of the type
+     itself).  */
+  for (field = TYPE_FIELDS (rli->t); field; field = TREE_CHAIN (field))
+    if (TREE_CODE (field) == FIELD_DECL && DECL_PACKED (field)
+       && DECL_OFFSET_ALIGN (field) >= TYPE_ALIGN (TREE_TYPE (field))
+       && TYPE_ALIGN (rli->t) >= TYPE_ALIGN (TREE_TYPE (field)))
+      DECL_PACKED (field) = 0;
+  
   /* Lay out any static members.  This is done now because their type
      may use the record's type.  */
   while (rli->pending_statics)
index 7b171da..77cf633 100644 (file)
@@ -1,3 +1,9 @@
+2005-08-08  Nathan Sidwell  <nathan@codesourcery.com>
+
+       PR c++/21166
+       * g++.dg/other/crash-4.C: Adjust
+       * g++/dg/ext/packed9.C: New.
+
 2005-08-08  Richard Sandiford  <richard@codesourcery.com>
 
        PR middle-end/21964
diff --git a/gcc/testsuite/g++.dg/ext/packed9.C b/gcc/testsuite/g++.dg/ext/packed9.C
new file mode 100644 (file)
index 0000000..ba5d4ab
--- /dev/null
@@ -0,0 +1,20 @@
+// Copyright (C) 2005 Free Software Foundation, Inc.
+// Contributed by Nathan Sidwell 26 Apr 2005 <nathan@codesourcery.com>
+
+// DR21166. unnecessary error on packed char
+
+struct s1 {
+        char    c1;
+} __attribute__((packed));
+
+char&
+f(struct s1 *s)
+{
+        return s->c1;
+}
+
+char *
+g(struct s1 *s)
+{
+        return &s->c1;
+}
index 35f23e8..986c498 100644 (file)
@@ -6,10 +6,12 @@
 
 struct a
 {
+  int m;
   a(const a&);
 };
 struct b
 { // { dg-error "cannot bind packed field" }
+  char c;
   a aa __attribute__((packed));
 };
 struct c