[PATCH] D30762: [ubsan] Add a nullability sanitizer

Vedant Kumar via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Mar 8 15:18:56 PST 2017


vsk created this revision.

Teach UBSan how to detect violations of the _Nonnull annotation when
passing arguments to callees, in assignments, and in return stmts.

Because _Nonnull does not affect IRGen, the new checks are disabled by
default. The new driver flags are:

  -fsanitize=nullability-arg (_Nonnull violation in call)
  -fsanitize=nullability-assign (_Nonnull violation in assignment)
  -fsanitize=nullability-return (_Nonnull violation in return stmt)
  -fsanitize=nullability (all of the above)

This patch builds on top of UBSan's existing support for detecting
violations of the nonnull attributes ('nonnull' and 'returns_nonnull').
I am reusing the compiler-rt support for the existing checks for now.
I have FIXME's for this, and plan on handling them in a follow-up.

One point of note is that the nullability-return check is only allowed
to kick in if all arguments to the function satisfy their nullability
preconditions. This makes it necessary to emit some null checks in the
function body itself.

Testing: check-clang and check-ubsan. I also built some Apple ObjC
frameworks with an asserts-enabled compiler, and verified that we get
valid reports.


https://reviews.llvm.org/D30762

Files:
  docs/UndefinedBehaviorSanitizer.rst
  include/clang/Basic/Sanitizers.def
  lib/CodeGen/CGCall.cpp
  lib/CodeGen/CGDecl.cpp
  lib/CodeGen/CGExprScalar.cpp
  lib/CodeGen/CodeGenFunction.cpp
  lib/CodeGen/CodeGenFunction.h
  lib/Driver/SanitizerArgs.cpp
  lib/Driver/ToolChain.cpp
  test/CodeGenObjC/ubsan-null-retval.m
  test/CodeGenObjC/ubsan-nullability.m

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D30762.91082.patch
Type: text/x-patch
Size: 24985 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170308/01b946db/attachment-0001.bin>


More information about the cfe-commits mailing list