From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 4444 invoked by alias); 24 Mar 2011 07:58:36 -0000 Received: (qmail 4344 invoked by uid 55); 24 Mar 2011 07:58:10 -0000 Date: Thu, 24 Mar 2011 08:53:00 -0000 From: "eggert at gnu dot org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/48267] New: incorrect signed overflow warning when a pointer cannot possibly overflow X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c X-Bugzilla-Keywords: X-Bugzilla-Severity: minor X-Bugzilla-Who: eggert at gnu dot org X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Changed-Fields: Message-ID: X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" MIME-Version: 1.0 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2011-03/txt/msg02510.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48267 Summary: incorrect signed overflow warning when a pointer cannot possibly overflow Product: gcc Version: 4.5.2 Status: UNCONFIRMED Severity: minor Priority: P3 Component: c AssignedTo: unassigned@gcc.gnu.org ReportedBy: eggert@gnu.org I ran into this problem when compiling the GNU Emacs trunk with a GCC 4.5.2 that I built on RHEL 5.5 (x86-64). I narrowed it down to the following stripped-down test case. This smells different from the previous bug report I filed in this area (PR48228) on the same platform. When I compile the following program with "gcc -S -Wstrict-overflow -O2" GCC reports "warning: assuming pointer wraparound does not occur when comparing P +- C1 with P +- C2". This warning is incorrect, since signed overflow is obviously impossible in this function: the only pointers computed are head_table and head_table + 1, which are both in range. Changing the "+ 1" to "+ 7" generates even more warnings, though the program is still correct. int head_table[7]; int foo (void) { const int *p; int x = 0; for (p = head_table; p < head_table + 1; p++) x ^= *p; return x; }