[Bug c++/12812] New: O3 produces wrong result for long long expression

geurts at retarget dot com gcc-bugzilla@gcc.gnu.org
Tue Oct 28 10:53:00 GMT 2003


PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.

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

           Summary: O3 produces wrong result for long long expression
           Product: gcc
           Version: 3.2.3
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: geurts at retarget dot com
                CC: gcc-bugs at gcc dot gnu dot org
  GCC host triplet: hppa2.0w-hp-hpux11.00

Program with long long expressions produces following result on hpux 11
   
   22 184549376

Expected output is 

   0  0

The error occurs when -O3 is specified.

--ab.c----------------------------------------------------------------------
#include <iostream.h>

void foo(long long a, long long b)
{
    long long c = a+b;
    int d = (int(c >> 32)>>23) + (c == 0);   
    int e = int(c >> 32);
    cout << d << ' ' << e << endl;
}

int main()
{
    foo(167772160, 16777216);
    return 0;    
}
------------------------------------------------------------------------------

Compile command is "g++ -O3 ab.c"

Gcc was built as follows:

Reading specs from /usr/gnu/gcc-3.2.3/lib/gcc-lib/hppa2.0w-hp-
hpux11.00/3.2.3/specs
Configured with: ../gcc-3.2.3-src/configure --prefix /usr/gnu/gcc-3.2.3 --with-
gnu-as --with-as=/target/staff/geurts/as --enable-long-long --without-zlib --
with-system-zlib --enable-languages=c,c++ --disable-libgcj --disable-shared
Thread model: single
gcc version 3.2.3



More information about the Gcc-bugs mailing list