]> gcc.gnu.org Git - gcc.git/commitdiff
re PR c++/21166 (g++ gives error on reference to packed structure elements)
authorNathan Sidwell <nathan@codesourcery.com>
Mon, 8 Aug 2005 14:22:35 +0000 (14:22 +0000)
committerNathan Sidwell <nathan@gcc.gnu.org>
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.

From-SVN: r102858

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 f6b156f127b085b3e31b2cbafceb810e1c0ad013..0996eced0df8f1dc61e0eb368a1d32ee6cec21c9 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 77dfc192775e51f736ec378e0f4579f5bb614d57..321a4d24ca440c5def80d0ab20eec3bc6a1fb542 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 7b171dac0bb8a199c53ce4f22eaf7144f96b416f..77cf6334b684150c1dcaad2f203c99b05a0d7aa5 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 35f23e8ccc00b284d26a47cf5bc4c45baddb2c8f..986c498e654ff79230c74efcd1b1a8bde7d7fd98 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
This page took 0.112399 seconds and 5 git commands to generate.