[tz] [PROPOSED 1/7] Avoid undefined behavior if no Link lines

Garrett Wollman wollman at csail.mit.edu
Wed Oct 26 18:55:19 UTC 2022


<<On Wed, 26 Oct 2022 01:59:40 -0400, Tom Lane via tz <tz at iana.org> said:

> I side with Winston Churchill in saying "this is nonsense up
> with which I shall not put".  There are no useful grounds for
> claiming that qsort, memset, memcpy, etc, with a null pointer
> and a zero count argument should be undefined.

In a perhaps less ridiculous case, undefined behavior when such a
library function is called with a null pointer for a source argument
allows the implementation (especially an inlining compiler) to
pre-warm the d-cache before entering the main loop.  Not all
architectures have a reliably non-trapping speculative read operation,
so this gives the compiler a bit more freedom and allows it to inline
a higher-performance implementation without first having to prove that
the source pointer isn't null.

This behavior seems silly for qsort() but it seems likely that the
compiler will share the same annotations and implementation strategy
for all standard library functions.

-GAWollman



More information about the tz mailing list