LANG=C /home/marcus/projects/gcc/BIN/bin/gcc -c -O2 -Wall -g -o xx.o relay16.i -m32 relay16.i: In function 'f': cc1: warning: array subscript is above array bounds -m32 seems necessary
Created attachment 14612 [details] relay16.i testcase
The expression warned about is call_5(D)->ret[5] and I suspect the mapped locations make the location information wrong.
Indeed. EXPR_LOCUS no longer is NULL if there is no location, but one has to use EXPR_HAS_LOCATION instead. Like Index: tree-vrp.c =================================================================== --- tree-vrp.c (revision 130323) +++ tree-vrp.c (working copy) @@ -4492,8 +4492,9 @@ check_all_array_refs (void) continue; } for (si = bsi_start (bb); !bsi_end_p (si); bsi_next (&si)) - walk_tree (bsi_stmt_ptr (si), check_array_bounds, - bsi_stmt (si), NULL); + if (expr_has_location (bsi_stmt (si))) + walk_tree (bsi_stmt_ptr (si), check_array_bounds, + bsi_stmt (si), NULL); } } which gets rid of the warning.
thanks for the analysis. I would go for a slightly more verbose version of the same patch: --- gcc/tree-vrp.c (revision 130297) +++ gcc/tree-vrp.c (working copy) @@ -4339,7 +4339,7 @@ check_array_ref (tree ref, location_t* l low_sub = up_sub = TREE_OPERAND (ref, 1); - if (!up_bound || !locus || TREE_NO_WARNING (ref) + if (!up_bound || TREE_NO_WARNING (ref) || TREE_CODE (up_bound) != INTEGER_CST /* Can not check flexible arrays. */ || (TYPE_SIZE (TREE_TYPE (ref)) == NULL_TREE @@ -4441,6 +4441,11 @@ check_array_bounds (tree *tp, int *walk_ tree stmt = (tree)data; location_t *location = EXPR_LOCUS (stmt); + if (!EXPR_HAS_LOCATION (stmt)) { + *walk_subtree = FALSE; + return NULL_TREE; + } + *walk_subtree = TRUE; if (TREE_CODE (t) == ARRAY_REF)
*** Bug 32546 has been marked as a duplicate of this bug. ***
Subject: Bug 34197 Author: mueller Date: Fri Nov 23 23:02:21 2007 New Revision: 130385 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=130385 Log: 2007-11-23 Dirk Mueller <dmueller@suse.de> Richard Guenther <rguenther@suse.de> PR middle-end/34197 * tree-vrp.c (check_array_ref): Move check for valid location.. (check_array_bounds) here. Use EXPR_HAS_LOCATION(). Modified: trunk/gcc/ChangeLog trunk/gcc/tree-vrp.c
Fixed for 4.3