public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/61158] New: negative shift at fold-const.c:12095
@ 2014-05-12 18:03 zeccav at gmail dot com
  2014-05-13 18:10 ` [Bug middle-end/61158] " mpolacek at gcc dot gnu.org
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: zeccav at gmail dot com @ 2014-05-12 18:03 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 61158
           Summary: negative shift at fold-const.c:12095
           Product: gcc
           Version: 4.9.1
            Status: UNCONFIRMED
          Severity: minor
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: zeccav at gmail dot com

Compilation of the following forces a negative shift, result undefined in my
opinion 
/* gcc -S negative shift at fold-const.c:12095
 * x86_64
 * "zerobits <<= prec - shiftc;"
 * because prec - shiftc = -8
 * result is undefined 
 * compiling Linux Fedora 20 source code kernel/trace/blktrace.c
 * checked with "gcc_assert(prec >= shiftc && prec-shiftc <
HOST_BITS_PER_WIDE_INT);" immediately before
*/
typedef unsigned long long __u64;
void blk_add_trace_unplug(unsigned int depth)
{
((__u64)(depth) & (__u64)0x00ff000000000000ULL) >> 40;
}


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

* [Bug middle-end/61158] negative shift at fold-const.c:12095
  2014-05-12 18:03 [Bug c/61158] New: negative shift at fold-const.c:12095 zeccav at gmail dot com
@ 2014-05-13 18:10 ` mpolacek at gcc dot gnu.org
  2014-05-14  5:19 ` zeccav at gmail dot com
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2014-05-13 18:10 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |mpolacek at gcc dot gnu.org
          Component|c                           |middle-end

--- Comment #1 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
prec and shiftc are both unsigned, so it's not -8, but some huge number.  That
indeed looks like a bug.  This code was added in r130589.


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

* [Bug middle-end/61158] negative shift at fold-const.c:12095
  2014-05-12 18:03 [Bug c/61158] New: negative shift at fold-const.c:12095 zeccav at gmail dot com
  2014-05-13 18:10 ` [Bug middle-end/61158] " mpolacek at gcc dot gnu.org
@ 2014-05-14  5:19 ` zeccav at gmail dot com
  2014-05-14 10:08 ` mpolacek at gcc dot gnu.org
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: zeccav at gmail dot com @ 2014-05-14  5:19 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Vittorio Zecca <zeccav at gmail dot com> ---
I found this one with -fsanitize=shift. The runtime error message says
"shift exponent -8 is negative". Maybe this is also a sanitizer bug?


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

* [Bug middle-end/61158] negative shift at fold-const.c:12095
  2014-05-12 18:03 [Bug c/61158] New: negative shift at fold-const.c:12095 zeccav at gmail dot com
  2014-05-13 18:10 ` [Bug middle-end/61158] " mpolacek at gcc dot gnu.org
  2014-05-14  5:19 ` zeccav at gmail dot com
@ 2014-05-14 10:08 ` mpolacek at gcc dot gnu.org
  2014-05-14 10:40 ` jakub at gcc dot gnu.org
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2014-05-14 10:08 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
(In reply to Vittorio Zecca from comment #2)
> I found this one with -fsanitize=shift. The runtime error message says
> "shift exponent -8 is negative". Maybe this is also a sanitizer bug?

Yeah, I opened PR61185.


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

* [Bug middle-end/61158] negative shift at fold-const.c:12095
  2014-05-12 18:03 [Bug c/61158] New: negative shift at fold-const.c:12095 zeccav at gmail dot com
                   ` (2 preceding siblings ...)
  2014-05-14 10:08 ` mpolacek at gcc dot gnu.org
@ 2014-05-14 10:40 ` jakub at gcc dot gnu.org
  2014-05-15 10:01 ` jakub at gcc dot gnu.org
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: jakub at gcc dot gnu.org @ 2014-05-14 10:40 UTC (permalink / raw)
  To: gcc-bugs

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |ASSIGNED
   Last reconfirmed|                            |2014-05-14
                 CC|                            |jakub at gcc dot gnu.org
           Assignee|unassigned at gcc dot gnu.org      |jakub at gcc dot gnu.org
     Ever confirmed|0                           |1

--- Comment #4 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Created attachment 32795
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=32795&action=edit
gcc49-pr61158.patch

Untested fix.  If prec >= shiftc, then the result is always 0, as we shift away
all the possibly non-zero bits.  Therefore, we should just optimize it into (X,
0).


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

* [Bug middle-end/61158] negative shift at fold-const.c:12095
  2014-05-12 18:03 [Bug c/61158] New: negative shift at fold-const.c:12095 zeccav at gmail dot com
                   ` (3 preceding siblings ...)
  2014-05-14 10:40 ` jakub at gcc dot gnu.org
@ 2014-05-15 10:01 ` jakub at gcc dot gnu.org
  2014-05-15 10:08 ` jakub at gcc dot gnu.org
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: jakub at gcc dot gnu.org @ 2014-05-15 10:01 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Author: jakub
Date: Thu May 15 10:01:11 2014
New Revision: 210467

URL: http://gcc.gnu.org/viewcvs?rev=210467&root=gcc&view=rev
Log:
    PR tree-optimization/61158
    * fold-const.c (fold_binary_loc): If X is zero-extended and
    shiftc >= prec, make sure zerobits is all ones instead of
    invoking undefined behavior.

    * gcc.dg/pr61158.c: New test.

Added:
    trunk/gcc/testsuite/gcc.dg/pr61158.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/fold-const.c
    trunk/gcc/testsuite/ChangeLog


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

* [Bug middle-end/61158] negative shift at fold-const.c:12095
  2014-05-12 18:03 [Bug c/61158] New: negative shift at fold-const.c:12095 zeccav at gmail dot com
                   ` (4 preceding siblings ...)
  2014-05-15 10:01 ` jakub at gcc dot gnu.org
@ 2014-05-15 10:08 ` jakub at gcc dot gnu.org
  2014-05-15 10:08 ` jakub at gcc dot gnu.org
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: jakub at gcc dot gnu.org @ 2014-05-15 10:08 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #7 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Author: jakub
Date: Thu May 15 10:08:12 2014
New Revision: 210469

URL: http://gcc.gnu.org/viewcvs?rev=210469&root=gcc&view=rev
Log:
    PR tree-optimization/61158
    * fold-const.c (fold_binary_loc): If X is zero-extended and
    shiftc >= prec, make sure zerobits is all ones instead of
    invoking undefined behavior.

    * gcc.dg/pr61158.c: New test.

Added:
    branches/gcc-4_9-branch/gcc/testsuite/gcc.dg/pr61158.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] 11+ messages in thread

