public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/45164]  New: -O3 optimization problematic on "long long" types near 64 bit wraparound
@ 2010-08-02 16:46 robots at marcabel dot com
  2010-08-02 16:47 ` [Bug c/45164] " robots at marcabel dot com
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: robots at marcabel dot com @ 2010-08-02 16:46 UTC (permalink / raw)
  To: gcc-bugs

Here is a small test case, with output and version information in the comments.

There are enough ways of stating this problem that it was not evident to me
within the existing bug list.  One skilled in the art would know if this is a
duplicate.

I'm not sure where to upload my .i file, so I will try to attach it a few
minutes after I post this.

-------

/*
 *  Illustration of GCC bug
 *  Marc W. Abel, August 2, 2010
 *
 *  gcc version information follows
 *  ------------------------------------
 *  Using built-in specs.
 *  Target: x86_64-linux-gnu
 *  Configured with: ../src/configure -v --with-pkgversion='Ubuntu
4.4.3-4ubuntu5' --with-bugurl=file:///usr/share/doc/gcc-4.4/README.Bugs
--enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --enable-shared
--enable-multiarch --enable-linker-build-id --with-system-zlib
--libexecdir=/usr/lib --without-included-gettext --enable-threads=posix
--with-gxx-include-dir=/usr/include/c++/4.4 --program-suffix=-4.4 --enable-nls
--enable-clocale=gnu --enable-libstdcxx-debug --enable-plugin --enable-objc-gc
--disable-werror --with-arch-32=i486 --with-tune=generic
--enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu
--target=x86_64-linux-gnu
 *  Thread model: posix
 *  gcc version 4.4.3 (Ubuntu 4.4.3-4ubuntu5) 
 *  ------------------------------------
 *
 *  Invocation and correct output (using -O2):
 *
 *  $ gcc -O2 o3bug.c && ./a.out | head -n 6
 *  7ffffffffffffffd fdffffffffffff7f
 *  7ffffffffffffffe feffffffffffff7f
 *  7fffffffffffffff ffffffffffffff7f
 *  8000000000000000 0000000000000080
 *  8000000000000001 0100000000000080
 *  8000000000000002 0200000000000080
 *
 *  Invocation and incorrect output (using -O3):
 *
 *  $ gcc -O3 o3bug.c && ./a.out | head -n 6
 *  7ffffffffffffffd fdffffffffffff7f
 *  7ffffffffffffffe feffffffffffff7f
 *  7fffffffffffffff ffffffffffffff7f
 *  8000000000000000 100ffffffffffff7f
 *  8000000000000001 101ffffffffffff7f
 *  8000000000000002 102ffffffffffff7f
 */

#include <stdio.h>

/*
 *  Convert an integer into an eight-byte format for persistance, LSB first.
 */
static void int_to_persist(unsigned char *eight_bytes, long long n)
{
        int i;

        for (i=0; i<8; i++, n >>= 8)
                eight_bytes[i] = n & 255u;
}

int main(int argc, char *argv[])
{
        unsigned char bytes[8];
        int i;
        long long m;

        for (m = 0x7ffffffffffffffdLL; ; ++m) {
                printf("%llx ", m);

                int_to_persist(bytes, m);
                for (i=0; i<8; i++)
                        printf("%02x", bytes[i]);
                printf("\n");
        }
}


-- 
           Summary: -O3 optimization problematic on "long long" types near
                    64 bit wraparound
           Product: gcc
           Version: 4.4.3
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: robots at marcabel dot com


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


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

* [Bug c/45164] -O3 optimization problematic on "long long" types near 64 bit wraparound
  2010-08-02 16:46 [Bug c/45164] New: -O3 optimization problematic on "long long" types near 64 bit wraparound robots at marcabel dot com
@ 2010-08-02 16:47 ` robots at marcabel dot com
  2010-08-02 16:48 ` pinskia at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: robots at marcabel dot com @ 2010-08-02 16:47 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from robots at marcabel dot com  2010-08-02 16:47 -------
Created an attachment (id=21371)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=21371&action=view)
Preprocessor output / compiler input


-- 


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


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

* [Bug c/45164] -O3 optimization problematic on "long long" types near 64 bit wraparound
  2010-08-02 16:46 [Bug c/45164] New: -O3 optimization problematic on "long long" types near 64 bit wraparound robots at marcabel dot com
  2010-08-02 16:47 ` [Bug c/45164] " robots at marcabel dot com
  2010-08-02 16:48 ` pinskia at gcc dot gnu dot org
@ 2010-08-02 16:48 ` robots at marcabel dot com
  2010-08-02 16:54 ` robots at marcabel dot com
  3 siblings, 0 replies; 5+ messages in thread
From: robots at marcabel dot com @ 2010-08-02 16:48 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from robots at marcabel dot com  2010-08-02 16:48 -------
Created an attachment (id=21372)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=21372&action=view)
Source code to produce

in case it doesn't paste well from my initial report.


-- 


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


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

* [Bug c/45164] -O3 optimization problematic on "long long" types near 64 bit wraparound
  2010-08-02 16:46 [Bug c/45164] New: -O3 optimization problematic on "long long" types near 64 bit wraparound robots at marcabel dot com
  2010-08-02 16:47 ` [Bug c/45164] " robots at marcabel dot com
@ 2010-08-02 16:48 ` pinskia at gcc dot gnu dot org
  2010-08-02 16:48 ` robots at marcabel dot com
  2010-08-02 16:54 ` robots at marcabel dot com
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2010-08-02 16:48 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from pinskia at gcc dot gnu dot org  2010-08-02 16:48 -------
Signed overflow is undefined; use either unsigned or -fwrapv to get the
behavior you want.


-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID


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


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

* [Bug c/45164] -O3 optimization problematic on "long long" types near 64 bit wraparound
  2010-08-02 16:46 [Bug c/45164] New: -O3 optimization problematic on "long long" types near 64 bit wraparound robots at marcabel dot com
                   ` (2 preceding siblings ...)
  2010-08-02 16:48 ` robots at marcabel dot com
@ 2010-08-02 16:54 ` robots at marcabel dot com
  3 siblings, 0 replies; 5+ messages in thread
From: robots at marcabel dot com @ 2010-08-02 16:54 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from robots at marcabel dot com  2010-08-02 16:54 -------
Confirmed resolved invalid.  Thank you!


-- 


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


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

end of thread, other threads:[~2010-08-02 16:54 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-08-02 16:46 [Bug c/45164] New: -O3 optimization problematic on "long long" types near 64 bit wraparound robots at marcabel dot com
2010-08-02 16:47 ` [Bug c/45164] " robots at marcabel dot com
2010-08-02 16:48 ` pinskia at gcc dot gnu dot org
2010-08-02 16:48 ` robots at marcabel dot com
2010-08-02 16:54 ` robots at marcabel 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).