aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorRichard Henderson <rth@redhat.com>2000-11-14 01:47:13 -0800
committerRichard Henderson <rth@gcc.gnu.org>2000-11-14 01:47:13 -0800
commit0caa3c8e095f903a847e8dfe4d652e9dfac91850 (patch)
treef759273c6d8e8f420c4cd169ddd35e54935ff5a9 /gcc
parent8422942cb6c2076b05d8a248f1f0c5b6ffe67321 (diff)
downloadgcc-0caa3c8e095f903a847e8dfe4d652e9dfac91850.zip
gcc-0caa3c8e095f903a847e8dfe4d652e9dfac91850.tar.gz
gcc-0caa3c8e095f903a847e8dfe4d652e9dfac91850.tar.bz2
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
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ChangeLog5
-rw-r--r--gcc/c-typeck.c92
2 files changed, 60 insertions, 37 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 38734a8..f82e04a 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,8 @@
+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>
* loop.c (basic_induction_var): Revert accidental checkin.
diff --git a/gcc/c-typeck.c b/gcc/c-typeck.c
index 6705440..09f4089 100644
--- a/gcc/c-typeck.c
+++ b/gcc/c-typeck.c
@@ -697,33 +697,38 @@ c_sizeof (type)
tree type;
{
enum tree_code code = TREE_CODE (type);
+ tree size;
if (code == FUNCTION_TYPE)
{
if (pedantic || warn_pointer_arith)
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)
pedwarn ("sizeof applied to a void type");
- return size_one_node;
+ size = size_one_node;
}
-
- if (code == ERROR_MARK)
- return size_one_node;
-
- if (!COMPLETE_TYPE_P (type))
+ else if (code == ERROR_MARK)
+ size = size_one_node;
+ else if (!COMPLETE_TYPE_P (type))
{
error ("sizeof applied to an incomplete type");
- return size_zero_node;
+ size = size_zero_node;
}
-
- /* Convert in case a char is more than one unit. */
- return size_binop (CEIL_DIV_EXPR, TYPE_SIZE_UNIT (type),
- size_int (TYPE_PRECISION (char_type_node)
- / BITS_PER_UNIT));
+ else
+ /* Convert in case a char is more than one unit. */
+ size = size_binop (CEIL_DIV_EXPR, TYPE_SIZE_UNIT (type),
+ size_int (TYPE_PRECISION (char_type_node)
+ / 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
@@ -731,17 +736,23 @@ c_sizeof_nowarn (type)
tree type;
{
enum tree_code code = TREE_CODE (type);
+ tree size;
if (code == FUNCTION_TYPE || code == VOID_TYPE || code == ERROR_MARK)
- return size_one_node;
-
- if (!COMPLETE_TYPE_P (type))
- return size_zero_node;
-
- /* Convert in case a char is more than one unit. */
- return size_binop (CEIL_DIV_EXPR, TYPE_SIZE_UNIT (type),
- size_int (TYPE_PRECISION (char_type_node)
- / BITS_PER_UNIT));
+ size = size_one_node;
+ else if (!COMPLETE_TYPE_P (type))
+ size = size_zero_node;
+ else
+ /* Convert in case a char is more than one unit. */
+ size = size_binop (CEIL_DIV_EXPR, TYPE_SIZE_UNIT (type),
+ size_int (TYPE_PRECISION (char_type_node)
+ / 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. */
@@ -775,20 +786,23 @@ c_alignof (type)
tree type;
{
enum tree_code code = TREE_CODE (type);
+ tree t;
if (code == FUNCTION_TYPE)
- return size_int (FUNCTION_BOUNDARY / BITS_PER_UNIT);
-
- if (code == VOID_TYPE || code == ERROR_MARK)
- return size_one_node;
-
- if (!COMPLETE_TYPE_P (type))
+ t = size_int (FUNCTION_BOUNDARY / BITS_PER_UNIT);
+ else if (code == VOID_TYPE || code == ERROR_MARK)
+ t = size_one_node;
+ else if (code == ERROR_MARK)
+ t = size_one_node;
+ else if (!COMPLETE_TYPE_P (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
@@ -800,20 +814,22 @@ tree
c_alignof_expr (expr)
tree expr;
{
+ tree t;
+
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
- && DECL_C_BIT_FIELD (TREE_OPERAND (expr, 1)))
+ else if (TREE_CODE (expr) == COMPONENT_REF
+ && DECL_C_BIT_FIELD (TREE_OPERAND (expr, 1)))
{
error ("`__alignof' applied to a bit-field");
- return size_one_node;
+ t = size_one_node;
}
else if (TREE_CODE (expr) == COMPONENT_REF
&& 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 best = t;
@@ -833,6 +849,8 @@ c_alignof_expr (expr)
}
else
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). */