]> granicus.if.org Git - clang/commit
[nonnull] Teach Clang to attach the nonnull LLVM attribute to
authorChandler Carruth <chandlerc@gmail.com>
Wed, 22 Mar 2017 09:09:13 +0000 (09:09 +0000)
committerChandler Carruth <chandlerc@gmail.com>
Wed, 22 Mar 2017 09:09:13 +0000 (09:09 +0000)
commit4db37b682d05e075757eb3b75d77cd14f51b1313
tree0cdc123697aa99cb750b7f88a497468d26872214
parent9d042bec10a91011bc2401675325b4b9f675ab44
[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.

This follows the design direction discussed on cfe-dev here:
http://lists.llvm.org/pipermail/cfe-dev/2017-January/052066.html

The idea is that for C standard library builtins, even if the library
vendor chooses to annotate their routines with __attribute__((nonnull)),
we will ignore those attributes which pertain to pointer arguments that
have an associated size. This allows the widespread (and seemingly
reasonable) pattern of calling these routines with a null pointer and
a zero size. I have only done this for the library builtins currently
recognized by Clang, but we can now trivially add to this set. This will
be controllable with -fno-builtin if anyone should care to do so.

Note that this does *not* change the AST. As a consequence, warnings,
static analysis, and source code rewriting are not impacted.

This isn't even a regression on any platform as neither Clang nor LLVM
have ever put 'nonnull' onto these arguments for declarations. All this
patch does is enable it on other declarations while preventing us from
ever accidentally enabling it on these libc functions due to a library
vendor.

It will also allow any other libraries using this annotation to gain
optimizations based on the annotation even when only a declaration is
visible.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@298491 91177308-0d34-0410-b5e6-96231b3b80d8
include/clang/AST/ASTContext.h
include/clang/Basic/Builtins.def
lib/AST/ASTContext.cpp
lib/CodeGen/CGCall.cpp
test/CodeGen/nonnull.c