Commit 33433751 by Mark Mitchell Committed by Mark Mitchell

stor-layout.c (layout_decl): Allow front-ends to explicitly set the DECL_SIZE for a FIELD_DECL.

	* stor-layout.c (layout_decl): Allow front-ends to explicitly set
	the DECL_SIZE for a FIELD_DECL.

From-SVN: r32287
parent 647639ef
2000-03-01 Mark Mitchell <mark@codesourcery.com>
* stor-layout.c (layout_decl): Allow front-ends to explicitly set
the DECL_SIZE for a FIELD_DECL.
2000-03-01 Bruce Korb <bkorb@gnu.org> 2000-03-01 Bruce Korb <bkorb@gnu.org>
* fixinc/inclhack.tpl: remove unused symlinks * fixinc/inclhack.tpl: remove unused symlinks
......
...@@ -265,30 +265,17 @@ layout_decl (decl, known_align) ...@@ -265,30 +265,17 @@ layout_decl (decl, known_align)
{ {
register tree type = TREE_TYPE (decl); register tree type = TREE_TYPE (decl);
register enum tree_code code = TREE_CODE (decl); register enum tree_code code = TREE_CODE (decl);
HOST_WIDE_INT spec_size = 0;
if (code == CONST_DECL) if (code == CONST_DECL)
return; return;
else if (code == FIELD_DECL)
{
if (DECL_SIZE (decl) != 0)
{
spec_size = TREE_INT_CST_LOW (DECL_SIZE (decl));
DECL_SIZE (decl) = 0;
}
}
else if (code != VAR_DECL && code != PARM_DECL && code != RESULT_DECL else if (code != VAR_DECL && code != PARM_DECL && code != RESULT_DECL
&& code != TYPE_DECL) && code != TYPE_DECL && code != FIELD_DECL)
abort (); abort ();
if (type == error_mark_node) if (type == error_mark_node)
{ type = void_type_node;
type = void_type_node;
spec_size = 0;
}
/* Usually the size and mode come from the data type without change. */ /* Usually the size and mode come from the data type without change. */
DECL_MODE (decl) = TYPE_MODE (type); DECL_MODE (decl) = TYPE_MODE (type);
TREE_UNSIGNED (decl) = TREE_UNSIGNED (type); TREE_UNSIGNED (decl) = TREE_UNSIGNED (type);
if (DECL_SIZE (decl) == 0) if (DECL_SIZE (decl) == 0)
...@@ -296,14 +283,23 @@ layout_decl (decl, known_align) ...@@ -296,14 +283,23 @@ layout_decl (decl, known_align)
DECL_SIZE (decl) = TYPE_SIZE (type); DECL_SIZE (decl) = TYPE_SIZE (type);
DECL_SIZE_UNIT (decl) = TYPE_SIZE_UNIT (type); DECL_SIZE_UNIT (decl) = TYPE_SIZE_UNIT (type);
} }
else if (code == FIELD_DECL)
if (code == FIELD_DECL && DECL_BIT_FIELD (decl))
{ {
if (spec_size == 0 && DECL_NAME (decl) != 0) HOST_WIDE_INT spec_size;
/* The front-end may set the explicit width of the field, so its
size may not be the same as the size of its type. This happens
with bitfields, of course (an `int' bitfield may be only 2 bits,
say), but it also happens with other fields. For example, the
C++ front-end creates zero-sized fields corresponding to empty
base classes, and depends on layout_type setting
DECL_FIELD_BITPOS correctly for the field. */
if (integer_zerop (DECL_SIZE (decl))
&& DECL_NAME (decl) != NULL_TREE)
abort (); abort ();
/* Size is specified in number of bits. */ /* Size is specified in number of bits. */
DECL_SIZE (decl) = bitsize_int (spec_size); spec_size = TREE_INT_CST_LOW (DECL_SIZE (decl));
if (spec_size % BITS_PER_UNIT == 0) if (spec_size % BITS_PER_UNIT == 0)
DECL_SIZE_UNIT (decl) = size_int (spec_size / BITS_PER_UNIT); DECL_SIZE_UNIT (decl) = size_int (spec_size / BITS_PER_UNIT);
else else
...@@ -313,8 +309,9 @@ layout_decl (decl, known_align) ...@@ -313,8 +309,9 @@ layout_decl (decl, known_align)
/* Force alignment required for the data type. /* Force alignment required for the data type.
But if the decl itself wants greater alignment, don't override that. But if the decl itself wants greater alignment, don't override that.
Likewise, if the decl is packed, don't override it. */ Likewise, if the decl is packed, don't override it. */
else if (DECL_ALIGN (decl) == 0 if (!(code == FIELD_DECL && DECL_BIT_FIELD (decl))
|| (! DECL_PACKED (decl) && TYPE_ALIGN (type) > DECL_ALIGN (decl))) && (DECL_ALIGN (decl) == 0
|| (! DECL_PACKED (decl) && TYPE_ALIGN (type) > DECL_ALIGN (decl))))
DECL_ALIGN (decl) = TYPE_ALIGN (type); DECL_ALIGN (decl) = TYPE_ALIGN (type);
/* See if we can use an ordinary integer mode for a bit-field. /* See if we can use an ordinary integer mode for a bit-field.
......
// Build don't link:
// Special g++ Options: -fnew-abi
// Origin: Mark Mitchell <mark@codesourcery.com>
struct S
{
};
struct T : public S
{
};
struct U : public T
{
};
void f (U);
int main ()
{
U u;
f (u);
}
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