public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/61240] New: Incorrect warning "integer overflow in expression" on pointer-pointer subtraction
@ 2014-05-19 23:10 Keith.S.Thompson at gmail dot com
  2014-05-20  8:38 ` [Bug c/61240] [4.8/4.9/4.10 Regression] " rguenth at gcc dot gnu.org
                   ` (11 more replies)
  0 siblings, 12 replies; 13+ messages in thread
From: Keith.S.Thompson at gmail dot com @ 2014-05-19 23:10 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61240

            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 = &i;
    int *q = &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 ‘main’:
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 undefined
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 (yielding &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: <gcc-bugs-return-451976-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org>
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: <gcc-bugs.gcc.gnu.org>
List-Archive: <http://gcc.gnu.org/ml/gcc-bugs/>
List-Post: <mailto:gcc-bugs@gcc.gnu.org>
List-Help: <mailto:gcc-bugs-help@gcc.gnu.org>
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" <gcc-bugzilla@gcc.gnu.org>
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: <bug-61232-4-dPayYuZMfT@http.gcc.gnu.org/bugzilla/>
In-Reply-To: <bug-61232-4@http.gcc.gnu.org/bugzilla/>
References: <bug-61232-4@http.gcc.gnu.org/bugzilla/>
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?ida232

--- Comment #10 from Ian Lance Taylor <ian at airs dot com> ---
Yes, I think that would be clearer.

Your patch does seem to fix the problem building libgo.  Thanks.


^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2015-06-30 22:49 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-05-19 23:10 [Bug c/61240] New: Incorrect warning "integer overflow in expression" on pointer-pointer subtraction Keith.S.Thompson at gmail dot com
2014-05-20  8:38 ` [Bug c/61240] [4.8/4.9/4.10 Regression] " rguenth at gcc dot gnu.org
2014-05-22  9:07 ` rguenth at gcc dot gnu.org
2014-07-01 20:09 ` jakub at gcc dot gnu.org
2014-08-04  7:21 ` mpolacek at gcc dot gnu.org
2014-08-04  7:30 ` jakub at gcc dot gnu.org
2014-08-04  7:39 ` mpolacek at gcc dot gnu.org
2014-12-01 12:26 ` [Bug c/61240] [4.8/4.9/5 " rguenth at gcc dot gnu.org
2014-12-01 12:35 ` mpolacek at gcc dot gnu.org
2014-12-19 13:28 ` jakub at gcc dot gnu.org
2015-02-13  8:45 ` mpolacek at gcc dot gnu.org
2015-04-27 17:54 ` [Bug c/61240] [4.8/4.9/5/6 " ktietz at gcc dot gnu.org
2015-06-30 22:49 ` [Bug c/61240] [4.9/5/6 " divyajyotidas15 at gmail dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).