Some fun with -O2

Thierry Thomas thierry at freebsd.org
Thu Jan 14 12:17:51 UTC 2021


Le jeu. 14 janv. 21 à 12:44:34 +0100, Konstantin Belousov <kostikbel at gmail.com>
 écrivait :

> There is no fun with this stuff.
> 
> The time_t type is signed, then the loop
>   for (time_t_max = 1; 0 < time_t_max; time_t_max *= 2)
>     continue;
> intent is to get signed overflow, which is UB.  Modern compilers prefer to
> shoot into your foot instead of following common sense.
> 
> Workaround is to add -fwrapv compiler switch.

Indeed, but the fun part is the different behaviour with / without -O2.
-- 
Th. Thomas.


More information about the freebsd-hackers mailing list