[PATCH] D30806: [nonnull] Teach Clang to attach the nonnull LLVM attribute to declarations and calls instead of just definitions, and then teach it to *not* attach such attributes even if the source code contains them.

Chandler Carruth via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Mar 10 00:46:06 PST 2017


chandlerc added a comment.

In https://reviews.llvm.org/D30806#697372, @ahatanak wrote:

> Are users allowed to call these routines with a null pointer and a non-zero size? Or can we assume that if the size is known to be non-zero at compile time, the pointers are not null?


If the sizes are non-zero, all of these will access memory through the pointer.

But we don't currently have any way of easily expressing this in the IR. We could try something fancy like call-side attributes when the size is known, but it is pretty redundant -- we could just teach the same things that look at the attributes to know that these are reads or writes of a constant size...

> I'm thinking we might miss optimization opportunities if it's not possible to mark the pointer parameters as nonnull.

Note that currently, *nothing marks these parameters as nonnull*. So in all the years that folks have used Clang and LLVM with libc headers that have an __attribute__((nonnull)), no one has found a performance problem with this as the root cause and fixed it.

To me, this indicates that this isn't that important of an optimization *for these libc routines*.

If someone ever comes up with a testcase where this is important thing for performance, I think we can cross the bridge of finding a fancier way to analyze things then.


https://reviews.llvm.org/D30806





More information about the cfe-commits mailing list