[PATCH] D34121: [ubsan] Teach the pointer overflow check that "p - <unsigned> <= p" (PR33430)

Vedant Kumar via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Jun 12 15:23:57 PDT 2017


vsk created this revision.

The pointer overflow check gives false negatives when dealing with
expressions in which an unsigned value is subtracted from a pointer.
This is summarized in PR33430 [1]: ubsan permits the result of the
submission to be greater than "p", but it should not.

To fix the issue, we should track whether or not the pointer expression
is a subtraction. If it is, and the indices are unsigned, we know to
expect "p - <unsigned> <= p".

I've tested this by running check-{llvm,clang} with a stage2 ubsan-enabled build. I've also added some tests to compiler-rt, which I'll upload in a separate patch.

[1] https://bugs.llvm.org/show_bug.cgi?id=33430


https://reviews.llvm.org/D34121

Files:
  lib/CodeGen/CGExpr.cpp
  lib/CodeGen/CGExprScalar.cpp
  lib/CodeGen/CodeGenFunction.h
  test/CodeGen/ubsan-pointer-overflow.m

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D34121.102250.patch
Type: text/x-patch
Size: 7833 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170612/27478883/attachment.bin>


More information about the cfe-commits mailing list