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

2016-01-19 Thread andreas.hilti at hotmail dot com
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 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.

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

2016-01-19 Thread andreas.hilti at hotmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69355

--- Comment #1 from Andreas Hiltebrand  ---
Created attachment 37392
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=37392&action=edit
the preprocessed file

The attachment was slightly too large, you can download it from:

https://www.dropbox.com/s/trtu01978cb4hsi/mytest.ii?dl=0

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

2016-01-19 Thread andreas.hilti at hotmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69355

--- Comment #3 from Andreas Hiltebrand  ---
I'm sorry. I did not zip it as the guidelines said explicitly:

What we do not want
[...]
An attached archive (tar, zip, shar, whatever) containing all (or some :-) of
the above.

and the preprocessed file is mentioned above. Thanks for fixing it.