--- Comment #9 from jmattson at vmware dot com 2010-05-28 16:53 ---
Okay. What if we stick with equality operators, then?
static inline void
foo(int *p)
{
if (p == a + 1 || p == a + 2) {
p[-1] = 0;
}
}
This code results in the same warning.
--
http://gcc.gnu.org/bugzi
--- Comment #8 from rguenth at gcc dot gnu dot org 2010-05-28 16:40 ---
(In reply to comment #7)
> So, you are saying that given an arbitrary pointer p, it is impossible to
> determine whether or not p points to an element of array a[], because
> comparing
> pointers to different object
--- Comment #7 from jmattson at vmware dot com 2010-05-28 15:55 ---
So, you are saying that given an arbitrary pointer p, it is impossible to
determine whether or not p points to an element of array a[], because comparing
pointers to different objects is undefined? I find that hard to b
--- Comment #6 from rguenth at gcc dot gnu dot org 2010-05-28 14:44 ---
Not really. Comparing pointers that point to different objects invokes
undefined behavior anyway.
You could try
--p;
if (p >= a && p < a + 10) {
*p = 0;
}
--
http://gcc.gnu.org/bugzilla/show_
--- Comment #5 from jmattson at vmware dot com 2010-05-28 14:39 ---
Can you recommend an elegant way to rewrite this code to avoid the warning?
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44300
--- Comment #4 from rguenth at gcc dot gnu dot org 2010-05-28 10:30 ---
GCC sees at the point of the warning
if (&b > &a && &b[0] < &a[10])
b[-1] = 0;
and it cannot statically determine those comparisons.
So it warns (IMHO correctly). This is very unlikely going to be fixed.
--
--- Comment #3 from jmattson at vmware dot com 2010-05-27 20:31 ---
Admittedly, foo() makes some assumptions about alignment as originally written.
A more pedantic version is:
static inline void
foo(int *p)
{
if (p >= a + 1 && p < a + 10) {
p[-1] = 0;
}
}
gcc still generat
--- Comment #2 from pinskia at gcc dot gnu dot org 2010-05-27 20:03 ---
"&b[0] > &a[0]" is not well defined in C or C++. That is what it gets
optimized to.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44300
--- Comment #1 from jmattson at vmware dot com 2010-05-27 20:01 ---
Created an attachment (id=20761)
--> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=20761&action=view)
source code
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44300