]> granicus.if.org Git - clang/commit
[ubsan] Teach the pointer overflow check that "p - <unsigned> <= p" (PR33430)
authorVedant Kumar <vsk@apple.com>
Thu, 13 Jul 2017 20:55:26 +0000 (20:55 +0000)
committerVedant Kumar <vsk@apple.com>
Thu, 13 Jul 2017 20:55:26 +0000 (20:55 +0000)
commit3eb6d072ea2aa7f39e85c036f98201df1e65c56c
treeaf1beab3f070962c541ff032dcf7f6bae73b63f0
parent16f984f4bd6a95dd565c3357c1fdc4ed126ad7da
[ubsan] Teach the pointer overflow check that "p - <unsigned> <= p" (PR33430)

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
subtraction 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
are in D34122.

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

Differential Revision: https://reviews.llvm.org/D34121

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@307955 91177308-0d34-0410-b5e6-96231b3b80d8
lib/CodeGen/CGExpr.cpp
lib/CodeGen/CGExprScalar.cpp
lib/CodeGen/CodeGenFunction.h
test/CodeGen/ubsan-pointer-overflow.m