summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormmitchel <mmitchel@138bc75d-0d04-0410-961f-82ee72b054a4>2003-01-07 01:33:54 +0000
committermmitchel <mmitchel@138bc75d-0d04-0410-961f-82ee72b054a4>2003-01-07 01:33:54 +0000
commit46b3cd1047523f3a90cc2f5cd8233883f9ba7329 (patch)
treebd8a925d8ba1a1525c5ec0f2f4495c72b4db643f
parenta36057b0935fea999a1c597eec45e103126132b9 (diff)
downloadppe42-gcc-46b3cd1047523f3a90cc2f5cd8233883f9ba7329.tar.gz
ppe42-gcc-46b3cd1047523f3a90cc2f5cd8233883f9ba7329.zip
* class.c (layout_class_type): Correct handling of unnamed
bitfields wider than their types. * testsuite/g++.dg/abi/bitfield9.C: New test. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@60966 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r--gcc/cp/ChangeLog3
-rw-r--r--gcc/cp/class.c17
-rw-r--r--gcc/testsuite/ChangeLog2
-rw-r--r--gcc/testsuite/g++.dg/abi/bitfield9.C11
4 files changed, 32 insertions, 1 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 70bc9ee33de..9522ae6f168 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,5 +1,8 @@
2003-01-06 Mark Mitchell <mark@codesourcery.com>
+ * class.c (layout_class_type): Correct handling of unnamed
+ bitfields wider than their types.
+
PR c++/9189
* parser.c (cp_parser): Remove default_arg_types. Update
documentation for unparsed_functions_queues.
diff --git a/gcc/cp/class.c b/gcc/cp/class.c
index c278aa5e91b..9666975a090 100644
--- a/gcc/cp/class.c
+++ b/gcc/cp/class.c
@@ -4993,6 +4993,7 @@ layout_class_type (tree t, tree *virtuals_p)
{
tree type;
tree padding;
+ bool was_unnamed_p = false;
/* We still pass things that aren't non-static data members to
the back-end, in case it wants to do something with them. */
@@ -5024,7 +5025,6 @@ layout_class_type (tree t, tree *virtuals_p)
{
integer_type_kind itk;
tree integer_type;
-
/* We must allocate the bits as if suitably aligned for the
longest integer type that fits in this many bits. type
of the field. Then, we are supposed to use the left over
@@ -5053,6 +5053,17 @@ layout_class_type (tree t, tree *virtuals_p)
padding = size_binop (MINUS_EXPR, DECL_SIZE (field),
TYPE_SIZE (integer_type));
}
+ /* An unnamed bitfield does not normally affect the
+ alignment of the containing class on a target where
+ PCC_BITFIELD_TYPE_MATTERS. But, the C++ ABI does not
+ make any exceptions for unnamed bitfields when the
+ bitfields are longer than their types. Therefore, we
+ temporarily give the field a name. */
+ if (PCC_BITFIELD_TYPE_MATTERS && !DECL_NAME (field))
+ {
+ was_unnamed_p = true;
+ DECL_NAME (field) = make_anon_name ();
+ }
DECL_SIZE (field) = TYPE_SIZE (integer_type);
DECL_ALIGN (field) = TYPE_ALIGN (integer_type);
DECL_USER_ALIGN (field) = TYPE_USER_ALIGN (integer_type);
@@ -5062,6 +5073,10 @@ layout_class_type (tree t, tree *virtuals_p)
layout_nonempty_base_or_field (rli, field, NULL_TREE,
empty_base_offsets);
+ /* If the bit-field had no name originally, remove the name
+ now. */
+ if (was_unnamed_p)
+ DECL_NAME (field) = NULL_TREE;
/* Remember the location of any empty classes in FIELD. */
if (abi_version_at_least (2))
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 2c8bb11ee5f..8b4fce3179c 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,5 +1,7 @@
2003-01-06 Mark Mitchell <mark@codesourcery.com>
+ * testsuite/g++.dg/abi/bitfield9.C: New test.
+
PR c++/9189
* g++.dg/parse/defarg3.C: New test.
diff --git a/gcc/testsuite/g++.dg/abi/bitfield9.C b/gcc/testsuite/g++.dg/abi/bitfield9.C
new file mode 100644
index 00000000000..0d744c7318f
--- /dev/null
+++ b/gcc/testsuite/g++.dg/abi/bitfield9.C
@@ -0,0 +1,11 @@
+// { dg-do run { target i?86-*-* } }
+// { dg-options -w }
+
+struct X {
+ char : 45;
+};
+
+int main () {
+ if (__alignof__ (X) != 4)
+ return 1;
+}
OpenPOWER on IntegriCloud