Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 14 Jan 2021 13:17:47 +0100
From:      Thierry Thomas <thierry@freebsd.org>
To:        freebsd-hackers@freebsd.org
Subject:   Re: Some fun with -O2
Message-ID:  <YAA2a4hBEc4xWJ3Z@graf.pompo.net>
In-Reply-To: <YAAuouAngRyT7Dw0@kib.kiev.ua>
References:  <YAAqI08bgBtfpssP@graf.pompo.net> <YAAuouAngRyT7Dw0@kib.kiev.ua>

next in thread | previous in thread | raw e-mail | index | archive | help
Le jeu. 14 janv. 21 à 12:44:34 +0100, Konstantin Belousov <kostikbel@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.



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?YAA2a4hBEc4xWJ3Z>