[Bug c++/51962] New: Compiling with -O3 and using the same input produces a different result

2012-01-23 Thread mario.achkar at gmail dot com
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: unassig...@gcc.gnu.org
ReportedBy: mario.ach...@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.


[Bug c++/51962] Compiling with -O3 and using the same input produces a different result

2012-01-23 Thread mario.achkar at gmail dot com
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.


[Bug c++/51962] Compiling with -O3 and using the same input produces a different result

2012-01-23 Thread mario.achkar at gmail dot com
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.