Commit 0caa3c8e by Richard Henderson Committed by Richard Henderson

c-typeck.c (c_sizeof): Fold result to c_size_type_node.

        * c-typeck.c (c_sizeof): Fold result to c_size_type_node.
        (c_sizeof_nowarn, c_alignof, c_alignof_expr): Likewise.

From-SVN: r37447
parent 8422942c
2000-11-14 Richard Henderson <rth@redhat.com>
* c-typeck.c (c_sizeof): Fold result to c_size_type_node.
(c_sizeof_nowarn, c_alignof, c_alignof_expr): Likewise.
2000-11-13 Franz Sirl <Franz.Sirl-kernel@lauterbach.com> 2000-11-13 Franz Sirl <Franz.Sirl-kernel@lauterbach.com>
* loop.c (basic_induction_var): Revert accidental checkin. * loop.c (basic_induction_var): Revert accidental checkin.
......
...@@ -697,33 +697,38 @@ c_sizeof (type) ...@@ -697,33 +697,38 @@ c_sizeof (type)
tree type; tree type;
{ {
enum tree_code code = TREE_CODE (type); enum tree_code code = TREE_CODE (type);
tree size;
if (code == FUNCTION_TYPE) if (code == FUNCTION_TYPE)
{ {
if (pedantic || warn_pointer_arith) if (pedantic || warn_pointer_arith)
pedwarn ("sizeof applied to a function type"); pedwarn ("sizeof applied to a function type");
return size_one_node; size = size_one_node;
} }
if (code == VOID_TYPE) else if (code == VOID_TYPE)
{ {
if (pedantic || warn_pointer_arith) if (pedantic || warn_pointer_arith)
pedwarn ("sizeof applied to a void type"); pedwarn ("sizeof applied to a void type");
return size_one_node; size = size_one_node;
} }
else if (code == ERROR_MARK)
if (code == ERROR_MARK) size = size_one_node;
return size_one_node; else if (!COMPLETE_TYPE_P (type))
if (!COMPLETE_TYPE_P (type))
{ {
error ("sizeof applied to an incomplete type"); error ("sizeof applied to an incomplete type");
return size_zero_node; size = size_zero_node;
} }
else
/* Convert in case a char is more than one unit. */ /* Convert in case a char is more than one unit. */
return size_binop (CEIL_DIV_EXPR, TYPE_SIZE_UNIT (type), size = size_binop (CEIL_DIV_EXPR, TYPE_SIZE_UNIT (type),
size_int (TYPE_PRECISION (char_type_node) size_int (TYPE_PRECISION (char_type_node)
/ BITS_PER_UNIT)); / BITS_PER_UNIT));
/* SIZE will have an integer type with TYPE_IS_SIZETYPE set.
TYPE_IS_SIZETYPE means that certain things (like overflow) will
never happen. However, this node should really have type
`size_t', which is just a typedef for an ordinary integer type. */
return fold (build1 (NOP_EXPR, c_size_type_node, size));
} }
tree tree
...@@ -731,17 +736,23 @@ c_sizeof_nowarn (type) ...@@ -731,17 +736,23 @@ c_sizeof_nowarn (type)
tree type; tree type;
{ {
enum tree_code code = TREE_CODE (type); enum tree_code code = TREE_CODE (type);
tree size;
if (code == FUNCTION_TYPE || code == VOID_TYPE || code == ERROR_MARK) if (code == FUNCTION_TYPE || code == VOID_TYPE || code == ERROR_MARK)
return size_one_node; size = size_one_node;
else if (!COMPLETE_TYPE_P (type))
if (!COMPLETE_TYPE_P (type)) size = size_zero_node;
return size_zero_node; else
/* Convert in case a char is more than one unit. */
/* Convert in case a char is more than one unit. */ size = size_binop (CEIL_DIV_EXPR, TYPE_SIZE_UNIT (type),
return size_binop (CEIL_DIV_EXPR, TYPE_SIZE_UNIT (type), size_int (TYPE_PRECISION (char_type_node)
size_int (TYPE_PRECISION (char_type_node) / BITS_PER_UNIT));
/ BITS_PER_UNIT));
/* SIZE will have an integer type with TYPE_IS_SIZETYPE set.
TYPE_IS_SIZETYPE means that certain things (like overflow) will
never happen. However, this node should really have type
`size_t', which is just a typedef for an ordinary integer type. */
return fold (build1 (NOP_EXPR, c_size_type_node, size));
} }
/* Compute the size to increment a pointer by. */ /* Compute the size to increment a pointer by. */
...@@ -775,20 +786,23 @@ c_alignof (type) ...@@ -775,20 +786,23 @@ c_alignof (type)
tree type; tree type;
{ {
enum tree_code code = TREE_CODE (type); enum tree_code code = TREE_CODE (type);
tree t;
if (code == FUNCTION_TYPE) if (code == FUNCTION_TYPE)
return size_int (FUNCTION_BOUNDARY / BITS_PER_UNIT); t = size_int (FUNCTION_BOUNDARY / BITS_PER_UNIT);
else if (code == VOID_TYPE || code == ERROR_MARK)
if (code == VOID_TYPE || code == ERROR_MARK) t = size_one_node;
return size_one_node; else if (code == ERROR_MARK)
t = size_one_node;
if (!COMPLETE_TYPE_P (type)) else if (!COMPLETE_TYPE_P (type))
{ {
error ("__alignof__ applied to an incomplete type"); error ("__alignof__ applied to an incomplete type");
return size_zero_node; t = size_zero_node;
} }
else
t = size_int (TYPE_ALIGN (type) / BITS_PER_UNIT);
return size_int (TYPE_ALIGN (type) / BITS_PER_UNIT); return fold (build1 (NOP_EXPR, c_size_type_node, t));
} }
/* Implement the __alignof keyword: Return the minimum required /* Implement the __alignof keyword: Return the minimum required
...@@ -800,20 +814,22 @@ tree ...@@ -800,20 +814,22 @@ tree
c_alignof_expr (expr) c_alignof_expr (expr)
tree expr; tree expr;
{ {
tree t;
if (TREE_CODE (expr) == VAR_DECL) if (TREE_CODE (expr) == VAR_DECL)
return size_int (DECL_ALIGN (expr) / BITS_PER_UNIT); t = size_int (DECL_ALIGN (expr) / BITS_PER_UNIT);
if (TREE_CODE (expr) == COMPONENT_REF else if (TREE_CODE (expr) == COMPONENT_REF
&& DECL_C_BIT_FIELD (TREE_OPERAND (expr, 1))) && DECL_C_BIT_FIELD (TREE_OPERAND (expr, 1)))
{ {
error ("`__alignof' applied to a bit-field"); error ("`__alignof' applied to a bit-field");
return size_one_node; t = size_one_node;
} }
else if (TREE_CODE (expr) == COMPONENT_REF else if (TREE_CODE (expr) == COMPONENT_REF
&& TREE_CODE (TREE_OPERAND (expr, 1)) == FIELD_DECL) && TREE_CODE (TREE_OPERAND (expr, 1)) == FIELD_DECL)
return size_int (DECL_ALIGN (TREE_OPERAND (expr, 1)) / BITS_PER_UNIT); t = size_int (DECL_ALIGN (TREE_OPERAND (expr, 1)) / BITS_PER_UNIT);
if (TREE_CODE (expr) == INDIRECT_REF) else if (TREE_CODE (expr) == INDIRECT_REF)
{ {
tree t = TREE_OPERAND (expr, 0); tree t = TREE_OPERAND (expr, 0);
tree best = t; tree best = t;
...@@ -833,6 +849,8 @@ c_alignof_expr (expr) ...@@ -833,6 +849,8 @@ c_alignof_expr (expr)
} }
else else
return c_alignof (TREE_TYPE (expr)); return c_alignof (TREE_TYPE (expr));
return fold (build1 (NOP_EXPR, c_size_type_node, t));
} }
/* Return either DECL or its known constant value (if it has one). */ /* Return either DECL or its known constant value (if it has one). */
......
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