aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorRichard Kenner <kenner@gcc.gnu.org>1994-03-14 08:47:18 -0500
committerRichard Kenner <kenner@gcc.gnu.org>1994-03-14 08:47:18 -0500
commit0a43d68083384a232b9975d62f2028bce83298ec (patch)
tree0eef033590d88766af6d7982e48f47b5596555de /gcc
parent0207ea829ba7dc8fefe3d7e308ad70c21d13eb44 (diff)
downloadgcc-0a43d68083384a232b9975d62f2028bce83298ec.zip
gcc-0a43d68083384a232b9975d62f2028bce83298ec.tar.gz
gcc-0a43d68083384a232b9975d62f2028bce83298ec.tar.bz2
(grokdeclarator): Convert to sizetype when manipulating size of array
and use care to avoid mixed-type operations. From-SVN: r6787
Diffstat (limited to 'gcc')
-rw-r--r--gcc/c-decl.c26
1 files changed, 16 insertions, 10 deletions
diff --git a/gcc/c-decl.c b/gcc/c-decl.c
index 7efb423..66ca348 100644
--- a/gcc/c-decl.c
+++ b/gcc/c-decl.c
@@ -4265,21 +4265,25 @@ grokdeclarator (declarator, declspecs, decl_context, initialized)
error ("size of array `%s' has non-integer type", name);
size = integer_one_node;
}
+
if (pedantic && integer_zerop (size))
pedwarn ("ANSI C forbids zero-size array `%s'", name);
+
if (TREE_CODE (size) == INTEGER_CST)
{
constant_expression_warning (size);
- if (INT_CST_LT (size, integer_zero_node))
+ if (tree_int_cst_sgn (size) < 0)
{
error ("size of array `%s' is negative", name);
size = integer_one_node;
}
- itype = build_index_type (size_binop (MINUS_EXPR, size,
- size_one_node));
}
else
{
+ /* Make sure the array size remains visibly nonconstant
+ even if it is (eg) a const variable with known value. */
+ size_varies = 1;
+
if (pedantic)
{
if (TREE_CONSTANT (size))
@@ -4287,14 +4291,16 @@ grokdeclarator (declarator, declspecs, decl_context, initialized)
else
pedwarn ("ANSI C forbids variable-size array `%s'", name);
}
- itype = build_binary_op (MINUS_EXPR, size, integer_one_node,
- 1);
- /* Make sure the array size remains visibly nonconstant
- even if it is (eg) a const variable with known value. */
- size_varies = 1;
- itype = variable_size (itype);
- itype = build_index_type (itype);
}
+
+ /* Convert size to sizetype, so that if it is a variable
+ the computations will be done in the proper mode. */
+ itype = fold (build (MINUS_EXPR, sizetype,
+ convert (sizetype, size), size_one_node));
+
+ if (size_varies)
+ itype = variable_size (itype);
+ itype = build_index_type (itype);
}
#if 0 /* This had bad results for pointers to arrays, as in