Octacone wrote:Is this normal behavior?
a) -O2 enabled, ignoring the shell everything is fine
b) -O2 disabled, ignoring the shell it crashes
Normal in the sense that it should happen, likely yes. When you get problems due to optimization changes it's because your doing something "wrong". It's possible, though very unlikely, that it is caused by bugs in the compiler.
Essentially, suppose some code has a null pointer which is used, that should cause a crash, but if the optimizer can deduce that the value from the pointed location is never actually used it may remove that piece of code and thus it no longer crashes. The compiler (and optimizer) is required to maintain "observable behavior"..
So if you do something "wrong" the optimizations may affect the outcome. For instance in some cases optimized code may be smaller, thus execute in less time and thus in some cases it may prevent certain race conditions where the slower non-optimized code would expose it, but this can also work the other way around. So generally it's good to test both debug and non-debug as well as some different optimization levels. If any of them have different behavior then you should always stop and fix those before continuing, otherwise you have nasty surprises waiting that might explode a year later and you have no clue why some completely unrelated piece of new code causes it to break.
Of course everyone has different desires for their project so it depends how far you want to take certain things, including automated builds to build different optimization levels and run automated tests against those. Doing it manually won't work in the long run, but even manually testing other build settings (debug, optimization, etc) occasionally can be useful.