Assignee: unassigned at gcc dot gnu.org
Reporter: jmattson at vmware dot com
Target Milestone: ---
Created attachment 35472
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=35472&action=edit
Preprocessed source file
As a result of inlining, gcc generates an unreachable out-of
'-v' '-save-temps' '-c' '-O2' '-Wall' '-mtune=generic'
--
Summary: Spurious array subscript warning
Product: gcc
Version: 4.4.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: jmattson at vmware dot com
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
--- 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;
--- 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 #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
--- 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