This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug tree-optimization/59124] [4.9/5/6 Regression] Wrong warnings "array subscript is above array bounds"
- From: "pangbw at gmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Thu, 10 Sep 2015 21:52:53 +0000
- Subject: [Bug tree-optimization/59124] [4.9/5/6 Regression] Wrong warnings "array subscript is above array bounds"
- Auto-submitted: auto-generated
- References: <bug-59124-4 at http dot gcc dot gnu dot org/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=59124
--- Comment #19 from baoshan <pangbw at gmail dot com> ---
I did a little investigation to the code:
The warning occurs because tree_int_cst_lt (up_bound, up_sub) is true here:
else if (TREE_CODE (up_sub) == INTEGER_CST
&& (ignore_off_by_one
? (tree_int_cst_lt (up_bound, up_sub)
&& !tree_int_cst_equal (up_bound_p1, up_sub))
: (tree_int_cst_lt (up_bound, up_sub)
|| tree_int_cst_equal (up_bound_p1, up_sub))))
{
if (dump_file && (dump_flags & TDF_DETAILS))
{
fprintf (dump_file, "Array bound warning for ");
dump_generic_expr (MSG_NOTE, TDF_SLIM, ref);
fprintf (dump_file, "\n");
}
warning_at (location, OPT_Warray_bounds,
=> "array subscript is above array bounds");
TREE_NO_WARNING (ref) = 1;
}
I dumped the tree up_bound and up_sub:
(gdb) p debug_tree(up_bound)
<integer_cst 0x7ffff6acd3a8 type <integer_type 0x7ffff6c3d0a8 sizetype>
constant 5>
p debug_tree(up_sub)
<integer_cst 0x7ffff6ae92d0 type <integer_type 0x7ffff6c3d738 unsigned int>
constant 4294967291>
We can see the value of up_sub is represented as unsigned int value 4294967291
which is really weird to me, it suppose to be a int value -5 here.