[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
Thu Mar 9 19:59:33 PST 2017


chandlerc created this revision.
Herald added a subscriber: mcrosier.

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.


https://reviews.llvm.org/D30806

Files:
  include/clang/AST/ASTContext.h
  include/clang/Basic/Builtins.def
  lib/AST/ASTContext.cpp
  lib/CodeGen/CGBuiltin.cpp
  lib/CodeGen/CGCall.cpp
  lib/Sema/SemaChecking.cpp
  test/CodeGen/nonnull.c

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D30806.91257.patch
Type: text/x-patch
Size: 22265 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170310/2cca12d7/attachment-0001.bin>


More information about the cfe-commits mailing list