diff options
author | Ted Kremenek <kremenek@apple.com> | 2011-04-12 03:49:37 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2011-04-12 03:49:37 +0000 |
commit | 57a4a152b2aa5d6a55ecd0678a6fb4508ed6277c (patch) | |
tree | 1cae5c25840a54822e96cdcb32d72ea449bac6bb | |
parent | c05f657d8300a865ab9a95198c498dd7e6b73199 (diff) | |
download | bcm5719-llvm-57a4a152b2aa5d6a55ecd0678a6fb4508ed6277c.tar.gz bcm5719-llvm-57a4a152b2aa5d6a55ecd0678a6fb4508ed6277c.zip |
Fix bug in SimpleSValBuilder where '--' pointer arithmetic was treated like '++' pointer arithmetic.
llvm-svn: 129348
-rw-r--r-- | clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp | 3 | ||||
-rw-r--r-- | clang/test/Analysis/misc-ps-region-store.cpp | 19 |
2 files changed, 21 insertions, 1 deletions
diff --git a/clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp b/clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp index d6062eaa90c..5d802511510 100644 --- a/clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp +++ b/clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp @@ -873,7 +873,8 @@ SVal SimpleSValBuilder::evalBinOpLN(const GRState *state, QualType elementType; if (const ElementRegion *elemReg = dyn_cast<ElementRegion>(region)) { - index = evalBinOpNN(state, BO_Add, elemReg->getIndex(), rhs, + assert(op == BO_Add || op == BO_Sub); + index = evalBinOpNN(state, op, elemReg->getIndex(), rhs, getArrayIndexType()); superR = elemReg->getSuperRegion(); elementType = elemReg->getElementType(); diff --git a/clang/test/Analysis/misc-ps-region-store.cpp b/clang/test/Analysis/misc-ps-region-store.cpp index aaf13810990..1846bdb3976 100644 --- a/clang/test/Analysis/misc-ps-region-store.cpp +++ b/clang/test/Analysis/misc-ps-region-store.cpp @@ -360,3 +360,22 @@ int test_invalidate_class() { return y.x; // no-warning } +// Test correct pointer arithmetic using 'p--'. This is to warn that we +// were loading beyond the written characters in buf. +char *RDar9269695(char *dst, unsigned int n) +{ + char buff[40], *p; + + p = buff; + do + *p++ = '0' + n % 10; + while (n /= 10); + + do + *dst++ = *--p; // no-warning + while (p != buff); + + return dst; +} + + |