This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/84599] following code gives different output for normal compilation and -O2 compiler.


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.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]