diff options
author | Simon Baldwin <simonb@google.com> | 2008-05-02 20:01:31 +0000 |
---|---|---|
committer | Simon Baldwin <simonb@gcc.gnu.org> | 2008-05-02 20:01:31 +0000 |
commit | e4d355154880463416ba21be979aa77654d727a0 (patch) | |
tree | 7a9abc71059af57af9a976cfa19589fee9e462be /gcc/c-common.c | |
parent | bb1418c1b43a95548515bffb8d4a54a173f2a49d (diff) | |
download | gcc-e4d355154880463416ba21be979aa77654d727a0.zip gcc-e4d355154880463416ba21be979aa77654d727a0.tar.gz gcc-e4d355154880463416ba21be979aa77654d727a0.tar.bz2 |
Rolled back the following changes made in revision 134865:
* c-common.h (warn_array_subscript_range): New function.
* c-common.c (warn_array_subscript_range): Ditto.
* tree-vrp.c (check_array_ref): Corrected code to agree with
comment, ignoring only arrays of size 0 or size 1.
* c-typeck.c (build_array_ref): Call warn_array_subscript_range.
* testsuite/gcc.dg/Warray-bounds.c: Updated for frontend warnings,
additional tests for arrays of size 0 and size 1.
* testsuite/g++.dg/warn/Warray-bounds.c: Ditto.
* testsuite/gcc.dg/Warray-bounds-noopt.c: New testcase.
* testsuite/g++.dg/warn/Warray-bounds-noopt.c: Ditto.
* typeck.c (build_array_ref): Call warn_array_subscript_range.
From-SVN: r134889
Diffstat (limited to 'gcc/c-common.c')
-rw-r--r-- | gcc/c-common.c | 54 |
1 files changed, 0 insertions, 54 deletions
diff --git a/gcc/c-common.c b/gcc/c-common.c index 3fa1649..5858523 100644 --- a/gcc/c-common.c +++ b/gcc/c-common.c @@ -7452,60 +7452,6 @@ warn_array_subscript_with_type_char (tree index) warning (OPT_Wchar_subscripts, "array subscript has type %<char%>"); } -/* Warn about obvious array bounds errors for fixed size arrays that - are indexed by a constant. This is a subset of similar checks in - tree-vrp.c; by doing this here we can get some level of checking - from non-optimized, non-vrp compilation. Returns true if a warning - is issued. */ - -bool -warn_array_subscript_range (const_tree array, const_tree index) -{ - if (skip_evaluation == 0 - && TREE_CODE (TREE_TYPE (array)) == ARRAY_TYPE - && TYPE_DOMAIN (TREE_TYPE (array)) && TREE_CODE (index) == INTEGER_CST) - { - const_tree max_index; - - max_index = TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (array))); - if (max_index && TREE_CODE (max_index) == INTEGER_CST - && tree_int_cst_lt (max_index, index) - && !tree_int_cst_equal (index, max_index) - /* Always allow off-by-one. */ - && !tree_int_cst_equal (int_const_binop (PLUS_EXPR, - max_index, - integer_one_node, - 0), - index) - /* Accesses after the end of arrays of size 0 (gcc - extension) and 1 are likely intentional ("struct - hack"). Note that max_index is array dimension - 1. */ - && compare_tree_int (max_index, 1) >= 0) - { - warning (OPT_Warray_bounds, - "array subscript is above array bounds"); - return true; - } - else - { - const_tree min_index; - - min_index = TYPE_MIN_VALUE (TYPE_DOMAIN (TREE_TYPE (array))); - if (min_index && TREE_CODE (min_index) == INTEGER_CST - && tree_int_cst_lt (index, min_index)) - { - warning (OPT_Warray_bounds, - compare_tree_int (min_index, 0) == 0 - ? "array subscript is negative" - : "array subscript is below array bounds"); - return true; - } - } - } - - return false; -} - /* Implement -Wparentheses for the unexpected C precedence rules, to cover cases like x + y << z which readers are likely to misinterpret. We have seen an expression in which CODE is a binary |