Joerg Sonnenberger
2015-Jun-01 21:14 UTC
[LLVMdev] [cfe-dev] RFC: Adding attribute(nonnull) to things in libc++
On Mon, Jun 01, 2015 at 10:52:20AM -0700, Marshall Clow wrote:> P.S. recent gcc (at least 4.8.x and later) make optimizations based on > this UB (i.e, if you pass a pointer to memcpy, then it can't be NULL).BTW, this seems to be more an issue with glibc adding the tagging and not behavior of GCC itself. Joerg
Benjamin Kramer
2015-Jun-02 10:49 UTC
[LLVMdev] [cfe-dev] RFC: Adding attribute(nonnull) to things in libc++
> On 01.06.2015, at 23:14, Joerg Sonnenberger <joerg at britannica.bec.de> wrote: > > On Mon, Jun 01, 2015 at 10:52:20AM -0700, Marshall Clow wrote: >> P.S. recent gcc (at least 4.8.x and later) make optimizations based on >> this UB (i.e, if you pass a pointer to memcpy, then it can't be NULL). > > BTW, this seems to be more an issue with glibc adding the tagging and > not behavior of GCC itself.GCC also adds nonnull attributes via its builtin functions mechanism. If we want to follow GCC here we should do the same (Builtins.def has a FIXME about nonnull), which is imo cleaner than wrapping memcpy in libc++ and has the advantage of also working with plain C code. I don't think this has an impact on optimization right now; Clang lowers memcpy calls to the llvm.memcpy intrinsic and we traditionally have allowed llvm.memcpy with a nullptr and zero length (i.e. the optimizer has to prove that the length argument is non-zero to assume the pointer is dereferenceable). - Ben
Joerg Sonnenberger
2015-Jun-02 11:34 UTC
[LLVMdev] [cfe-dev] RFC: Adding attribute(nonnull) to things in libc++
On Tue, Jun 02, 2015 at 12:49:11PM +0200, Benjamin Kramer wrote:> > > On 01.06.2015, at 23:14, Joerg Sonnenberger <joerg at britannica.bec.de> wrote: > > > > On Mon, Jun 01, 2015 at 10:52:20AM -0700, Marshall Clow wrote: > >> P.S. recent gcc (at least 4.8.x and later) make optimizations based on > >> this UB (i.e, if you pass a pointer to memcpy, then it can't be NULL). > > > > BTW, this seems to be more an issue with glibc adding the tagging and > > not behavior of GCC itself. > > GCC also adds nonnull attributes via its builtin functions mechanism.I don't see it on NetBSD with GCC 4.8.4, so a plain prototype doesn't seeem to trigger it. Joerg