diff options
author | simonb <simonb@138bc75d-0d04-0410-961f-82ee72b054a4> | 2008-05-01 19:03:32 +0000 |
---|---|---|
committer | simonb <simonb@138bc75d-0d04-0410-961f-82ee72b054a4> | 2008-05-01 19:03:32 +0000 |
commit | 98cb064a88338684234aeff8d4dca8b4768e6b35 (patch) | |
tree | 9ed540dc4bc280eaffa691609aa5d92b79a62090 /gcc/cp | |
parent | 49698f189da3d0b50c33959fe9f59be8fc7d061e (diff) | |
download | gcc-98cb064a88338684234aeff8d4dca8b4768e6b35.tar.gz |
* 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.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@134865 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/cp')
-rw-r--r-- | gcc/cp/ChangeLog | 4 | ||||
-rw-r--r-- | gcc/cp/typeck.c | 14 |
2 files changed, 16 insertions, 2 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 52892226720..29b70d02ad4 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,7 @@ +2008-05-01 Simon Baldwin <simonb@google.com> + + * typeck.c (build_array_ref): Call warn_array_subscript_range. + 2008-04-30 Jakub Jelinek <jakub@redhat.com> PR c++/35986 diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c index bf264ad2cc7..1447182ed01 100644 --- a/gcc/cp/typeck.c +++ b/gcc/cp/typeck.c @@ -2556,7 +2556,8 @@ build_array_ref (tree array, tree idx) if (TREE_CODE (TREE_TYPE (array)) == ARRAY_TYPE) { - tree rval, type; + bool has_warned_on_bounds_check = false; + tree rval, type, ref; warn_array_subscript_with_type_char (idx); @@ -2573,6 +2574,10 @@ build_array_ref (tree array, tree idx) pointer arithmetic.) */ idx = perform_integral_promotions (idx); + /* Warn about any obvious array bounds errors for fixed size arrays that + are indexed by a constant. */ + has_warned_on_bounds_check = warn_array_subscript_range (array, idx); + /* An array that is indexed by a non-constant cannot be stored in a register; we must be able to do address arithmetic on its address. @@ -2623,7 +2628,12 @@ build_array_ref (tree array, tree idx) |= (CP_TYPE_VOLATILE_P (type) | TREE_SIDE_EFFECTS (array)); TREE_THIS_VOLATILE (rval) |= (CP_TYPE_VOLATILE_P (type) | TREE_THIS_VOLATILE (array)); - return require_complete_type (fold_if_not_in_template (rval)); + ref = require_complete_type (fold_if_not_in_template (rval)); + + /* Suppress bounds warning in tree-vrp.c if already warned here. */ + if (has_warned_on_bounds_check) + TREE_NO_WARNING (ref) = 1; + return ref; } { |