This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/84599] following code gives different output for normal compilation and -O2 compiler.
- From: "dmalcolm at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Tue, 27 Feb 2018 17:58:49 +0000
- Subject: [Bug c++/84599] following code gives different output for normal compilation and -O2 compiler.
- Auto-submitted: auto-generated
- References: <bug-84599-4@http.gcc.gnu.org/bugzilla/>
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.