public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "Keith.S.Thompson at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
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	[thread overview]
Message-ID: <bug-61240-4@http.gcc.gnu.org/bugzilla/> (raw)

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.


             reply	other threads:[~2014-05-19 23:10 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-05-19 23:10 Keith.S.Thompson at gmail dot com [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-61240-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).