https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84599
David Malcolm <dmalcolm at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|UNCONFIRMED |RESOLVED CC| |dmalcolm at gcc dot gnu.org Resolution|--- |INVALID --- Comment #2 from David Malcolm <dmalcolm at gcc dot gnu.org> --- Without optimization, -fsanitize=undefined shows: /tmp/t.c:13:22: runtime error: signed integer overflow: 968551222 * 3 cannot be represented in type 'int' With -O2, -fsanitize=undefined shows: /tmp/t.c:13:22: runtime error: signed integer overflow: 968551222 * 3 cannot be represented in type 'int' /tmp/t.c:13:22: runtime error: signed integer overflow: 1143237676 * 3 cannot be represented in type 'int' Looks like it's the * 3 within: mSeed = mSeed * 3 + 1; and hence the code is relying on the behavior of that overflow, which optimization is allowed to change.