public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/35140]  New: floating point error in combination with std::list with -O2 optimization turned on
@ 2008-02-08 15:05 basti at fkp dot tu-darmstadt dot de
  2008-02-08 15:29 ` [Bug c++/35140] wrong result due to -O2 optimization in combination with std::list basti at fkp dot tu-darmstadt dot de
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: basti at fkp dot tu-darmstadt dot de @ 2008-02-08 15:05 UTC (permalink / raw)
  To: gcc-bugs

The following program:
//------------------------------------

#include<iostream>
#include<list>

class sample
{
public:
    double criterium;
    sample(double _criterium):criterium(_criterium) {};
}; 


int main(){

  std::list<sample > samples;
  samples.push_back(sample(1.));

  double tmp=0.;

  std::list<sample >::iterator i1;
  i1=samples.begin();   
  tmp=(*i1).criterium; 
  // !!!!!!!!!!!!!!!!!!!!!
  // THIS += operation fails
  (*i1).criterium+=2.; 
  //!!!!!!!!!!!!!!!!!!!!!!!!

  std::cout<<"tmp "<<tmp<<" (*i1).criterium "<<(*i1).criterium <<std::endl; 

  return 0;
}
#----------------

produces the output

tmp 1 (*i1).criterium 1

when compiled with '-O2' or '-O3'
The right output would be 

tmp 1 (*i1).criterium 3

which occurred if compiled with -O1 or without optimization at all. 
The bug was found with the two versions 4.1.2 and 4.1.3 but NOT 
with 3.4.6 and 4.2.1.

In the following you find the output of the compilation with
 g++  -v -save-temps  -O2 

================================================
System 1:
========

Using built-in specs.
Target: i486-linux-gnu
Configured with: ../src/configure -v
--enable-languages=c,c++,fortran,objc,obj-c++,treelang --prefix=/usr
--enable-shared --with-system-zlib --libexecdir=/usr/lib
--without-included-gettext --enable-threads=posix --enable-nls
--program-suffix=-4.1 --enable-__cxa_atexit --enable-clocale=gnu
--enable-libstdcxx-debug --enable-mpfr --with-tune=i686
--enable-checking=release i486-linux-gnu
Thread model: posix
gcc version 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)
 /usr/lib/gcc/i486-linux-gnu/4.1.2/cc1plus -E -quiet -v -D_GNU_SOURCE
tst_short.cpp -mtune=i686 -fworking-directory -O2 -fpch-preprocess -o
tst_short.ii
ignoring nonexistent directory "/usr/local/include/i486-linux-gnu"
ignoring nonexistent directory
"/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../i486-linux-gnu/include"
ignoring nonexistent directory "/usr/include/i486-linux-gnu"
#include "..." search starts here:
#include <...> search starts here:
 /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2
 /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/i486-linux-gnu
 /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/backward
 /usr/local/include
 /usr/lib/gcc/i486-linux-gnu/4.1.2/include
 /usr/include
End of search list.
 /usr/lib/gcc/i486-linux-gnu/4.1.2/cc1plus -fpreprocessed tst_short.ii -quiet
-dumpbase tst_short.cpp -mtune=i686 -auxbase tst_short -g -O2 -version -o
tst_short.s
GNU C++ version 4.1.2 20061115 (prerelease) (Debian 4.1.1-21) (i486-linux-gnu)
        compiled by GNU C version 4.1.2 20061115 (prerelease) (Debian
4.1.1-21).
GGC heuristics: --param ggc-min-expand=99 --param ggc-min-heapsize=129483
Compiler executable checksum: 183d42a838ed2b7313bffcb8f2f2fda7
 as -V -Qy -o tst_short.o tst_short.s
GNU assembler version 2.17 (i486-linux-gnu) using BFD version 2.17 Debian
GNU/Linux
 /usr/lib/gcc/i486-linux-gnu/4.1.2/collect2 --eh-frame-hdr -m elf_i386
-dynamic-linker /lib/ld-linux.so.2 -o tst_short_O2
/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../lib/crt1.o
/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../lib/crti.o
/usr/lib/gcc/i486-linux-gnu/4.1.2/crtbegin.o
-L/usr/lib/gcc/i486-linux-gnu/4.1.2 -L/usr/lib/gcc/i486-linux-gnu/4.1.2
-L/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../lib -L/lib/../lib
-L/usr/lib/../lib tst_short.o -lstdc++ -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc
/usr/lib/gcc/i486-linux-gnu/4.1.2/crtend.o
/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../lib/crtn.o



================================================
System 2:

Using built-in specs.
Target: i486-linux-gnu
Configured with: ../src/configure -v
--enable-languages=c,c++,fortran,objc,obj-c++,treelang --prefix=/usr
--enable-shared --with-system-zlib --libexecdir=/usr/lib
--without-included-gettext --enable-threads=posix --enable-nls
--with-gxx-include-dir=/usr/include/c++/4.1.3 --program-suffix=-4.1
--enable-__cxa_atexit --enable-clocale=gnu --enable-libstdcxx-debug
--enable-mpfr --enable-checking=release i486-linux-gnu
Thread model: posix
gcc version 4.1.3 20070929 (prerelease) (Ubuntu 4.1.2-16ubuntu2)
 /usr/lib/gcc/i486-linux-gnu/4.1.3/cc1plus -E -quiet -v -D_GNU_SOURCE
tst_short.cpp -mtune=generic -fpch-preprocess -o tst_short.ii
ignoring nonexistent directory "/usr/local/include/i486-linux-gnu"
ignoring nonexistent directory
"/usr/lib/gcc/i486-linux-gnu/4.1.3/../../../../i486-linux-gnu/include"
ignoring nonexistent directory "/usr/include/i486-linux-gnu"
#include "..." search starts here:
#include <...> search starts here:
 /usr/include/c++/4.1.3
 /usr/include/c++/4.1.3/i486-linux-gnu
 /usr/include/c++/4.1.3/backward
 /usr/local/include
 /usr/lib/gcc/i486-linux-gnu/4.1.3/include
 /usr/include
End of search list.
 /usr/lib/gcc/i486-linux-gnu/4.1.3/cc1plus -fpreprocessed tst_short.ii -quiet
-dumpbase tst_short.cpp -mtune=generic -auxbase tst_short -version
-fstack-protector -fstack-protector -o tst_short.s
GNU C++ version 4.1.3 20070929 (prerelease) (Ubuntu 4.1.2-16ubuntu2)
(i486-linux-gnu)
        compiled by GNU C version 4.1.3 20070929 (prerelease) (Ubuntu
4.1.2-16ubuntu2).
GGC heuristics: --param ggc-min-expand=64 --param ggc-min-heapsize=64316
Compiler executable checksum: 3cc47be363985179cfafdceddd0e8f5d
 as --traditional-format -V -Qy -o tst_short.o tst_short.s
GNU assembler version 2.18 (i486-linux-gnu) using BFD version (GNU Binutils for
Ubuntu) 2.18
 /usr/lib/gcc/i486-linux-gnu/4.1.3/collect2 --eh-frame-hdr -m elf_i386
--hash-style=both -dynamic-linker /lib/ld-linux.so.2 -o tst_short
/usr/lib/gcc/i486-linux-gnu/4.1.3/../../../../lib/crt1.o
/usr/lib/gcc/i486-linux-gnu/4.1.3/../../../../lib/crti.o
/usr/lib/gcc/i486-linux-gnu/4.1.3/crtbegin.o
-L/usr/lib/gcc/i486-linux-gnu/4.1.3 -L/usr/lib/gcc/i486-linux-gnu/4.1.3
-L/usr/lib/gcc/i486-linux-gnu/4.1.3/../../../../lib -L/lib/../lib
-L/usr/lib/../lib tst_short.o -lstdc++ -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc
/usr/lib/gcc/i486-linux-gnu/4.1.3/crtend.o
/usr/lib/gcc/i486-linux-gnu/4.1.3/../../../../lib/crtn.o


-- 
           Summary: floating point error in combination with std::list with
                    -O2 optimization turned on
           Product: gcc
           Version: 4.1.3
            Status: UNCONFIRMED
          Severity: major
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: basti at fkp dot tu-darmstadt dot de


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


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

* [Bug c++/35140] wrong result due to -O2 optimization in combination with std::list
  2008-02-08 15:05 [Bug c++/35140] New: floating point error in combination with std::list with -O2 optimization turned on basti at fkp dot tu-darmstadt dot de
@ 2008-02-08 15:29 ` basti at fkp dot tu-darmstadt dot de
  2008-02-08 16:07 ` rguenth at gcc dot gnu dot org
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: basti at fkp dot tu-darmstadt dot de @ 2008-02-08 15:29 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from basti at fkp dot tu-darmstadt dot de  2008-02-08 15:28 -------
replacing all doubles types with size_t or int does change nothing.
the bug still exists.


-- 

basti at fkp dot tu-darmstadt dot de changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |basti at fkp dot tu-
                   |                            |darmstadt dot de
      Known to fail|                            |4.1.2 4.1.3
      Known to work|                            |3.4.6 4.2.1
            Summary|floating point error in     |wrong result due to -O2
                   |combination with std::list  |optimization in combination
                   |with -O2 optimization turned|with std::list
                   |on                          |


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


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

* [Bug c++/35140] wrong result due to -O2 optimization in combination with std::list
  2008-02-08 15:05 [Bug c++/35140] New: floating point error in combination with std::list with -O2 optimization turned on basti at fkp dot tu-darmstadt dot de
  2008-02-08 15:29 ` [Bug c++/35140] wrong result due to -O2 optimization in combination with std::list basti at fkp dot tu-darmstadt dot de