* [Bug middle-end/61158] negative shift at fold-const.c:12095
  2014-05-12 18:03 [Bug c/61158] New: negative shift at fold-const.c:12095 zeccav at gmail dot com
                   ` (5 preceding siblings ...)
  2014-05-15 10:08 ` jakub at gcc dot gnu.org
@ 2014-05-15 10:08 ` jakub at gcc dot gnu.org
  2014-09-06 17:13 ` danglin at gcc dot gnu.org
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: jakub at gcc dot gnu.org @ 2014-05-15 10:08 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Fixed for 4.9.1+ so far.


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

* [Bug middle-end/61158] negative shift at fold-const.c:12095
  2014-05-12 18:03 [Bug c/61158] New: negative shift at fold-const.c:12095 zeccav at gmail dot com
                   ` (6 preceding siblings ...)
  2014-05-15 10:08 ` jakub at gcc dot gnu.org
@ 2014-09-06 17:13 ` danglin at gcc dot gnu.org
  2014-09-06 18:01 ` danglin at gcc dot gnu.org
  2021-02-21  7:51 ` zeccav at gmail dot com
  9 siblings, 0 replies; 11+ messages in thread
From: danglin at gcc dot gnu.org @ 2014-09-06 17:13 UTC (permalink / raw)
  To: gcc-bugs

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

John David Anglin <danglin at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |danglin at gcc dot gnu.org

--- Comment #8 from John David Anglin <danglin at gcc dot gnu.org> ---
gcc.dg/pr61158.c fails on hppa2.0w-hp-hpux11.11 on 4.9 branch:

spawn /mnt/gnu/gcc/objdir-test/gcc/xgcc -B/mnt/gnu/gcc/objdir-test/gcc/
/mnt/gnu
/gcc/gcc/gcc/testsuite/gcc.dg/pr61158.c -fno-diagnostics-show-caret
-fdiagnostic
s-color=never -O2 -fdump-tree-original -S -o pr61158.s
PASS: gcc.dg/pr61158.c (test for excess errors)
FAIL: gcc.dg/pr61158.c scan-tree-dump original "return 0;"

This is tree dump:

# less pr61158.c.003t.original

;; Function foo (null)
;; enabled by -tree-original


{
  return ((long long unsigned int) x & 71776119061217280) >> 40;
}


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

* [Bug middle-end/61158] negative shift at fold-const.c:12095
  2014-05-12 18:03 [Bug c/61158] New: negative shift at fold-const.c:12095 zeccav at gmail dot com
                   ` (7 preceding siblings ...)
  2014-09-06 17:13 ` danglin at gcc dot gnu.org
@ 2014-09-06 18:01 ` danglin at gcc dot gnu.org
  2021-02-21  7:51 ` zeccav at gmail dot com
  9 siblings, 0 replies; 11+ messages in thread
From: danglin at gcc dot gnu.org @ 2014-09-06 18:01 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #9 from John David Anglin <danglin at gcc dot gnu.org> ---
It looks like the test fails because HOST_BITS_PER_WIDE_INT is
32 on hppa2.0w-hp-hpux11.11.  As a result, the fold optimization
doesn't occur.


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

* [Bug middle-end/61158] negative shift at fold-const.c:12095
  2014-05-12 18:03 [Bug c/61158] New: negative shift at fold-const.c:12095 zeccav at gmail dot com
                   ` (8 preceding siblings ...)
  2014-09-06 18:01 ` danglin at gcc dot gnu.org
@ 2021-02-21  7:51 ` zeccav at gmail dot com
  9 siblings, 0 replies; 11+ messages in thread
From: zeccav at gmail dot com @ 2021-02-21  7:51 UTC (permalink / raw)
  To: gcc-bugs

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

Vittorio Zecca <zeccav at gmail dot com> changed:

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

--- Comment #10 from Vittorio Zecca <zeccav at gmail dot com> ---
Resolved.

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

end of thread, other threads:[~2021-02-21  7:51 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-05-12 18:03 [Bug c/61158] New: negative shift at fold-const.c:12095 zeccav at gmail dot com
2014-05-13 18:10 ` [Bug middle-end/61158] " mpolacek at gcc dot gnu.org
2014-05-14  5:19 ` zeccav at gmail dot com
2014-05-14 10:08 ` mpolacek at gcc dot gnu.org
2014-05-14 10:40 ` jakub at gcc dot gnu.org
2014-05-15 10:01 ` jakub at gcc dot gnu.org
2014-05-15 10:08 ` jakub at gcc dot gnu.org
2014-05-15 10:08 ` jakub at gcc dot gnu.org
2014-09-06 17:13 ` danglin at gcc dot gnu.org
2014-09-06 18:01 ` danglin at gcc dot gnu.org
2021-02-21  7:51 ` zeccav 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).