[Bug c/124223] Cast (int32_t)0x80000000 causes the whole loop to be optimized away
redi at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Tue Feb 24 11:11:19 GMT 2026
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=124223
--- Comment #12 from Jonathan Wakely <redi at gcc dot gnu.org> ---
That's not undefined. It very clearly says "implementation-defined", not
undefined.
GCC defines it here:
https://gcc.gnu.org/onlinedocs/gcc/Integers-implementation.html
"For conversion to a type of width N, the value is reduced modulo 2^N to be
within range of the type; no signal is raised."
So no, doing unsigned arithmetic and then converting to a signed type is not
equally undefined, it's fine.
More information about the Gcc-bugs
mailing list