This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug tree-optimization/45180] bogus warning: array subscript is above array bounds
- From: "joachim dot reichel at gmx dot de" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 4 Aug 2010 15:00:43 -0000
- Subject: [Bug tree-optimization/45180] bogus warning: array subscript is above array bounds
- References: <bug-45180-7360@http.gcc.gnu.org/bugzilla/>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- Comment #2 from joachim dot reichel at gmx dot de 2010-08-04 15:00 -------
Ok, I see. But that seems a bit unfortunate. Isn't there a great deal of such
code? Just think of some vector class: c would be a class member, get()
non-static and "if...f()" is an assert-like statement (that might return or
not).
void f();
int result;
struct Vector {
int c[3];
int get(int i) const {
if (i >= 3)
f();
return c[i];
}
};
void g(const Vector& x, int index)
{
result = x.get(index) + x.get(index);
}
--
In the original test case if I make get() a global function, then there is no
warning. Is the code then transformed differently?
And if I replace the argument in the second call of get() by index+1 I also
don't get the warning. I guess that's because the load into tem2 gets moved out
of the if-block then?
Just trying to understand how common the problem is ...
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45180