Commit 63e5f567 by Mark Mitchell Committed by Mark Mitchell

class.c (layout_class_type): Correct handling of unnamed bitfields wider than their types.

	* class.c (layout_class_type): Correct handling of unnamed
	bitfields wider than their types.

	* testsuite/g++.dg/abi/bitfield9.C: New test.

From-SVN: r60966
parent 52fd80fb
2003-01-06 Mark Mitchell <mark@codesourcery.com> 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 PR c++/9189
* parser.c (cp_parser): Remove default_arg_types. Update * parser.c (cp_parser): Remove default_arg_types. Update
documentation for unparsed_functions_queues. documentation for unparsed_functions_queues.
......
...@@ -4993,6 +4993,7 @@ layout_class_type (tree t, tree *virtuals_p) ...@@ -4993,6 +4993,7 @@ layout_class_type (tree t, tree *virtuals_p)
{ {
tree type; tree type;
tree padding; tree padding;
bool was_unnamed_p = false;
/* We still pass things that aren't non-static data members to /* We still pass things that aren't non-static data members to
the back-end, in case it wants to do something with them. */ the back-end, in case it wants to do something with them. */
...@@ -5024,7 +5025,6 @@ layout_class_type (tree t, tree *virtuals_p) ...@@ -5024,7 +5025,6 @@ layout_class_type (tree t, tree *virtuals_p)
{ {
integer_type_kind itk; integer_type_kind itk;
tree integer_type; tree integer_type;
/* We must allocate the bits as if suitably aligned for the /* We must allocate the bits as if suitably aligned for the
longest integer type that fits in this many bits. type longest integer type that fits in this many bits. type
of the field. Then, we are supposed to use the left over of the field. Then, we are supposed to use the left over
...@@ -5053,6 +5053,17 @@ layout_class_type (tree t, tree *virtuals_p) ...@@ -5053,6 +5053,17 @@ layout_class_type (tree t, tree *virtuals_p)
padding = size_binop (MINUS_EXPR, DECL_SIZE (field), padding = size_binop (MINUS_EXPR, DECL_SIZE (field),
TYPE_SIZE (integer_type)); 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_SIZE (field) = TYPE_SIZE (integer_type);
DECL_ALIGN (field) = TYPE_ALIGN (integer_type); DECL_ALIGN (field) = TYPE_ALIGN (integer_type);
DECL_USER_ALIGN (field) = TYPE_USER_ALIGN (integer_type); DECL_USER_ALIGN (field) = TYPE_USER_ALIGN (integer_type);
...@@ -5062,6 +5073,10 @@ layout_class_type (tree t, tree *virtuals_p) ...@@ -5062,6 +5073,10 @@ layout_class_type (tree t, tree *virtuals_p)
layout_nonempty_base_or_field (rli, field, NULL_TREE, layout_nonempty_base_or_field (rli, field, NULL_TREE,
empty_base_offsets); 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. */ /* Remember the location of any empty classes in FIELD. */
if (abi_version_at_least (2)) if (abi_version_at_least (2))
......
2003-01-06 Mark Mitchell <mark@codesourcery.com> 2003-01-06 Mark Mitchell <mark@codesourcery.com>
* testsuite/g++.dg/abi/bitfield9.C: New test.
PR c++/9189 PR c++/9189
* g++.dg/parse/defarg3.C: New test. * g++.dg/parse/defarg3.C: New test.
......
// { dg-do run { target i?86-*-* } }
// { dg-options -w }
struct X {
char : 45;
};
int main () {
if (__alignof__ (X) != 4)
return 1;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment