Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

My experience goes in a different direction: when you see different behavior when compiled with and without optimization, suspect a memory allocation error or overrun. While compiler optimization bugs do exist, I've more often found that the problem is real.

If you are working with your own code and care if it works:

  1) Turn on all compiler warnings
  2) Change your code so it compiles clean
  3) Run under Valgrind (or equivalent).
  4) Address all reported errors, specifically 
     whitelisting them if necessary.
  5) If you find a bug, don't stop until you've found
     the cause.  You're done when you understand what
     caused the bug to appear, not when the symptoms go away. 
  6) Use open source tools, since otherwise you'll be
     tempted to blame some unspecified 'bug in the compiler'.
     (not that ESR would be using any other)
  7) If it is a compiler bug, report it, along with 
     the smallest test case you can generate.


This is definitely along the right path. One proviso that I'd note: Most of the time in my own debugging when I've run into something that goes away at a different level of optimization it's uninitialized variables / memory. Valgrind is the shizzle.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: