summaryrefslogtreecommitdiffstats
path: root/clang/lib/StaticAnalyzer/Checkers/UndefinedAssignmentChecker.cpp
diff options
context:
space:
mode:
authorRoman Lebedev <lebedev.ri@gmail.com>2017-11-30 09:18:35 +0000
committerRoman Lebedev <lebedev.ri@gmail.com>2017-11-30 09:18:35 +0000
commit88b56caa0e18e2e4efe122d31e646872436e87f3 (patch)
treeda245a2448f253d1261d3cf87ba5599f209d1f78 /clang/lib/StaticAnalyzer/Checkers/UndefinedAssignmentChecker.cpp
parent21e8ded4d2a4d90bee00ecb80abb812866fb6183 (diff)
downloadbcm5719-llvm-88b56caa0e18e2e4efe122d31e646872436e87f3.tar.gz
bcm5719-llvm-88b56caa0e18e2e4efe122d31e646872436e87f3.zip
[analyzer] Fix false negative on post-increment of uninitialized variable.
Summary: Currently clang static analyzer does warn on: ``` int x; x+=1; x-=1; x=x+1; x=x-1; ``` But does warn on: ``` int x; x++; x--; --x; ++x; ``` This differential should fix that. Fixes https://bugs.llvm.org/show_bug.cgi?id=35419 Reviewers: dcoughlin, NoQ Reviewed By: dcoughlin Subscribers: NoQ, xazax.hun, szepet, cfe-commits, a.sidorin Tags: #clang Differential Revision: https://reviews.llvm.org/D40463 llvm-svn: 319411
Diffstat (limited to 'clang/lib/StaticAnalyzer/Checkers/UndefinedAssignmentChecker.cpp')
-rw-r--r--clang/lib/StaticAnalyzer/Checkers/UndefinedAssignmentChecker.cpp8
1 files changed, 8 insertions, 0 deletions
diff --git a/clang/lib/StaticAnalyzer/Checkers/UndefinedAssignmentChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/UndefinedAssignmentChecker.cpp
index 7a31efc8cef..c3dcf1fac19 100644
--- a/clang/lib/StaticAnalyzer/Checkers/UndefinedAssignmentChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/UndefinedAssignmentChecker.cpp
@@ -60,6 +60,14 @@ void UndefinedAssignmentChecker::checkBind(SVal location, SVal val,
const Expr *ex = nullptr;
while (StoreE) {
+ if (const UnaryOperator *U = dyn_cast<UnaryOperator>(StoreE)) {
+ str = "The expression is an uninitialized value. "
+ "The computed value will also be garbage";
+
+ ex = U->getSubExpr();
+ break;
+ }
+
if (const BinaryOperator *B = dyn_cast<BinaryOperator>(StoreE)) {
if (B->isCompoundAssignmentOp()) {
ProgramStateRef state = C.getState();
OpenPOWER on IntegriCloud