[Bug c/99268] shifted uint64_t becomes wrong value

jakub at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Thu Feb 25 13:15:28 GMT 2021


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99268

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |INVALID
                 CC|                            |jakub at gcc dot gnu.org
             Status|UNCONFIRMED                 |RESOLVED

--- Comment #1 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
User error, 1 << 31 is undefined behavior in C and even when it is not UB (e.g.
in C++20), the result when int is 32-bit is -2147483647 - 1 (i.e. INT_MIN,
negative value) which when cast to uint64_t is then 0xffffffff80000000ULL.
You could try using -fsanitize=undefined to get it diagnosed at runtime.


More information about the Gcc-bugs mailing list