https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69984
--- Comment #5 from Jakub Jelinek <jakub at gcc dot gnu.org> --- Even if the computation is 32-bit, by the time you multiply say (unsigned short int) 0xffff with itself, you get undefined behavior. So, as has been said, if you want to perform the multiplication in unsigned long or unsigned int, you need to cast one of the operands.