https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83133
--- Comment #13 from Maxim Egorushkin <maxim.yegorushkin at gmail dot com> --- (In reply to Uroš Bizjak from comment #9) > (In reply to Maxim Egorushkin from comment #6) > > > This code underflows a signed integer, which is undefined behaviour, if I am > > not mistaken. So, this would not be a valid example, would it? > > An example of "dangerous optimization" from Comment #2 was requested. The > optimization is valid, but this code happens as well. As shown in the > example, the program, compiled with clang declared 2147483647 as nonpositive > when compiled with -O2 and as positive when compiled with -O0. > > We can sweep the issue under the carpet as "undefined behaviour", but I > don't want to jeopardize the robustness of an industrial-strength compiler > with the implementation of this relatively minor optimization. It looks like -fstrict-overflow flag is there to enable exactly this kind of optimization.