diff options
author | Gabor Horvath <xazax.hun@gmail.com> | 2017-10-10 11:01:49 +0000 |
---|---|---|
committer | Gabor Horvath <xazax.hun@gmail.com> | 2017-10-10 11:01:49 +0000 |
commit | 21524676a2c9a137459cea8ccc15df27f314418a (patch) | |
tree | 8b42ef8060a79a1b3d6d66d2ffbf9068fa8e96f9 /clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp | |
parent | 29ffd3f1d9dfe63b8f088ae1c7d4eefefec388f7 (diff) | |
download | bcm5719-llvm-21524676a2c9a137459cea8ccc15df27f314418a.tar.gz bcm5719-llvm-21524676a2c9a137459cea8ccc15df27f314418a.zip |
[analyzer] Implement pointer arithmetic on constants
Patch by: Rafael Stahl!
Differential Revision: https://reviews.llvm.org/D37478
llvm-svn: 315296
Diffstat (limited to 'clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp')
-rw-r--r-- | clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp b/clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp index bb4c2a6b525..a5b5744c3fb 100644 --- a/clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp +++ b/clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp @@ -922,6 +922,10 @@ SVal SimpleSValBuilder::evalBinOpLN(ProgramStateRef state, if (rhs.isZeroConstant()) return lhs; + // Perserve the null pointer so that it can be found by the DerefChecker. + if (lhs.isZeroConstant()) + return lhs; + // We are dealing with pointer arithmetic. // Handle pointer arithmetic on constant values. @@ -937,6 +941,8 @@ SVal SimpleSValBuilder::evalBinOpLN(ProgramStateRef state, // Offset the increment by the pointer size. llvm::APSInt Multiplicand(rightI.getBitWidth(), /* isUnsigned */ true); + QualType pointeeType = resultTy->getPointeeType(); + Multiplicand = getContext().getTypeSizeInChars(pointeeType).getQuantity(); rightI *= Multiplicand; // Compute the adjusted pointer. |