public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/51962] New: Compiling with -O3 and using the same input produces a different result
@ 2012-01-23 11:23 mario.achkar at gmail dot com
  2012-01-23 11:25 ` [Bug c++/51962] " redi at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: mario.achkar at gmail dot com @ 2012-01-23 11:23 UTC (permalink / raw)
  To: gcc-bugs

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

             Bug #: 51962
           Summary: Compiling with -O3 and using the same input produces a
                    different result
    Classification: Unclassified
           Product: gcc
           Version: 4.6.2
            Status: UNCONFIRMED
          Severity: critical
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: mario.achkar@gmail.com


Created attachment 26423
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=26423
The simple C++ code that causes the "bug".

Compile the following simple code without -O3, and run.

Now compile it with -O3 option (for optimization), run again.

Surprisingly 2 different outputs appear.

I have made the program as minimal as possible and traced back the error to the
following line:

if (((k-x[j])*(k-x[j])+(y[j]-ya)*(y[j]-ya))<=r[j]*r[j]) { found1 = true; } 
(line 17 in the code)

Comment this and the problem is solved.

This caused a huge problem that took me around an hour to figure out that it
was related to compiler optimization. I have provided the simplest case I could
find causing the error.

Thank you for your time and hope you fix it soon.
Please keep me updated.


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

* [Bug c++/51962] Compiling with -O3 and using the same input produces a different result
  2012-01-23 11:23 [Bug c++/51962] New: Compiling with -O3 and using the same input produces a different result mario.achkar at gmail dot com
@ 2012-01-23 11:25 ` redi at gcc dot gnu.org
  2012-01-23 11:33 ` mario.achkar at gmail dot com
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: redi at gcc dot gnu.org @ 2012-01-23 11:25 UTC (permalink / raw)
  To: gcc-bugs

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

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|critical                    |normal

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> 2012-01-23 11:19:39 UTC ---
You do not initialise found1.  Set that to false and your problem probably goes
away.


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

* [Bug c++/51962] Compiling with -O3 and using the same input produces a different result
  2012-01-23 11:23 [Bug c++/51962] New: Compiling with -O3 and using the same input produces a different result mario.achkar at gmail dot com
  2012-01-23 11:25 ` [Bug c++/51962] " redi at gcc dot gnu.org
@ 2012-01-23 11:33 ` mario.achkar at gmail dot com
  2012-01-23 11:43 ` mario.achkar at gmail dot com
  2012-01-23 11:47 ` redi at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: mario.achkar at gmail dot com @ 2012-01-23 11:33 UTC (permalink / raw)
  To: gcc-bugs

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

Mario Achkar <mario.achkar at gmail dot com> changed:

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

--- Comment #2 from Mario Achkar <mario.achkar at gmail dot com> 2012-01-23 11:24:54 UTC ---
yes you are right. That was hard to find. It's weird though how both work
differently when it comes to this.


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

* [Bug c++/51962] Compiling with -O3 and using the same input produces a different result
  2012-01-23 11:23 [Bug c++/51962] New: Compiling with -O3 and using the same input produces a different result mario.achkar at gmail dot com
  2012-01-23 11:25 ` [Bug c++/51962] " redi at gcc dot gnu.org
  2012-01-23 11:33 ` mario.achkar at gmail dot com
@ 2012-01-23 11:43 ` mario.achkar at gmail dot com
  2012-01-23 11:47 ` redi at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: mario.achkar at gmail dot com @ 2012-01-23 11:43 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Mario Achkar <mario.achkar at gmail dot com> 2012-01-23 11:27:48 UTC ---
(In reply to comment #1)
> You do not initialise found1.  Set that to false and your problem probably goes
> away.
Thanks for the fast reply.


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

* [Bug c++/51962] Compiling with -O3 and using the same input produces a different result
  2012-01-23 11:23 [Bug c++/51962] New: Compiling with -O3 and using the same input produces a different result mario.achkar at gmail dot com
                   ` (2 preceding siblings ...)
  2012-01-23 11:43 ` mario.achkar at gmail dot com
@ 2012-01-23 11:47 ` redi at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: redi at gcc dot gnu.org @ 2012-01-23 11:47 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Jonathan Wakely <redi at gcc dot gnu.org> 2012-01-23 11:33:39 UTC ---
It was very easy to find using valgrind, or a static analysis tool.


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

end of thread, other threads:[~2012-01-23 11:33 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-01-23 11:23 [Bug c++/51962] New: Compiling with -O3 and using the same input produces a different result mario.achkar at gmail dot com
2012-01-23 11:25 ` [Bug c++/51962] " redi at gcc dot gnu.org
2012-01-23 11:33 ` mario.achkar at gmail dot com
2012-01-23 11:43 ` mario.achkar at gmail dot com
2012-01-23 11:47 ` redi at gcc dot gnu.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).