From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 10509 invoked by alias); 19 May 2014 23:10:24 -0000 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 Received: (qmail 10450 invoked by uid 48); 19 May 2014 23:10:18 -0000 From: "Keith.S.Thompson at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/61240] New: Incorrect warning "integer overflow in expression" on pointer-pointer subtraction Date: Mon, 19 May 2014 23:10:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c X-Bugzilla-Version: 4.8.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: Keith.S.Thompson at gmail dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-SW-Source: 2014-05/txt/msg01667.txt.bz2 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D61240 Bug ID: 61240 Summary: Incorrect warning "integer overflow in expression" on pointer-pointer subtraction Product: gcc Version: 4.8.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: Keith.S.Thompson at gmail dot com Credit goes to "Lumbering Lummox", the author of this Stack Overflow post: http://stackoverflow.com/q/23747641/827263 I see this problem with gcc versions 4.8.0 and 4.9.0, both compiled from source, on Linux Mint 14 on x86_64. Source program: int main(void) { int i; int *p =3D &i; int *q =3D &i + 1; p - (p - 1); q - (q - 1); } Compiler output: % /usr/local/apps/gcc-4.8.0/bin/gcc gcc-bug-integer-overflow.c gcc-bug-integer-overflow.c: In function =E2=80=98main=E2=80=99: gcc-bug-integer-overflow.c:5:7: warning: integer overflow in expression [-Woverflow] p - (p - 1); ^ gcc-bug-integer-overflow.c:6:7: warning: integer overflow in expression [-Woverflow] q - (q - 1); ^ A warning would be appropriate for "p - (p - 1)", since (p - 1) has undefin= ed behavior -- but since it's pointer arithmetic, not integer arithmetic, the "integer overflow" warning is at least incorrectly worded. Furthermore, the error message points to the first "-", which is not the problem. As for "q - (q - 1)", no warning should be issued at all, since both "(q - = 1)" and "q - (q - 1)" are valid expressions with well defined behavior (yieldin= g &i and (ptrdiff_t)1, respectively). This might be related to bug #48267. >>From gcc-bugs-return-451976-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org Mon May 19 23:53:14 2014 Return-Path: Delivered-To: listarch-gcc-bugs@gcc.gnu.org Received: (qmail 3316 invoked by alias); 19 May 2014 23:53:13 -0000 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 Delivered-To: mailing list gcc-bugs@gcc.gnu.org Received: (qmail 3257 invoked by uid 48); 19 May 2014 23:53:09 -0000 From: "ian at airs dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug go/61232] [4.10 Regression] link errors building libgo Date: Mon, 19 May 2014 23:53:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: go X-Bugzilla-Version: 4.10.0 X-Bugzilla-Keywords: build X-Bugzilla-Severity: normal X-Bugzilla-Who: ian at airs dot com X-Bugzilla-Status: ASSIGNED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: hubicka at gcc dot gnu.org X-Bugzilla-Target-Milestone: 4.10.0 X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-SW-Source: 2014-05/txt/msg01668.txt.bz2 Content-length: 219 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61232 --- Comment #10 from Ian Lance Taylor --- Yes, I think that would be clearer. Your patch does seem to fix the problem building libgo. Thanks.