Signed overflow optimization hazards in the kernel
Signed overflow optimization hazards in the kernel
Posted Aug 20, 2012 7:22 UTC (Mon) by jezuch (subscriber, #52988)In reply to: Signed overflow optimization hazards in the kernel by jzbiciak
Parent article: Signed overflow optimization hazards in the kernel
> The compiler wants to know it's safe to assume this loop goes around 16 times. That isn't true if "x + 16" could overflow.
If you want to make it explicit, there's a flag for this in GCC: -funsafe-loop-optimizations (along with -Wunsafe-loop-optimizations if you want to know when it happens; it's a warning, though, so beware of build environments which insist on -Werror). AFACT there are two cases handled by this flag: assuming that the loop counter does not overflow, and assuming that the loop is not infinite. Don't know the exact implementation details, though.
