[Bug tree-optimization/59124] [4.9/5/6 Regression] Wrong warnings "array subscript is above array bounds"

pangbw at gmail dot com gcc-bugzilla@gcc.gnu.org
Thu Sep 10 21:52:00 GMT 2015


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.



More information about the Gcc-bugs mailing list