Date: Sun, 25 Feb 2018 21:48:13 +0100 From: Tijl Coosemans <tijl@FreeBSD.org> To: Konstantin Belousov <kostikbel@gmail.com> Cc: Eitan Adler <lists@eitanadler.com>, FreeBSD Standards <freebsd-standards@freebsd.org>, FreeBSD Hackers <freebsd-hackers@freebsd.org>, Kevin Lo <kevlo@freebsd.org> Subject: Re: Marking select(2) as restrict Message-ID: <20180225214813.776a9f58@kalimero.tijl.coosemans.org> In-Reply-To: <20180222105608.GE94212@kib.kiev.ua> References: <CAF6rxg=h_oMiUu7P=GAOQf_OySQM2w31hg6Kas%2B3jeEM3qq_Cg@mail.gmail.com> <CAF6rxgnt9c0n8i-nHQwoKGbZKF2hM5AZqEJnz0CLo26XOO4_sg@mail.gmail.com> <20180221032247.GA81670@ns.kevlo.org> <CAF6rxg=WwqeBnmJzfOZgtwrYesXPfvJFeaVmQwtTa_89_sxaJg@mail.gmail.com> <CANCZdfo46bhfaRpbqOmJjk4%2B=1R2c5kvmrJPENaxNgK==5M4kg@mail.gmail.com> <CAF6rxg=wNVgDUF9o744ngmzPNeHB3hqdrLufy=yS3D4osczxFQ@mail.gmail.com> <20180221104400.GU94212@kib.kiev.ua> <20180222112752.10da7e51@kalimero.tijl.coosemans.org> <20180222105608.GE94212@kib.kiev.ua>
next in thread | previous in thread | raw e-mail | index | archive | help
On Thu, 22 Feb 2018 12:56:08 +0200 Konstantin Belousov <kostikbel@gmail.com> 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: EXAMPLE 3 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.
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20180225214813.776a9f58>