[Bug c++/69355] New: Wrong results with -O1 optimization

andreas.hilti at hotmail dot com gcc-bugzilla@gcc.gnu.org
Tue Jan 19 10:08:00 GMT 2016


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

            Bug ID: 69355
           Summary: Wrong results with -O1 optimization
           Product: gcc
           Version: 5.3.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: andreas.hilti at hotmail dot com
  Target Milestone: ---

Consider the following program: It reads in a Vector, normalizes it, and
outputs it.

typedef tvmet::Vector<double, 3> Vector;

int main(){
 Vector v1;
 v1 = 1,2,3;
 Vector r;
 r = v1/norm2(v1);
 std::cout << r;
}

The compiler version is:
gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/5.3.1/lto-wrapper
Target: x86_64-redhat-linux
Configured with: ../configure --enable-bootstrap
--enable-languages=c,c++,objc,obj-c++,fortran,ada,go,lto --prefix=/usr
--mandir=/usr/share/man --infodir=/usr/share/info
--with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-shared
--enable-threads=posix --enable-checking=release --enable-multilib
--with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions
--enable-gnu-unique-object --enable-linker-build-id
--with-linker-hash-style=gnu --enable-plugin --enable-initfini-array
--disable-libgcj --with-default-libstdcxx-abi=gcc4-compatible --with-isl
--enable-libmpx --enable-gnu-indirect-function --with-tune=generic
--with-arch_32=i686 --build=x86_64-redhat-linux
Thread model: posix
gcc version 5.3.1 20151207 (Red Hat 5.3.1-2) (GCC) 

With -O1, it results in the incorrect result:

g++ -O1 mytest.cpp -I../include -save-temps
(no output)
(the preprocessed file is attached)

./a.out 
[
  inf, inf, inf
]


With -O0, it results in the correct result:

g++ -O0 mytest.cpp -I../include
(no output)

./a.out
[
  0.267261, 0.534522, 0.801784
]

The same behaviour can also be observed using g++ 5.2.1.
With g++ 4.8.4 and 4.9.2, it leads to the correct result with -O1 and -O0.

P.S. This is my first bug report; I'm sorry if I anything is wrong/missing.


More information about the Gcc-bugs mailing list