Some fun with -O2
Dimitry Andric
dim at FreeBSD.org
Thu Jan 14 12:05:05 UTC 2021
On 14 Jan 2021, at 12:25, Thierry Thomas <thierry at FreeBSD.org> wrote:
>
> Let´s check a small C program, check_mktime.c, fetchable from
> <https://people.freebsd.org/~thierry/check_mktime.c>.
>
> $CC -o check_mktime -O2 check_mktime.c
> ./check_mktime
$ gcc -fsanitize=undefined check_mktime.c -o check_mktime
<...lots of warnings snipped...>
$ ./check_mktime
check_mktime.c:109:51: runtime error: signed integer overflow: 4611686018427387904 * 2 cannot be represented in type 'long int'
check_mktime.c:111:13: runtime error: signed integer overflow: -9223372036854775808 - 1 cannot be represented in type 'long int'
check_mktime.c:123:28: runtime error: signed integer overflow: 1073741824 * 2 cannot be represented in type 'int'
check_mktime.c:125:7: runtime error: signed integer overflow: -2147483648 - 1 cannot be represented in type 'int'
This program indeed relies on -fwrapv.
-Dimitry
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 223 bytes
Desc: Message signed with OpenPGP
URL: <http://lists.freebsd.org/pipermail/freebsd-hackers/attachments/20210114/8000f262/attachment.sig>
More information about the freebsd-hackers
mailing list