From ce662d4c92d5a0fd86a4ea80e91ca58db778b7ee Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Wed, 31 Jan 2001 18:38:11 +0100 Subject: [PATCH] c-typeck.c (set_init_index): If first is equal to last, assume as if it was not a range at all. * c-typeck.c (set_init_index): If first is equal to last, assume as if it was not a range at all. * gcc.dg/gnu99-init-1.c: Add test for [0 ... 0] range. From-SVN: r39380 --- gcc/ChangeLog | 5 +++++ gcc/c-typeck.c | 26 ++++++++++++++++---------- gcc/testsuite/ChangeLog | 4 ++++ gcc/testsuite/gcc.dg/gnu99-init-1.c | 3 +++ 4 files changed, 28 insertions(+), 10 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index cf31ea1523f..d82c6c99bcf 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2001-01-31 Jakub Jelinek + + * c-typeck.c (set_init_index): If first is equal to last, assume as + if it was not a range at all. + 2001-01-31 Alexandre Oliva * config/fp-bit.c: Include tm.h. diff --git a/gcc/c-typeck.c b/gcc/c-typeck.c index 3dc52e48031..3b8f9b090cf 100644 --- a/gcc/c-typeck.c +++ b/gcc/c-typeck.c @@ -5688,21 +5688,27 @@ set_init_index (first, last) { constructor_index = convert (bitsizetype, first); - if (last != 0 && tree_int_cst_lt (last, first)) + if (last) { - error_init ("empty index range in initializer"); - last = 0; - } - else if (last) - { - last = convert (bitsizetype, last); - if (constructor_max_index != 0 - && tree_int_cst_lt (constructor_max_index, last)) + if (tree_int_cst_equal (first, last)) + last = 0; + else if (tree_int_cst_lt (last, first)) { - error_init ("array index range in initializer exceeds array bounds"); + error_init ("empty index range in initializer"); last = 0; } + else + { + last = convert (bitsizetype, last); + if (constructor_max_index != 0 + && tree_int_cst_lt (constructor_max_index, last)) + { + error_init ("array index range in initializer exceeds array bounds"); + last = 0; + } + } } + designator_depth++; designator_errorneous = 0; if (constructor_range_stack || last) diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 7d20abc5a4e..14117aed6f5 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2001-01-31 Jakub Jelinek + + * gcc.dg/gnu99-init-1.c: Add test for [0 ... 0] range. + 2001-01-31 Jeffrey Oldham * gcc.dg/c99-float-1.c: Back out "XFAIL FLT_EVAL_METHOD and diff --git a/gcc/testsuite/gcc.dg/gnu99-init-1.c b/gcc/testsuite/gcc.dg/gnu99-init-1.c index 9c22c90103b..009c8515f1e 100644 --- a/gcc/testsuite/gcc.dg/gnu99-init-1.c +++ b/gcc/testsuite/gcc.dg/gnu99-init-1.c @@ -24,6 +24,7 @@ struct M o[] = { [0 ... 5].O = { [1 ... 2].K[0 ... 1] = 4 }, struct M p[] = { [0 ... 5].O[1 ... 2].K = { [0 ... 1] = 4 }, [5].O[2].K[2] = 5, 6, 7 }; int q[3][3] = { [0 ... 1] = { [1 ... 2] = 23 }, [1][2] = 24 }; +int r[1] = { [0 ... 1 - 1] = 27 }; int main (void) { @@ -73,5 +74,7 @@ int main (void) abort (); if (q[2][0] || q[2][1] || q[2][2]) abort (); + if (r[0] != 27) + abort (); exit (0); } -- 2.30.2