aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNathan Sidwell <nathan@codesourcery.com>2005-08-08 14:22:35 +0000
committerNathan Sidwell <nathan@gcc.gnu.org>2005-08-08 14:22:35 +0000
commitf303a996311673f8c9178f6593bf4c804077a8ec (patch)
tree2061e9e62bc833d5825ee342b6f3929525652c9e
parent4de997d1376a22a139c43ab64ab0c1482b5b4487 (diff)
downloadgcc-f303a996311673f8c9178f6593bf4c804077a8ec.zip
gcc-f303a996311673f8c9178f6593bf4c804077a8ec.tar.gz
gcc-f303a996311673f8c9178f6593bf4c804077a8ec.tar.bz2
re PR c++/21166 (g++ gives error on reference to packed structure elements)
.: 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
-rw-r--r--gcc/ChangeLog5
-rw-r--r--gcc/stor-layout.c11
-rw-r--r--gcc/testsuite/ChangeLog6
-rw-r--r--gcc/testsuite/g++.dg/ext/packed9.C20
-rw-r--r--gcc/testsuite/g++.dg/other/crash-4.C2
5 files changed, 44 insertions, 0 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index f6b156f..0996ece 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -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.
diff --git a/gcc/stor-layout.c b/gcc/stor-layout.c
index 77dfc19..321a4d2 100644
--- a/gcc/stor-layout.c
+++ b/gcc/stor-layout.c
@@ -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)
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 7b171da..77cf6334 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -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
index 0000000..ba5d4ab
--- /dev/null
+++ b/gcc/testsuite/g++.dg/ext/packed9.C
@@ -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;
+}
diff --git a/gcc/testsuite/g++.dg/other/crash-4.C b/gcc/testsuite/g++.dg/other/crash-4.C
index 35f23e8..986c498 100644
--- a/gcc/testsuite/g++.dg/other/crash-4.C
+++ b/gcc/testsuite/g++.dg/other/crash-4.C
@@ -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