3 ms·
> it's not a bug It's not a bug in what? The compiler or the input program? [The answer is, the compiler is fine, the input program has undefined behavior.] >
by tom_mellior 9y ago
> it's not a bug
It's not a bug in what? The compiler or the input program? [The answer is, the compiler is fine, the input program has undefined behavior.]
> without optimization it doesn't happen
That's fine. As the input program has undefined behavior, the compiler is free to compile it differently at different optimization levels.
- phkahler 9y agoI've seen plenty of people blame the optimizer for bugs in their code. This is especially common with people doing embedded stuff when they don't understand the "volatile" keyword. Just because it works without optimization doesn't mean your code is correct. Some of them will insist on not using the optimizer because it can introduce bugs. I take the opposite attitude - let's go with -o3 from day one because we'll eventually run out of CPU time and have to turn it on anyway. If that uncovers bugs in the code or compiler it's better to find them early.