aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Kenner <kenner@gcc.gnu.org>1997-03-02 13:25:40 -0500
committerRichard Kenner <kenner@gcc.gnu.org>1997-03-02 13:25:40 -0500
commitee2990e780903c327ff2fe9314a7bac0bfc788b5 (patch)
treeac10b2c0fd698ec1c42b76ca52613eef204840e0
parentf28c0e6987c1d099e868e216dec53f8b4f2099ba (diff)
downloadgcc-ee2990e780903c327ff2fe9314a7bac0bfc788b5.zip
gcc-ee2990e780903c327ff2fe9314a7bac0bfc788b5.tar.gz
gcc-ee2990e780903c327ff2fe9314a7bac0bfc788b5.tar.bz2
(process_init_element): Warn and truncate if upper bound of index is
out of range. From-SVN: r13684
-rw-r--r--gcc/c-typeck.c28
1 files changed, 19 insertions, 9 deletions
diff --git a/gcc/c-typeck.c b/gcc/c-typeck.c
index 592cad1..32d5c27 100644
--- a/gcc/c-typeck.c
+++ b/gcc/c-typeck.c
@@ -5769,10 +5769,8 @@ set_init_index (first, last)
error_init ("duplicate array index in initializer%s", " for `%s'", NULL);
else
{
- TREE_INT_CST_LOW (constructor_index)
- = TREE_INT_CST_LOW (first);
- TREE_INT_CST_HIGH (constructor_index)
- = TREE_INT_CST_HIGH (first);
+ TREE_INT_CST_LOW (constructor_index) = TREE_INT_CST_LOW (first);
+ TREE_INT_CST_HIGH (constructor_index) = TREE_INT_CST_HIGH (first);
if (last != 0 && tree_int_cst_lt (last, first))
error_init ("empty index range in initializer%s", " for `%s'", NULL);
@@ -6377,7 +6375,21 @@ process_init_element (value)
/* In the case of [LO .. HI] = VALUE, only evaluate VALUE once. */
if (constructor_range_end)
- value = save_expr (value);
+ {
+ if (constructor_max_index != 0
+ && tree_int_cst_lt (constructor_max_index,
+ constructor_range_end))
+ {
+ pedwarn_init ("excess elements in array initializer%s",
+ " after `%s'", NULL_PTR);
+ TREE_INT_CST_HIGH (constructor_range_end)
+ = TREE_INT_CST_HIGH (constructor_max_index);
+ TREE_INT_CST_LOW (constructor_range_end)
+ = TREE_INT_CST_LOW (constructor_max_index);
+ }
+
+ value = save_expr (value);
+ }
/* Now output the actual element.
Ordinarily, output once.
@@ -6395,10 +6407,8 @@ process_init_element (value)
tem = size_binop (PLUS_EXPR, constructor_index,
integer_one_node);
- TREE_INT_CST_LOW (constructor_index)
- = TREE_INT_CST_LOW (tem);
- TREE_INT_CST_HIGH (constructor_index)
- = TREE_INT_CST_HIGH (tem);
+ TREE_INT_CST_LOW (constructor_index) = TREE_INT_CST_LOW (tem);
+ TREE_INT_CST_HIGH (constructor_index) = TREE_INT_CST_HIGH (tem);
if (!value)
/* If we are doing the bookkeeping for an element that was