public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/56917] New: -ftrapv detects a overflow wrongly.
@ 2013-04-11 10:40 akr at fsij dot org
  2014-11-03 12:31 ` [Bug c/56917] " mpolacek at gcc dot gnu.org
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: akr at fsij dot org @ 2013-04-11 10:40 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56917

             Bug #: 56917
           Summary: -ftrapv detects a overflow wrongly.
    Classification: Unclassified
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: akr@fsij.org


Created attachment 29855
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=29855
steps to reproduce the -ftrapv problem

I found that following program aborts with -ftrapv with gcc-4.8.0 on
Debian GNU/Linux (x86_64).

  % cat tst.c
  unsigned long ul = 0x8000000000000000UL;

  int main(int argc, char *argv[])
  {
    long l;
    l = (-(long)(ul-1))-1;
    return 0;
  }
  % /home/src/gcc/bin/gcc -g -ftrapv -Wall tst.c
  tst.c: In function 'main':
  tst.c:5:8: warning: variable 'l' set but not used [-Wunused-but-set-variable]
     long l;
      ^
  % ./a.out 
  zsh: abort (core dumped)  ./a.out

I think it should not abort on x86_64.

Since ul is LONG_MAX+1 (in indefinite precision), ul-1 is LONG_MAX which is
representable in long.
So the cast, (long)(ul-1), doesn't change the value.
Its negation, -(long)(ul-1), is -LONG_MAX which is also representable in long.
Its predecessor, (-(long)(ul-1))-1, is -LONG_MAX-1 = LONG_MIN which is also
representable in long.

gcc-ftrapv-problem-log.txt contains the log with gcc -v.


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

* [Bug c/56917] -ftrapv detects a overflow wrongly.
  2013-04-11 10:40 [Bug c/56917] New: -ftrapv detects a overflow wrongly akr at fsij dot org
@ 2014-11-03 12:31 ` mpolacek at gcc dot gnu.org
  2014-12-03 12:50 ` [Bug middle-end/56917] " mpolacek at gcc dot gnu.org
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2014-11-03 12:31 UTC (permalink / raw)
  To: gcc-bugs

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

Marek Polacek <mpolacek at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2014-11-03
                 CC|                            |mpolacek at gcc dot gnu.org
   Target Milestone|---                         |5.0
     Ever confirmed|0                           |1

--- Comment #1 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Confirmed, this can be seen with ubsan as well.  The issue is that fold changes
-(long int) (ul - 1) - 1
into
(-long int) ul
For e.g. ul = LONG_MAX+1 that shouldn't be done, I'm afraid.


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

* [Bug middle-end/56917] -ftrapv detects a overflow wrongly.
  2013-04-11 10:40 [Bug c/56917] New: -ftrapv detects a overflow wrongly akr at fsij dot org
  2014-11-03 12:31 ` [Bug c/56917] " mpolacek at gcc dot gnu.org
@ 2014-12-03 12:50 ` mpolacek at gcc dot gnu.org
  2014-12-03 12:54 ` mpolacek at gcc dot gnu.org
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2014-12-03 12:50 UTC (permalink / raw)
  To: gcc-bugs

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

Marek Polacek <mpolacek at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED
           Assignee|unassigned at gcc dot gnu.org      |mpolacek at gcc dot gnu.org

--- Comment #2 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Looking into this again.


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

* [Bug middle-end/56917] -ftrapv detects a overflow wrongly.
  2013-04-11 10:40 [Bug c/56917] New: -ftrapv detects a overflow wrongly akr at fsij dot org
  2014-11-03 12:31 ` [Bug c/56917] " mpolacek at gcc dot gnu.org
  2014-12-03 12:50 ` [Bug middle-end/56917] " mpolacek at gcc dot gnu.org
@ 2014-12-03 12:54 ` mpolacek at gcc dot gnu.org
  2014-12-03 12:58 ` rguenth at gcc dot gnu.org
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2014-12-03 12:54 UTC (permalink / raw)
  To: gcc-bugs

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

Marek Polacek <mpolacek at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|5.0                         |4.8.4

--- Comment #3 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Adjusting target.  Happens with 4.8 as well.


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

* [Bug middle-end/56917] -ftrapv detects a overflow wrongly.
  2013-04-11 10:40 [Bug c/56917] New: -ftrapv detects a overflow wrongly akr at fsij dot org
                   ` (2 preceding siblings ...)
  2014-12-03 12:54 ` mpolacek at gcc dot gnu.org
@ 2014-12-03 12:58 ` rguenth at gcc dot gnu.org
  2014-12-04 19:20 ` mpolacek at gcc dot gnu.org
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: rguenth at gcc dot gnu.org @ 2014-12-03 12:58 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Richard Biener <rguenth at gcc dot gnu.org> ---
fold looks too much through sign-changing NOP conversions, this makes it
tricky to spot errors in patterns.


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