@ 2008-02-08 16:07 ` rguenth at gcc dot gnu dot org
  2008-02-08 16:33 ` basti at fkp dot tu-darmstadt dot de
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2008-02-08 16:07 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from rguenth at gcc dot gnu dot org  2008-02-08 16:07 -------
This is possibly a dup of one of the various alias problems of gcc 4.1.
-fno-strict-aliasing is a workaround.


-- 

rguenth at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |rguenth at gcc dot gnu dot
                   |                            |org
           Keywords|                            |alias, wrong-code
      Known to work|3.4.6 4.2.1                 |3.4.6 4.2.1 4.3.0


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


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

* [Bug c++/35140] wrong result due to -O2 optimization in combination with std::list
  2008-02-08 15:05 [Bug c++/35140] New: floating point error in combination with std::list with -O2 optimization turned on basti at fkp dot tu-darmstadt dot de
  2008-02-08 15:29 ` [Bug c++/35140] wrong result due to -O2 optimization in combination with std::list basti at fkp dot tu-darmstadt dot de
  2008-02-08 16:07 ` rguenth at gcc dot gnu dot org
@ 2008-02-08 16:33 ` basti at fkp dot tu-darmstadt dot de
  2008-02-08 22:00 ` bangerth at dealii dot org
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: basti at fkp dot tu-darmstadt dot de @ 2008-02-08 16:33 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from basti at fkp dot tu-darmstadt dot de  2008-02-08 16:32 -------
One can even omit the helper class sample and directly use a list<size_t >,
bug is still there!!! 

