From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 5226 invoked by alias); 22 Aug 2008 16:45:33 -0000 Received: (qmail 1518 invoked by uid 48); 22 Aug 2008 16:44:23 -0000 Date: Fri, 22 Aug 2008 16:45:00 -0000 Message-ID: <20080822164423.1517.qmail@sourceware.org> X-Bugzilla-Reason: CC References: Subject: [Bug middle-end/36902] Array bound warning with dead code after optimization In-Reply-To: Reply-To: gcc-bugzilla@gcc.gnu.org To: gcc-bugs@gcc.gnu.org From: "manu at gcc dot gnu dot org" Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2008-08/txt/msg01689.txt.bz2 ------- Comment #17 from manu at gcc dot gnu dot org 2008-08-22 16:44 ------- The location passed to check_array_ref is correct but the new way to check if we are in system headers does not work well with the %H hack. This will go away soon hopefully when everything takes an explicit location. The fix is to use warning_at. This kind of thing may happen in the middle-end and in the front-end. This doesn't fix the bogus warning though, it just suppresses it within system headers. Index: gcc/tree-vrp.c =================================================================== --- gcc/tree-vrp.c (revision 139373) +++ gcc/tree-vrp.c (working copy) @@ -4811,11 +4811,11 @@ insert_range_assertions (void) range. If the array subscript is a RANGE, warn if it is non-overlapping with valid range. IGNORE_OFF_BY_ONE is true if the ARRAY_REF is inside a ADDR_EXPR. */ static void -check_array_ref (tree ref, const location_t *location, bool ignore_off_by_one) +check_array_ref (tree ref, location_t location, bool ignore_off_by_one) { value_range_t* vr = NULL; tree low_sub, up_sub; tree low_bound, up_bound = array_ref_up_bound (ref); @@ -4850,12 +4850,12 @@ check_array_ref (tree ref, const locatio if (TREE_CODE (up_sub) == INTEGER_CST && tree_int_cst_lt (up_bound, up_sub) && TREE_CODE (low_sub) == INTEGER_CST && tree_int_cst_lt (low_sub, low_bound)) { - warning (OPT_Warray_bounds, - "%Harray subscript is outside array bounds", location); + warning_at (location, OPT_Warray_bounds, + "array subscript is outside array bounds"); TREE_NO_WARNING (ref) = 1; } } else if (TREE_CODE (up_sub) == INTEGER_CST && tree_int_cst_lt (up_bound, up_sub) @@ -4865,28 +4865,28 @@ check_array_ref (tree ref, const locatio up_bound, integer_one_node, 0), up_sub))) { - warning (OPT_Warray_bounds, "%Harray subscript is above array bounds", - location); + warning_at (location, OPT_Warray_bounds, + "array subscript is above array bounds"); TREE_NO_WARNING (ref) = 1; } else if (TREE_CODE (low_sub) == INTEGER_CST && tree_int_cst_lt (low_sub, low_bound)) { - warning (OPT_Warray_bounds, "%Harray subscript is below array bounds", - location); + warning_at (location, OPT_Warray_bounds, + "array subscript is below array bounds"); TREE_NO_WARNING (ref) = 1; } } /* Searches if the expr T, located at LOCATION computes address of an ARRAY_REF, and call check_array_ref on it. */ static void -search_for_addr_array(tree t, const location_t *location) +search_for_addr_array(tree t, location_t location) { while (TREE_CODE (t) == SSA_NAME) { gimple g = SSA_NAME_DEF_STMT (t); @@ -4925,11 +4925,11 @@ search_for_addr_array(tree t, const loca static tree check_array_bounds (tree *tp, int *walk_subtree, void *data) { tree t = *tp; struct walk_stmt_info *wi = (struct walk_stmt_info *) data; - const location_t *location = (const location_t *) wi->info; + location_t location = *((location_t *) wi->info); *walk_subtree = TRUE; if (TREE_CODE (t) == ARRAY_REF) check_array_ref (t, location, false /*ignore_off_by_one*/); @@ -4972,11 +4972,11 @@ check_all_array_refs (void) continue; } for (si = gsi_start_bb (bb); !gsi_end_p (si); gsi_next (&si)) { gimple stmt = gsi_stmt (si); - const location_t *location = gimple_location_ptr (stmt); + location_t location = gimple_location (stmt); struct walk_stmt_info wi; if (!gimple_has_location (stmt)) continue; if (is_gimple_call (stmt)) @@ -4990,12 +4990,12 @@ check_all_array_refs (void) } } else { memset (&wi, 0, sizeof (wi)); - wi.info = CONST_CAST (void *, (const void *) location); - + /* wi.info = CONST_CAST (void *, (const void *) &location);*/ + wi.info = (void *) &location; walk_gimple_op (gsi_stmt (si), check_array_bounds, &wi); } } -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36902