* [Bug middle-end/56917] -ftrapv detects a overflow wrongly.
  2013-04-11 10:40 [Bug c/56917] New: -ftrapv detects a overflow wrongly akr at fsij dot org
                   ` (3 preceding siblings ...)
  2014-12-03 12:58 ` rguenth at gcc dot gnu.org
@ 2014-12-04 19:20 ` mpolacek at gcc dot gnu.org
  2014-12-04 19:22 ` mpolacek at gcc dot gnu.org
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2014-12-04 19:20 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Author: mpolacek
Date: Thu Dec  4 19:20:12 2014
New Revision: 218395

URL: https://gcc.gnu.org/viewcvs?rev=218395&root=gcc&view=rev
Log:
    PR middle-end/56917
    * fold-const.c (fold_unary_loc): Perform the negation in A's type
    when transforming ~ (A - 1) or ~ (A + -1) to -A.

    * c-c++-common/ubsan/pr56917.c: New test.

Added:
    trunk/gcc/testsuite/c-c++-common/ubsan/pr56917.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/fold-const.c
    trunk/gcc/testsuite/ChangeLog


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

* [Bug middle-end/56917] -ftrapv detects a overflow wrongly.
  2013-04-11 10:40 [Bug c/56917] New: -ftrapv detects a overflow wrongly akr at fsij dot org
                   ` (4 preceding siblings ...)
  2014-12-04 19:20 ` mpolacek at gcc dot gnu.org
@ 2014-12-04 19:22 ` mpolacek at gcc dot gnu.org
  2015-03-11 10:38 ` mpolacek at gcc dot gnu.org
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2014-12-04 19:22 UTC (permalink / raw)
  To: gcc-bugs

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

Marek Polacek <mpolacek at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|---                         |FIXED

--- Comment #6 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Fixed.


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

* [Bug middle-end/56917] -ftrapv detects a overflow wrongly.
  2013-04-11 10:40 [Bug c/56917] New: -ftrapv detects a overflow wrongly akr at fsij dot org
                   ` (5 preceding siblings ...)
  2014-12-04 19:22 ` mpolacek at gcc dot gnu.org