the above mentioned work-around with -fno-strict-aliasing works, 
but still...

makes my kinda nervous about all my codes...


-- 


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


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

* [Bug c++/35140] wrong result due to -O2 optimization in combination with std::list
  2008-02-08 15:05 [Bug c++/35140] New: floating point error in combination with std::list with -O2 optimization turned on basti at fkp dot tu-darmstadt dot de
                   ` (2 preceding siblings ...)
  2008-02-08 16:33 ` basti at fkp dot tu-darmstadt dot de
@ 2008-02-08 22:00 ` bangerth at dealii dot org
  2008-02-08 22:21 ` rguenth at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: bangerth at dealii dot org @ 2008-02-08 22:00 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from bangerth at dealii dot org  2008-02-08 21:59 -------
Can this be reproduced with gcc 4.2.x or current mainline?


-- 

bangerth at dealii dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bangerth at dealii dot org


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


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

* [Bug c++/35140] wrong result due to -O2 optimization in combination with std::list
  2008-02-08 15:05 [Bug c++/35140] New: floating point error in combination with std::list with -O2 optimization turned on basti at fkp dot tu-darmstadt dot de
                   ` (3 preceding siblings ...)
  2008-02-08 22:00 ` bangerth at dealii dot org
@ 2008-02-08 22:21 ` rguenth at gcc dot gnu dot org
  2008-02-20 14:43 ` basti at fkp dot tu-darmstadt dot de
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2008-02-08 22:21 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from rguenth at gcc dot gnu dot org  2008-02-08 22:20 -------
Not with this testcase.


