This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug tree-optimization/45180] bogus warning: array subscript is above array bounds



------- 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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]