[LLVMdev] [cfe-dev] RFC: Adding attribute(nonnull) to things in libc++
Benjamin Kramer
benny.kra at gmail.com
Tue Jun 2 03:49:11 PDT 2015
> 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
More information about the llvm-dev
mailing list