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

           Summary: wrong code with -O2 and -O3
           Product: gcc
           Version: 4.5.3
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: [email protected]
        ReportedBy: [email protected]


Created attachment 24472
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=24472
code that leads to wrong compiler output

test.cpp (attached) is code that has been heavily stripped from our
application.
When trying to further strip it, I also stripped the problem.
Compiled with g++ 4.5.x and without -O2 or -O3 it works as expected. 
Compiled with g++ 4.4.6 or 4.6.0 and with -O2 or -O3 it works as expected.
Compiled with g++ 4.5.x and with -O2 or -O3 it doesn't work as expected.

>/usr/local/gcc-4.5.3/bin/g++ -v
Using built-in specs.
COLLECT_GCC=/usr/local/gcc-4.5.3/bin/g++
COLLECT_LTO_WRAPPER=/usr/local/gcc-4.5.3/libexec/gcc/i686-pc-linux-gnu/4.5.3/lto-wrapper
Target: i686-pc-linux-gnu
Configured with: ../gcc-4.5.3/configure --prefix=/usr/local/gcc-4.5.3
Thread model: posix
gcc version 4.5.3 (GCC)
>
>
>/usr/local/gcc-4.5.3/bin/g++ test.cpp -o test
>./test
configuring window #3 to check whether value #1 is in [-3.5..3.5]
setting value #1 to 111
preparations done ...
checking whether value #1 (111) is in window #3 [-3.5..3.5] .. out of window
>
>
>/usr/local/gcc-4.5.3/bin/g++ -O2 test.cpp -o test
>./test
configuring window #3 to check whether value #1 is in [-3.5..3.5]
setting value #1 to 111
preparations done ...
checking whether value #0 (1) is in window #3 [1..1] .. in window
>

("out of window" is the correct answer, we are checking value #1 = 111 which is
not in window #3 having a range of [-3.5..3.5])

Obviously some of the m_pp...[i] pointers or the objects behind get mixed.
Moving line 59 
"unsigned Select = m_ppSelect[i]->get();" 
into the following if scope makes the problem disappear.
While stripping I had a situation where -O3 -fPIC produced the problem and -O3
did not. Unfortunately I can't reconstruct this code any more.

Reply via email to