This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/35652] Location information incorrect on string bounds warning
- From: "rguenth at gcc dot gnu dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 21 Mar 2008 12:49:51 -0000
- Subject: [Bug c++/35652] Location information incorrect on string bounds warning
- References: <bug-35652-11271@http.gcc.gnu.org/bugzilla/>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- Comment #1 from rguenth at gcc dot gnu dot org 2008-03-21 12:49 -------
The warning happens when for example constant propagation tries to optimize
the read from the constant string and calls builtins.c:c_strlen which
produces this warning. As that warning doesn't specify any location the
current source location is used which is bogus for a warning from the
middle-end.
What we see in the IL that causes this is:
<bb 4>:
D.12603_7 = append (&s, &"y"[120]);
which is because 'x' + "y" is the same as "y"['x'].
We should avoid re-constructing these out-of-bounds array accesses.
Note that the warning appears multiple times since &"y"[120] is a constant
that is replicated all over the IL and thus present multiple times.
If c_strlen would just return 0 in these cases after warning once that
would fix the issue as well (and it can validly do so, as the code invokes
undefined behavior).
--
rguenth at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Ever Confirmed|0 |1
Keywords| |diagnostic, wrong-code
Known to fail| |4.3.0
Last reconfirmed|0000-00-00 00:00:00 |2008-03-21 12:49:51
date| |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35652