------- Comment #23 from sergstesh at yahoo dot com 2008-01-21 05:07 ------- It's too bad the bug is closed just as a duplicate of another bug.
The main points of this bug are: 1) the code triggering the bug uses undefined in "C" standards language features - behavior in case of integer overflow + signed <-> unsigned comparison; 2) "C" standard is not the only standard having some cases undefined - whenever compiler developers face an undefined case they should somehow define the case themselves and publish their definition/decision; 3) it's very desirable for the compiler developers to be consistent, i.e. whenever the undefined by standard case is encountered, the compiler behaves the same way, i.e. produces code implementing the same algorithm; 4) I do see consistency in gcc-3.4.6, gcc-4.1.2 - regardless of -O1 vs -O2 generated by gcc code functionally behaves the same way; 5) gcc-4.2.x shows lack of consistency - -O1 code behaves differently compared to -O2 one. It's a pity that newer gcc versions are less consistent than the old ones. As I suggested earlier, the cleanest solution would be _not_ to perform optimization on unclean code, thus ensuring consistency. -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34841