Marking select(2) as restrict

Tijl Coosemans tijl at
Sun Feb 25 20:48:23 UTC 2018

On Thu, 22 Feb 2018 12:56:08 +0200 Konstantin Belousov <kostikbel at> wrote:
> Consider the recently changed devd code:
> 	select(n + 1, &fd, &fd, &fd);
> There, compiler can see that restrict is applied to arguments which are
> given same values.  Since this leads to the self-contradicting statement
> 	fd != fd
> which cannot be true, compliler in its optimizing wisdom can assume that
> the code is never executing and remove it.  I do not know whether clang
> actually makes such transformation, but it does not sound unfeasible
> looking at its other advances.

There's an example in the C99 standard that indicates such a call is not
necessarily undefined so compilers cannot optimise it away:

The function parameter declarations
void h(int n, int * restrict p, int * restrict q, int * restrict r)
	int i;
	for (i = 0; i < n; i++)
		p[i] = q[i] + r[i];
illustrate how an unmodified object can be aliased through two restricted
pointers.  In particular, if a and b are disjoint arrays, a call of the
form h(100, a, b, b) has defined behavior, because array b is not modified
within function h.

More information about the freebsd-standards mailing list