[PATCH] D67122: [UBSan][clang][compiler-rt] Applying non-zero offset to nullptr is undefined behaviour

Roman Lebedev via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Sep 3 14:41:18 PDT 2019


lebedev.ri updated this revision to Diff 218533.
lebedev.ri marked an inline comment as done.
lebedev.ri added a comment.

Reworded `(ptr - intptr_t(ptr)) -> nullptr` ubsan message to be less specific.

Currently, `EmitCheckedInBoundsGEP()` is used sparsely,
a lot of `GEP inbounds` are created directly.
While i suspect that is being done intentionally:

> rL304459 <https://reviews.llvm.org/rL304459>
> 
> - It does not check some GEPs in CGExprCXX. I'm not sure that inserting checks here, or in CGClass, would catch many bugs.

and i think that may have made sense for the original check
(overflow), i'm not sure we get to be this picky here.

I'm still deliberating, but i suspect it will be a good idea
to change all `Builder.Create*InBoundsGEP*()` in clang CodeGen
to go through `EmitCheckedInBoundsGEP()`.
Although i suppose those new cases should only run this sanitizer.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D67122/new/

https://reviews.llvm.org/D67122

Files:
  clang/docs/ReleaseNotes.rst
  clang/docs/UndefinedBehaviorSanitizer.rst
  clang/include/clang/Basic/Sanitizers.def
  clang/lib/CodeGen/CGExprScalar.cpp
  clang/lib/CodeGen/CodeGenFunction.h
  clang/test/CodeGen/catch-nullptr-and-nonzero-offset-blacklist.c
  clang/test/CodeGen/catch-nullptr-and-nonzero-offset-in-offsetof-idiom.c
  clang/test/CodeGen/catch-nullptr-and-nonzero-offset.c
  clang/test/CodeGen/catch-pointer-offsetting.c
  clang/test/CodeGen/catch-pointer-overflow.c
  clang/test/CodeGenCXX/catch-nullptr-and-nonzero-offset-in-offsetof-idiom.cpp
  clang/test/Driver/fsanitize.c
  compiler-rt/lib/ubsan/ubsan_checks.inc
  compiler-rt/lib/ubsan/ubsan_handlers.cpp
  compiler-rt/test/ubsan/TestCases/Pointer/index-overflow.cpp
  compiler-rt/test/ubsan/TestCases/Pointer/nullptr-and-nonzero-offset-constants.cpp
  compiler-rt/test/ubsan/TestCases/Pointer/nullptr-and-nonzero-offset-summary.cpp
  compiler-rt/test/ubsan/TestCases/Pointer/nullptr-and-nonzero-offset-variable.cpp
  compiler-rt/test/ubsan/TestCases/Pointer/unsigned-index-expression.cpp
  compiler-rt/test/ubsan_minimal/TestCases/nullptr-and-nonzero-offset.c
  llvm/docs/ReleaseNotes.rst

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D67122.218533.patch
Type: text/x-patch
Size: 81801 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190903/853f58cc/attachment-0001.bin>


More information about the cfe-commits mailing list