[LLVMdev] [cfe-dev] RFC: Adding attribute(nonnull) to things in libc++

Benjamin Kramer benny.kra at gmail.com
Tue Jun 2 04:47:17 PDT 2015


> On 02.06.2015, at 13:34, Joerg Sonnenberger <joerg at britannica.bec.de> wrote:
> 
> 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.

Hmm, odd. GCC has done so for a long time, maybe it's disabled on some platforms? I get nonnull warnings with gcc 4.7 and gcc 5.0.

$ gcc -Wall -x c - <<< "int main() { memcpy(0, 0, 0); }"
<stdin>: In function ‘main’:
<stdin>:1:1: warning: implicit declaration of function ‘memcpy’ [-Wimplicit-function-declaration]
<stdin>:1:14: warning: incompatible implicit declaration of built-in function ‘memcpy’ [enabled by default]
<stdin>:1:1: warning: null argument where non-null required (argument 1) [-Wnonnull]
<stdin>:1:1: warning: null argument where non-null required (argument 2) [-Wnonnull]

- Ben



More information about the llvm-dev mailing list