-- 


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


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

* [Bug c++/35140] wrong result due to -O2 optimization in combination with std::list
  2008-02-08 15:05 [Bug c++/35140] New: floating point error in combination with std::list with -O2 optimization turned on basti at fkp dot tu-darmstadt dot de
                   ` (4 preceding siblings ...)
  2008-02-08 22:21 ` rguenth at gcc dot gnu dot org
@ 2008-02-20 14:43 ` basti at fkp dot tu-darmstadt dot de
  2008-02-20 14:48 ` rguenth at gcc dot gnu dot org
  2008-12-26 16:14 ` tkoenig at gcc dot gnu dot org
  7 siblings, 0 replies; 9+ messages in thread
From: basti at fkp dot tu-darmstadt dot de @ 2008-02-20 14:43 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #6 from basti at fkp dot tu-darmstadt dot de  2008-02-20 14:42 -------
The bug is not encountered when using the list<> container 
from the stlport-library instead of the one coming with the 
compiler. I tried the versions 4.6, 5.0, and 5.1 
(debian-etch packages libstlport4.6-dev,libstlport5.0-dev,
libstlport5.1-dev) and everything worked fine.

Hope that helps, sebastian

ps: is there any chance this bug is sorted out any time soon, 
or should i switch to a different compiler-version alltogether?


-- 


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


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

* [Bug c++/35140] wrong result due to -O2 optimization in combination with std::list
  2008-02-08 15:05 [Bug c++/35140] New: floating point error in combination with std::list with -O2 optimization turned on basti at fkp dot tu-darmstadt dot de
                   ` (5 preceding siblings ...)
  2008-02-20 14:43 ` basti at fkp dot tu-darmstadt dot de
@ 2008-02-20 14:48 ` rguenth at gcc dot gnu dot org
  2008-12-26 16:14 ` tkoenig at gcc dot gnu dot org
  7 siblings, 0 replies; 9+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2008-02-20 14:48 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #7 from rguenth at gcc dot gnu dot org  2008-02-20 14:47 -------
We should probably admit that we will not fix this bug for GCC 4.1 (there will
be no further release off that branch).  A workaround is to use
-fno-strict-aliasing.

Please consider moving to GCC 4.2.x or 4.3.x once it is released.


-- 


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


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

* [Bug c++/35140] wrong result due to -O2 optimization in combination with std::list
  2008-02-08 15:05 [Bug c++/35140] New: floating point error in combination with std::list with -O2 optimization turned on basti at fkp dot tu-darmstadt dot de
                   ` (6 preceding siblings ...)
  2008-02-20 14:48 ` rguenth at gcc dot gnu dot org
@ 2008-12-26 16:14 ` tkoenig at gcc dot gnu dot org
  7 siblings, 0 replies; 9+ messages in thread
From: tkoenig at gcc dot gnu dot org @ 2008-12-26 16:14 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #8 from tkoenig at gcc dot gnu dot org  2008-12-26 16:11 -------
Works with current trunk, 4.1 is no longer maintained.

Closing.


-- 

tkoenig at gcc dot gnu dot org changed:

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


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


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

end of thread, other threads:[~2008-12-26 16:14 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-02-08 15:05 [Bug c++/35140] New: floating point error in combination with std::list with -O2 optimization turned on basti at fkp dot tu-darmstadt dot de
2008-02-08 15:29 ` [Bug c++/35140] wrong result due to -O2 optimization in combination with std::list basti at fkp dot tu-darmstadt dot de
2008-02-08 16:07 ` rguenth at gcc dot gnu dot org
2008-02-08 16:33 ` basti at fkp dot tu-darmstadt dot de
2008-02-08 22:00 ` bangerth at dealii dot org
2008-02-08 22:21 ` rguenth at gcc dot gnu dot org
2008-02-20 14:43 ` basti at fkp dot tu-darmstadt dot de
2008-02-20 14:48 ` rguenth at gcc dot gnu dot org
2008-12-26 16:14 ` tkoenig at gcc dot gnu dot org

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).