@ 2015-03-11 10:38 ` mpolacek at gcc dot gnu.org
  2015-06-18 13:04 ` rguenth at gcc dot gnu.org
  2015-06-18 14:47 ` rguenth at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2015-03-11 10:38 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #7 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Author: mpolacek
Date: Wed Mar 11 10:37:38 2015
New Revision: 221346

URL: https://gcc.gnu.org/viewcvs?rev=221346&root=gcc&view=rev
Log:
    Backported from mainline
    2014-12-04  Marek Polacek  <polacek@redhat.com>

    PR middle-end/56917
    * fold-const.c (fold_unary_loc): Perform the negation in A's type
    when transforming ~ (A - 1) or ~ (A + -1) to -A.

    * c-c++-common/ubsan/pr56917.c: New test.

Added:
    branches/gcc-4_9-branch/gcc/testsuite/c-c++-common/ubsan/pr56917.c
Modified:
    branches/gcc-4_9-branch/gcc/ChangeLog
    branches/gcc-4_9-branch/gcc/fold-const.c
    branches/gcc-4_9-branch/gcc/testsuite/ChangeLog


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

* [Bug middle-end/56917] -ftrapv detects a overflow wrongly.
  2013-04-11 10:40 [Bug c/56917] New: -ftrapv detects a overflow wrongly akr at fsij dot org
                   ` (6 preceding siblings ...)
  2015-03-11 10:38 ` mpolacek at gcc dot gnu.org
@ 2015-06-18 13:04 ` rguenth at gcc dot gnu.org
  2015-06-18 14:47 ` rguenth at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: rguenth at gcc dot gnu.org @ 2015-06-18 13:04 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #8 from Richard Biener <rguenth at gcc dot gnu.org> ---
This also fixed a rejects-valid

int lValue;
int main()
{
  switch (lValue)
    {
    case -(int)((2U << (8 * sizeof(int) - 2)) - 1) - 1:;
    }
}

> g++-4.8 cMinLongValue.ii 
cMinLongValue.ii: In function ‘int main()’:
cMinLongValue.ii:6:54: error: overflow in constant expression [-fpermissive]
     case -(int)((2U << (8 * sizeof(int) - 2)) - 1) - 1:;
                                                      ^
cMinLongValue.ii:6:54: error: overflow in constant expression [-fpermissive]

I am going to backport and add this testcase.
>From gcc-bugs-return-489305-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org Thu Jun 18 13:31:55 2015
Return-Path: <gcc-bugs-return-489305-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org>
Delivered-To: listarch-gcc-bugs@gcc.gnu.org
Received: (qmail 103977 invoked by alias); 18 Jun 2015 13:31:54 -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 103917 invoked by uid 55); 18 Jun 2015 13:31:50 -0000
From: "matz at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug middle-end/66253] [6 Regression] 459.GemsFDTD in SPEC CPU 2006 is miscompiled
Date: Thu, 18 Jun 2015 13:31:00 -0000
X-Bugzilla-Reason: CC
X-Bugzilla-Type: changed
X-Bugzilla-Watch-Reason: None
X-Bugzilla-Product: gcc
X-Bugzilla-Component: middle-end
X-Bugzilla-Version: 6.0
X-Bugzilla-Keywords:
X-Bugzilla-Severity: normal
X-Bugzilla-Who: matz at gcc dot gnu.org
X-Bugzilla-Status: ASSIGNED
X-Bugzilla-Resolution:
X-Bugzilla-Priority: P3
X-Bugzilla-Assigned-To: matz at gcc dot gnu.org
X-Bugzilla-Target-Milestone: 6.0
X-Bugzilla-Flags:
X-Bugzilla-Changed-Fields:
Message-ID: <bug-66253-4-wHYRlBkIMk@http.gcc.gnu.org/bugzilla/>
In-Reply-To: <bug-66253-4@http.gcc.gnu.org/bugzilla/>
References: <bug-66253-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: 2015-06/txt/msg01637.txt.bz2
Content-length: 697

https://gcc.gnu.org/bugzilla/show_bug.cgi?idf253

--- Comment #8 from Michael Matz <matz at gcc dot gnu.org> ---
Author: matz
Date: Thu Jun 18 13:31:17 2015
New Revision: 224605

URL: https://gcc.gnu.org/viewcvs?rev"4605&root=gcc&view=rev
Log:
        PR middle-end/66253
        * tree-vect-stmts.c (vectorizable_store): Implement non-SLP
        grouped strided stores.
        (vectorizable_load): Don't use the DR from first_stmt in
        the non-SLP grouped strided case.

testsuite/
        * gcc.dg/vect/pr66253.c: New testcase.

Added:
    trunk/gcc/testsuite/gcc.dg/vect/pr66253.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/tree-vect-stmts.c


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

* [Bug middle-end/56917] -ftrapv detects a overflow wrongly.
  2013-04-11 10:40 [Bug c/56917] New: -ftrapv detects a overflow wrongly akr at fsij dot org
                   ` (7 preceding siblings ...)
  2015-06-18 13:04 ` rguenth at gcc dot gnu.org
@ 2015-06-18 14:47 ` rguenth at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: rguenth at gcc dot gnu.org @ 2015-06-18 14:47 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #9 from Richard Biener <rguenth at gcc dot gnu.org> ---
Author: rguenth
Date: Thu Jun 18 14:47:18 2015
New Revision: 224617

URL: https://gcc.gnu.org/viewcvs?rev=224617&root=gcc&view=rev
Log:
2015-06-18  Richard Biener  <rguenther@suse.de>

        Backport from mainline
        2014-12-04  Marek Polacek  <polacek@redhat.com>

        PR middle-end/56917
        * fold-const.c (fold_unary_loc): Perform the negation in A's type
        when transforming ~ (A - 1) or ~ (A + -1) to -A.

        * g++.dg/other/const4.C: New testcase.

Added:
    branches/gcc-4_8-branch/gcc/testsuite/g++.dg/other/const4.C
Modified:
    branches/gcc-4_8-branch/gcc/ChangeLog
    branches/gcc-4_8-branch/gcc/fold-const.c
    branches/gcc-4_8-branch/gcc/testsuite/ChangeLog


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

end of thread, other threads:[~2015-06-18 14:47 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-04-11 10:40 [Bug c/56917] New: -ftrapv detects a overflow wrongly akr at fsij dot org
2014-11-03 12:31 ` [Bug c/56917] " mpolacek at gcc dot gnu.org
2014-12-03 12:50 ` [Bug middle-end/56917] " mpolacek at gcc dot gnu.org
2014-12-03 12:54 ` mpolacek at gcc dot gnu.org
2014-12-03 12:58 ` rguenth at gcc dot gnu.org
2014-12-04 19:20 ` mpolacek at gcc dot gnu.org
2014-12-04 19:22 ` mpolacek at gcc dot gnu.org
2015-03-11 10:38 ` mpolacek at gcc dot gnu.org
2015-06-18 13:04 ` rguenth at gcc dot gnu.org
2015-06-18 14:47 ` rguenth at gcc dot gnu.org

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).